私の大学のプロジェクトでこのセミナーを行っています.を追加するまで3つのメソッドを作成しました。これらのメソッドは、ユーザー(私はそれのスキャナを使用して、私もBufferReader
を試してみました)しかし今はプログラムが実行を停止し、私はterminal.Alsoで書き込みすることはできませんBlueJからエラーの種類を取得していない。 JButtons
:JButtons - 入力を許可しない
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Window extends JFrame implements ActionListener {
JButton b1 = new JButton("Load from file");
JButton b2 = new JButton("Save to file");
JButton b3 = new JButton("Add hotel and resrvations");
JButton b4 = new JButton("Search hotel by id");
JButton b5 = new JButton("Search reservation by name");
Main m0 = new Main();
public Window(Main main0) {
super("Management");//Name
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
FlowLayout flow = new FlowLayout();
setLayout(flow);
add(b1);
add(b2);
add(b3);
add(b4);
add(b5);
pack();
setVisible(true);
m0 = main0;
}
public void actionPerformed(ActionEvent ae) {
Object source = ae.getSource();
if(source == b1) {
m0.loadFile();
}else if(source == b2) {
m0.saveFile();
}else if(source == b3) {
m0.addHotel();
}else if(source == b4) {
m0.searchById();
}else if(source == b5) {
m0.searchByName();
}
}}
同じ問題
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Window extends JFrame implements ActionListener {
JButton b1 = new JButton("Get input");
Main m0 = new Main();
public Window(Main main0) {
super("Management");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
b1.addActionListener(this);
FlowLayout flow = new FlowLayout();
setLayout(flow);
add(b1);
pack();
setVisible(true);
m0 = main0;
}
public void actionPerformed(ActionEvent ae) {
Object source = ae.getSource();
if(source == b1) {
m0.userInput();
}
}
につながる、より単純化されたコード
}
とシンプルなメイン
import java.io.*;
import java.util.*;
public class Main{
public void userInput(){
Scanner scan = new Scanner(System.in);
System.out.println("Give hotel's name : ");
String name = scan.nextLine();
System.out.println(name);
}
public static void main(){
Main m0 = new Main();
Window w = new Window(m0);
}
}
問題は、お時間をメインclass.Thanksに存在する3つの最後methods.These方法で発生!!
まず、IDE(Netbeans、Eclipse、IntelliJ)は「実行中止」と言っていますか?何も起こらず、すべてがうまくいっているので、リターン0で終了しますか? – Shiki
BlueJ.Itで作業していますが、最初のScanner.nextLine()でaddHotel()を呼び出すと実行が停止します。そこには入力をする予定ですが、terminal.Alsoには書き込めませんその他の方法。 –