以前做网页的时候就很奇怪别人怎么实现的在同一个页面点击会自动切换到另一个页面,后来知道了用框架可以实现这种功能,现在在用Java做窗体程序的时候,好像又遇到了同样的问题。
内容面板Panel 之间 的切换
首先添加一个鼠标单击事件,或是添加一个button,单击时,当前登陆面板loginpanel,切换至注册面板zhucepanel
private void loginMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
//单击登陆菜单项时,切换到登陆面板
this.remove(zhucePanel);
this.setContentPane(loginPanel);
this.revalidate();
this.repaint();
}
private void zhuceMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
//当单击注册时,切换带注册面板
this.remove(loginPanel);//首先移除当前注册面板
this.setContentPane(zhucePanel);//将注册面板添加至进来
this.revalidate();//重新组织组件
this.repaint();//重绘自己
}
、、、、、、、、、、、、、、、、、、、、、、、、、、、
内部窗体jInternalFrame
在jFrame窗体中添加桌面窗格,jDesktopPane,在桌面窗格中完成内部窗体切换,
将AddBookMessage切换至桌面窗格
JInternalFrame addbookmessage=new AddBookMessage();
jDesktopPane1.add(addbookmessage);
addbookmessage.setVisible(true);
this.setVisible(true);