java panel.add_Java - 添加/删除JPanel类(Java - Add/Remove JPanel classes)

I'm trying to make the JPanels swap from one to another. Sounds simple, but I'm struggling due to having my panels all in different classes.

I have 4 classes: - GUI (Main class) - BankingAppMainFrame (JFrame class) - BankingAppStartPanel (JPanel class)

Here is my relevant JFrame code:

//This is the only way i didn't get errors xD

public void panelSwap(JFrame z, JPanel x, JPanel y) {

z.remove(x);

z.add(y);

}

Here is my relevant BankingAppStartPanel code:

LoginButton.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent event) {

//I thought I'd need to instance all my classes

BankingAppMainFrame mainFrame = new BankingAppMainFrame();

BankingAppStartPanel startPanel = new BankingAppStartPanel();

BankingAppLoginPanel loginPanel = new BankingAppLoginPanel();

//This is calling the panelSwap method from the main Class

mainFrame.panelSwap(mainFrame, startPanel, loginPanel);

}

});

The BankingAppLoginPanel is just a blank panel at the moment until I can get this to work.

What I'm trying to do is remove the current Panel (In this case "BankingAppStartPanel" and replace it with the "BankingAppLoginPanel".

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值