所以我的主要计划是使用带有按钮的GUI和两个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 Class
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);
}
如果需要更多信息,请告诉我们。
答案 0 :(得分:0)
我刚才没有引用现有的MainGUI类。