需要程序等到按钮被另一个类点击

时间:2013-10-01 15:24:27

标签: java swing jbutton

需要Start()等待按钮在另一个类中单击,然后再继续。请帮忙。

板球比赛

private string occurance;

public void Start()
{
    EnterGUI objE = new EnterGUI();

    objE.setVisible(true);

    String occur = objE.textField.getText();

    occurance = occur;
}

EnterGUI

public class EnterGUI extends JFrame {

    String occurance;

    public void setOccurance(String occurance) {
        this.occurance = occurance;
    }

    public String getOccurance() {
        return occurance;
    }

    JButton btnNewButton = new JButton("Save");
    btnNewButton.setBounds(120, 5, 86, 43);
    btnNewButton.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent arg0) {
        setOccurance(textField.getText());
    }
  });
 }
} 

1 个答案:

答案 0 :(得分:2)

你为什么要等?单击按钮时调用start()...

btnNewButton.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent arg0) {
      setOccurance(textField.getText());

      CricketMatch cricketMatch = new CricketMatch();
      cricketMatch.start();
   }
});
顺便说一句,方法应该以小写字母开头。