首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >线程"Thread-3“java.lang.NumberFormatException中的异常:用于输入字符串:"”

线程"Thread-3“java.lang.NumberFormatException中的异常:用于输入字符串:"”
EN

Stack Overflow用户
提问于 2014-03-08 22:03:48
回答 1查看 926关注 0票数 0

所以我的主要计划是有一个带有一个按钮和两个jTextFields的图形用户界面。当按下按钮时,它将启动我创建的Runnah类的一个新线程。Runnah类应该从文本字段中获取输入;

然后,当我运行Runnah时,NumberFormatException类将获得一个gui.getSeconds();

MainGUI类

代码语言:javascript
复制
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类

代码语言:javascript
复制
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);
}

如果需要更多的信息,请告诉我。

EN

回答 1

Stack Overflow用户

发布于 2014-03-08 22:26:59

我只是没有引用现有的MainGUI类。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22275628

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档