我正在从事大型项目。正如你所看到的,我有一个主要的JFrame和大约20个菜单项。每个菜单项都必须弹出一个新窗口。一开始,我已经创建了一个JLayeredPanel,然后给我分配每个菜单项一个的JPanel这是内部JFrame.Then我把25面板JLayeredPanel ......默认所有的面板被设置为不可见,如:
panel1.setVisible(false);
panel2.setVisible(false);
等
当用户点击一个菜单项时,其JPanel将可见并且其余部分不可见。它看起来很乱,我有5000行代码。我使用InternalFrame和TabbedPane,但我不满意他们。我想将我的代码拆分到不同的JPanel类中,并将它们分配给主JFrame。我的意思是当用户点击每个菜单项时,它将调用外部JPanel并将其呈现在主JFrame上的JPanel上。我使用NetBeans中的设计模式,但这一切对我来说,但simpled结构是这样的,它是不工作:
public class NewJPanel extends JPanel{
//I have added buttons and etc on this panel
......
}
public class frame extends JFrame(){
JPanel panel = new JPanel();
.....
Public frame(){
frame.add(panel);
}
......
//When use click on the any button on the panel
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
//this is not working
NewJPanel fi = new NewJPanel();
panel1.add(fi);
//or I tested this way separately but it did not work
panel1.remove();
panel1 = new NewJPanel();
add(panel);
invalidate();
}
}
请给我任何建议,我怎么能以专业的方式在splited类控制这个程序。
是'Public'有效或'延伸的JFrame()'? –
@yannishristofakis是的,它是公开的。 – Bernard
这是您关于此主题的第3个问题。退出创建新问题,并按照使用'CardLayout'的其他帖子的建议。绝对没有理由使用JLayeredPane。 – camickr