所以我的主要计划是有一个带有一个按钮和两个jTextFields的图形用户界面。当按下按钮时,它将启动我创建的Runnah类的一个新线程。Runnah类应该从文本字段中获取输入;
然后,当我运行Runnah时,NumberFormatException类将获得一个gui.getSeconds();
MainGUI类
public class MainGUI extends javax.swing.JFrame {
Runnah runnah;
Thread thread;
public MainGUI() {
initComponents();
//runnah = new Runnah();
}
private void startButtonActionPerformed(java.awt.event.ActionEvent evt) {
try {
runnah = new Runnah();
} catch (AWTException ex) {
Logger.getLogger(MainGUI.class.getName()).log(Level.SEVERE, null, ex);
}
thread = new Thread(runnah);
thread.start();
}
public String getInput(){
String temp = textInp.getText();
return temp;
}
public int getSeconds(){
return Integer.parseInt(secInp.getText());
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MainGUI().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JTextField secInp;
private javax.swing.JButton startButton;
private javax.swing.JTextField textInp;
// End of variables declaration
}Runnah类
public class Runnah implements Runnable{
private MainGUI gui;
private Robot robot;
public Runnah() throws AWTException{
this.robot = new Robot();
gui = new MainGUI();
}
public Runnah(Robot robot) {
this.robot = robot;
}
@Override
public void run() {
String temp = gui.getInput();
CharSequence input = temp;
int seconds = 1;
seconds = gui.getSeconds() * 1000;
robot.delay(seconds);
}如果需要更多的信息,请告诉我。
发布于 2014-03-08 22:26:59
我只是没有引用现有的MainGUI类。
https://stackoverflow.com/questions/22275628
复制相似问题