如何在jpanel中保存对变量的更改?

时间:2018-10-22 17:34:01

标签: java jpanel

String user=user;
if("disable".equals(e.getActionCommand())) {
        user=JOptionPane.showInputDialog(null, "Please enter your name.");
            int conf=JOptionPane.showConfirmDialog(null, user+". Is this correct?");
            if(conf==1) {user=JOptionPane.showInputDialog(null, "Please enter your name.");}
            else if(conf==0) {}
            text.setText("Hello, "+user);}
            name.setEnabled(false);
            age.setEnabled(true);
            agetext.setEnabled(true);
            age.setEnabled(true);
            text.setEnabled(false);
        if("agetask".equals(e.getActionCommand())) {int age = 0; //so the do statement doesn't break for the while loop
            String nage;
            do {
                nage = String.valueOf(JOptionPane.showInputDialog("How old are you, " + user + "?\n"));
                try {age = Integer.parseInt(nage);
                }
                catch(NumberFormatException ex1) {//stops program from crashing if something goes wrong
                    JOptionPane.showMessageDialog(null, "Please enter a valid number, " +user);
                }
            }while((age<=0) || (age>=150));}

运行代码时,唯一可用的按钮是名称任务。当用户输入姓名并确认时,年龄任务打开。但是,打开年龄任务时,用户变量仍将以“用户”而不是用户的输入形式返回。如何在jpanel的各个部分之间“共享”变量更改?

0 个答案:

没有答案