线程中的异常" AWT-EventQueue-0" java.lang.NumberFormatException:对于输入字符串:""。

时间:2016-03-15 12:47:39

标签: java swing jtextfield jdk1.6

我知道这个Exception告诉我,我试图解析为一个空字符串,但我无法弄清楚为什么它是空的。问题是JTextField tMax,即使我在其中尝试一些int数。 这是代码:

package AppPackage.panelsPackage;

        import java.awt.Toolkit;
        import java.awt.event.KeyEvent;
        import javax.swing.JTextField;
        import javax.swing.text.AbstractDocument;
        import javax.swing.text.BadLocationException;
        import javax.swing.text.DocumentFilter;


        public class Panel extends javax.swing.JPanel {

            /** Creates new form EulerPanel */
            public Panel() {
                initComponents();
            }

          private void initComponents() {
              //components
              private javax.swing.JTextField tMax = new javax.swing.JTextField()
              //code
              tMaxEuler.addKeyListener(new java.awt.event.KeyAdapter() {
                public void keyTyped(java.awt.event.KeyEvent evt) {
                    tMaxKeyTyped(evt);
                }
            });

          public String getTMax() {
        String tMaxString = tMax.getText();
        return tMaxString;
    }


public class OptionFrame extends javax.swing.JFrame {

       //code
       private void runBtnActionPerformed(java.awt.event.ActionEvent evt) {
       Panel panel1 = new Panel();
       String tMaxString = panel1.getTMaxEuler();
       int tMax = Integer.parseInt(tMaxString);
       int sample = tMax +3;

     public static void main(String args[]) {
          java.awt.EventQueue.invokeLater(new Runnable() {

        public void run() {
            new OptionFrameHSimulator().setVisible(true);
        }
    });
}

I can't understand why the JTextField tMax results empty, even if I write a number in it.
What is the problem?

0 个答案:

没有答案