0
私はこのテストコードを持っています。ボタンを押したときにメソッドが値を返すようにします。それについて最善の方法は何でしょうか?ネストされたクラスからのJava戻り
public String test(){
JFrame frame=new JFrame();
frame.setSize(800,600);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
JButton button=new JButton("Click Me!");
frame.add(button);
}
私はActionListener
を追加しようとしているが、私は、親メソッドから値を返す手立てを見ません。
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//A return here would not work
}
});
グローバルである場合は、フォーム内のオブジェクトを更新できます。リターンの代わりに、オブジェクトを直接更新します。 – kevingreen
'JFrame'の代わりに[' JOptionPane'](https://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html)を使用してください。このような作業のために設計されています。 –