1

そのため、現在受講しているクラスでは、ATM システムを作成する必要があります。というわけで、パネルを2枚用意することにしました。すべてのプロセスが実行されるメイン パネルと、ユーザー向けにオプションが一覧表示されるオプション パネルです。問題は、上記のように、メインパネルを削除できないように見えるため、実際にアカウント作成画面などのパネルに置き換えることができないことです。実際、端末ウィンドウが表示されるだけです。完全に空白。私が確認した限りでは、ボタン イベントが発生しており、削除機能を通過することさえあります。

いずれにせよ、問題が何であるかを理解できないようです。おそらく、押されているボタンもパネルとともに削除されているためです。関連するコードは次のとおりです。

public class AccountSystem extends JFrame implements ActionListener
{
    public static Account currentuser = new Account(); //This is so that the methods know which account is currently logged in so they can perform operations on it.
    public static int count=0;
    public static Account acc[] = new Account[1000];
    public static String parts[] = new String[3];
    private JButton login, logout, createacc, deposit1, deposit2, withdraw1, withdraw2, transfer1, transfer2, nevermind;
    private JPanel options, mainarea, titlecard;
    private JTextField username, password, transfer, depositarea, withdrawarea, retypearea;
    private JLabel userprompt, depositprompt, withdrawpromt, balancedisp, passwordprompt, mainmessage, title;
    private String newuser, newpass, newpassconfirm;
    BorderLayout borderlayout;
    GridLayout gridlayout;
    public AccountSystem()
    {
        borderlayout = new BorderLayout();
        borderlayout.setHgap(5);
        borderlayout.setVgap(5);
        //Establishing our buttons here.
        JButton login = new JButton("Login");
        login.addActionListener(this);
        JButton createacc = new JButton("New Account");
        createacc.addActionListener(this);

        //Establishing our panels here.
        JPanel options = new JPanel();
        JPanel mainarea = new JPanel();
        JPanel titlecard = new JPanel();
        //Establishing our JLabel here.
        JLabel userprompt = new JLabel("Username: ");
        JLabel passwordprompt = new JLabel("Password: ");
        JLabel title = new JLabel(" LOGIN ");
        //Establishing our textfields here.
        JTextField username = new JTextField(20);
        JTextField password = new JTextField(20);
        JTextField transfer = new JTextField(20);
        JTextField withdrawarea = new JTextField(20);
        //Building the GUI here.
        titlecard.setSize(500,50);
        titlecard.setLocation (0,0);
        mainarea.setSize(300,450);
        mainarea.setLocation(0,50);
        options.setSize(150,450);
        options.setLocation(300,50);
        titlecard.add(title);
        mainarea.add(userprompt);
        mainarea.add(username);
        mainarea.add(passwordprompt);
        mainarea.add(password);
        mainarea.add(login);
        mainarea.add(createacc);
        getContentPane().setLayout(null);
        getContentPane().add(titlecard);
        getContentPane().add(mainarea);
        getContentPane().add(options);
    }
}

public void actionPerformed (ActionEvent e) 
{
    if ((e.getActionCommand()).equals("Login"))
    {
        login();
    }
    else if ((e.getActionCommand()).equals("New Account"))
    {
        accountmaker();
    }
    else if ((e.getActionCommand()).equals("Deposit Funds"))
    {
        deposit();
    }
    else if ((e.getActionCommand()).equals("Withdraw Funds"))
    {
        withdraw();
    }
    else if ((e.getActionCommand()).equals("Withdraw"))
    {
        withdrawprocedure();
    }
    else if ((e.getActionCommand()).equals("Create Account"))
    {
        accountprocedure();
    }
}

public void accountmaker() //This is the screen where the user creates the account they want to. Of course, something needed to be done to differentiate this screen and the login screen.
{
    currentuser = null; //This is so that the program doesn't get somehow confused when dealing with multiple uses of the program.
    getContentPane().remove(mainarea);
    title.setText("Create New Account");
    mainarea = new JPanel();
    JLabel userprompt = new JLabel ("Username: ");
    JLabel passwordprompt = new JLabel("Password: ");
    JLabel retype = new JLabel ("Retype: "); //This is what makes it different from the login screen
    createacc = new JButton ("Create Account");
    createacc.addActionListener(this);
    JButton nevermind = new JButton("Cancel");
    nevermind.addActionListener(this);
    JTextField username = new JTextField(20);
    JTextField password = new JTextField(20);
    retypearea = new JTextField(20);
    mainarea.setSize(300,500);
    mainarea.setLocation(0,0);
    mainarea.add(userprompt);
    mainarea.add(username);
    mainarea.add(passwordprompt);
    mainarea.add(password);
    mainarea.add(retype);
    mainarea.add(retypearea);
    getContentPane().add(mainarea);
    getContentPane().invalidate();
    getContentPane().validate();
    getContentPane().repaint();
}

これは、プログラムが使用する Account クラスです。

public class Account
{
    private String username;
    private String password;
    private double balance=0;
    public void deposit (double deposit)
    {
        balance += deposit;
    }
    public void withdraw (double withdraw)
    {
        balance -= withdraw;
    }
    public void setBalance (double newbalance)
    {
        balance = newbalance;
    }
    public void setUsername (String newusername)
    {
        username = newusername;
    }
    public void setPassword (String newpassword)
    {
        password = newpassword;
    }
    public String getUsername ()
    {
        return username;
    }
    public double getbalance ()
    {
        return balance;
    }
    public String getpassword()
    {
        return password;
    }
}
4

1 に答える 1