最初にGUI(gui1)があります。ボタンを押すと、別のGUI(gui2)が作成されます。私の質問は、gui1のメソッドを使用して、gui2の要素にアクセスするにはどうすればよいですか?
例:gui1のボタンを押す と、gui1のQuesHandText.setText(myVector[0]);
QuesHandText
aJTextField
とgui2myVector[0]
のvarになります。結果のエラーメッセージ:スレッド「AWT-EventQueue-0」の例外java.lang.NullPointerException
Gui2から[OK]を押すと、Gui1のJTextFieldにTextを設定したい http://img72.imageshack.us/img72/2822/36185233.png
//imports
public class Gui extends JFrame{
public JButton Simulate, Particular, Start, HandSelection;
public JTextField QuesHandText, FlopTurnRiverText, RezultatText;
public Gui g;
public Gui()
{
QuesHandText = new JTextField(4);
//instruct
ClassParticular handler1 = new ClassParticular();
Particular.addActionListener(handler1);
}
public Gui(String t)
{
//instruct
myVector[0]="some_string";
myVector[1]="some_string2";
}
public class ClassParticular implements ActionListener{
public void actionPerformed(ActionEvent event){
//instruc
HandSelection hs = new HandSelection();
HandSelection.addActionListener(hs);
StartClass hndlr = new StartClass();
Start.addActionListener(hndlr);
add(HandSelection);
add(Start);
}
}
public class HandSelection implements ActionListener{
public void actionPerformed(ActionEvent e){
g = new Gui("Hand selection");
g.setVisible(true);
g.setSize(1135,535);
g.setDefaultCloseOperation(HIDE_ON_CLOSE);
g.setResizable(false);
}
}
public class StartClass implements ActionListener{
public void actionPerformed(ActionEvent event){
QuesHandText.setText(myVector[0]); // THE PROBLEM IS HERE, I KNOW IT !!
}
}
}