JFrame正在出现,但面板不是?

时间:2016-12-03 14:37:58

标签: java eclipse swing arraylist jpanel

所以我试图用按钮创建一个银行,但我的面板不想出现我不知道为什么。我将面板添加到框架中,所以我不知道为什么它不起作用。是的,我确实导入了所有内容并且没有错误。

public class Bank {

private List<Account> accounts = new ArrayList<Account>();





public void makeAccount(Account account){
    accounts.add(account);
}

public void deleteAccount(Account account){
    accounts.remove(account);
}

public boolean login(Account account, char[] password){
    if(account.getPassword().equals(password)){
        return true;
    } else {
        return false;
    }
} 

public static void main(String[] args) {

    window();
}

public static void window(){

    JFrame f = new JFrame("Bank ");


    f.setVisible(true);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(1000, 500);
    f.setResizable (false);
    f.setLayout(new BorderLayout());


    JTextField in = new JTextField();
    JPasswordField pw = new JPasswordField();
    JPanel panel = new JPanel();
    JButton btn = new JButton("Create Account");
    f.add(panel, BorderLayout.CENTER);

    panel.setLayout(new GridLayout(3, 2, 20, 10));

    panel.add(new JLabel("User: "));
    panel.add(in);
    panel.add(new JLabel("Password: "));
    panel.add(pw);
    panel.add(btn);
    btn.addActionListener(new ActionListener(){

        @Override
        public void actionPerformed(ActionEvent e) {


        }
    });


}

这是帐户类:

package button;

public class Account

private int balance;
private String name;
private char[] password;



private char[] password;

public Account(String name, char[] password){
    this.name = name;
    this.password = password;
    balance = 0;
}

public int getBalance() {
    return balance;
}

public void setBalance(int balance) {
    this.balance = balance;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public char[] getPassword() {
    return password;
}

public void setPassword(char[] password) {
    this.password = password;
}

}

0 个答案:

没有答案