-1

需要 Start() 等到在另一个类中单击按钮才能继续。请帮忙。

板球比赛

private string occurance;

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

    objE.setVisible(true);

    String occur = objE.textField.getText();

    occurance = occur;
}

进入GUI

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());
    }
  });
 }
} 
4

1 回答 1

2

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

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

      CricketMatch cricketMatch = new CricketMatch();
      cricketMatch.start();
   }
});

顺便说一句,方法应该以小写字母开头。

于 2013-10-01T15:35:26.037 回答