需要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());
}
});
}
}
答案 0 :(得分:2)
你为什么要等?单击按钮时调用start()...
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
setOccurance(textField.getText());
CricketMatch cricketMatch = new CricketMatch();
cricketMatch.start();
}
});
顺便说一句,方法应该以小写字母开头。