如果使用scanner将多个textfields的值保存在一个textfile中,javaswing gui就会冻结

pes8fvy9  于 2021-06-29  发布在  Java
关注(0)|答案(0)|浏览(154)

我在atmsystem上制作了一个javaswinggui,在将文本字段保存到一个文本文件(名为account numbers.txt)上时遇到了一个问题,该文件保存了账户、个人识别码(pin)、储蓄余额、支票余额和信用卡存款和取款余额。
运行程序时。。。
按下“注册”按钮后,整个gui冻结,我使用scanner,因为它可以读取文本文件上每行的单独条目,以比较它很快登录atm,并使用程序将要读取的文本文件中的储蓄、支票和信用卡余额,但由于gui冻结,我被卡在了注册部分。有什么建议吗?

JButton Register_button = new JButton("REGISTER");
Register_button.addActionListener(new ActionListener() {

    @SuppressWarnings("deprecation")
    public void actionPerformed(ActionEvent e) {
        File file=new File("ACCOUNT NUMBERS.txt");
        Scanner ACCOUNT = new Scanner(System.in);
        try{  
            String AN = AN_passfield.getText();
            String PIN = PIN_passfield.getText();
            int SAB = Integer.parseInt(SAB_textfield.getText());
            int CAB = Integer.parseInt(CAB_textfield.getText());
            int CCAB = Integer.parseInt(CCAB_textfield.getText());

            String  ANs = ACCOUNT.next(AN);
            String  PINs = ACCOUNT.next(PIN);
            int  SABs = ACCOUNT.nextInt(SAB);
            int CABs = ACCOUNT.nextInt(CAB);
            int  CCABs = ACCOUNT.nextInt(CCAB);

            PrintWriter pw=new PrintWriter(new FileOutputStream(file,true));

            pw.write(ANs+" "+PINs+" "+SABs+" "+CABs+" "+CCABs+"\n");
            pw.flush();
            pw.close();
            ACCOUNT.close();
            ATMSignUPSuccess.main(new String[] {});
            frame.dispose();
        } catch(Exception ex){
            ex.printStackTrace();
        }
    }
});

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题