这里的第一个代码来自我无法弄清楚的主要代码的 prerec。
boolean CompanyLoaded, StartingNum = true;
FirstCheck newwin = new FirstCheck();
public CollectNumbers() {
if (StartingNum = true) firstCheck = newwin.FirstCheck(); <----Runs FirstCheck okay
if (CompanyLoaded = true) LoadCompany();
从现在开始,我将在下面发布我的 FirstCheck 课程。我试过抽象覆盖actionPerformed,我试过线程睡眠,等待,但无法弄清楚如何让我的FirstCheck()方法等到actionPerformed()返回我的字符串(Int)。任何帮助,将不胜感激!
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
abstract class FirstCheck extends JFrame implements ActionListener {
static int num;
static boolean bnum = true;
JTextField NumberEntry;
Toolkit tools = Toolkit.getDefaultToolkit();
Dimension windowLocVar = tools.getScreenSize();
public int FirstCheck() {
JFrame frame = new JFrame();
NumberEntry = new JTextField();
JButton Done = new JButton("Done");
Done.addActionListener(this);
JLabel label = new JLabel("Starting Check Number?");
label.setVerticalTextPosition(JLabel.BOTTOM);
label.setHorizontalTextPosition(JLabel.CENTER);
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(3,1));
panel.add(NumberEntry);
panel.add(label);
panel.add(Done);
frame.add(panel);
frame.pack();
frame.setVisible(true);
frame.setSize(250,150);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocation(windowLocVar.width/2-300,windowLocVar.height/2-100);
//try {
// Thread.sleep(5000);
// }
//catch(InterruptedException e) {
// // Restore the interrupted status
// Thread.currentThread().interrupt();
// }
}
public int actionPerformed(ActionEvent e) {
bnum = false;
num = Integer.parseInt(NumberEntry.getText());
return num;
}
}