相关窗口、对话框、面板间的切换 点击主窗口菜单触发事件->弹出对话框,点击对话框按钮触发事件->返回主窗口,并加载一新的面板。问:如何实现后一个事件?谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 dispose()弹出的窗口romove掉现有的面板 add一个新的就行了啊 不知道 具体什么要求 看你怎么写了,你可以在点击对话框按钮的时候先把对话框setvisible(false)掉,,然后再把panel.setvisible(true)弹出不就行了~~~ 补充一下:主窗口:Frame1原面板:Panel_Main对话窗:Diag_Logoff新面板:Panel_Result代码一:主窗口Frame1public class Frame1 extends JFrame { JPanel contentPane; JMenuBar jMenuBar1 = new JMenuBar(); JMenu jMenu1 = new JMenu(); JMenuItem jMenuItem1 = new JMenuItem(); JMenu jMenu2 = new JMenu(); JMenuItem jMenuItem2 = new JMenuItem(); JPanel jPanel1 = new JPanel(); public Frame1() { try { setDefaultCloseOperation(EXIT_ON_CLOSE); jbInit(); } catch (Exception exception) { exception.printStackTrace(); } } /** * Component initialization. * * @throws java.lang.Exception */ private void jbInit() throws Exception { contentPane = (JPanel) getContentPane(); contentPane.setLayout(null); this.setJMenuBar(jMenuBar1); setSize(new Dimension(400, 300)); setTitle("Frame Title"); jMenu1.setText("使用"); jMenuItem1.setText("下机"); jMenuItem1.addActionListener(new Frame_jMenuItem1_actionAdapter(this)); jMenu2.setText("退出"); jMenuItem2.setText("退出"); jPanel1.setBounds(new Rectangle(10, 10, 398, 286)); jMenuBar1.add(jMenu1); jMenuBar1.add(jMenu2); jMenu1.add(jMenuItem1); jMenu2.add(jMenuItem2); contentPane.add(jPanel1); Panel_Main pm = new Panel_Main(); this.setContentPane(pm); } public void jMenuItem1_actionPerformed(ActionEvent e) { Dialog_Logoff dlf = new Dialog_Logoff(new Frame1(),"呵呵",true); Point p = new Point(this.getX() + 35, this.getY() + 60); dlf.setLocation(p); dlf.setSize(350, 180); dlf.setVisible(true); }}代码二:对话窗Diag_Logoffpublic class Dialog_Logoff extends JDialog { public Dialog_Logoff(Frame owner, String title, boolean modal) { super(owner, title, modal); try { setDefaultCloseOperation(DISPOSE_ON_CLOSE); jbInit(); pack(); } catch (Exception exception) { exception.printStackTrace(); } } public Dialog_Logoff() { this(new Frame(), "Dialog_Logoff", false); } private void jbInit() throws Exception { this.getContentPane().setLayout(null); jButton1.setBounds(new Rectangle(85, 72, 83, 25)); jButton1.setText("返回"); jButton1.addActionListener(new Dialog_Logoff_jButton1_actionAdapter(this)); this.getContentPane().add(jLabel1); this.getContentPane().add(jButton1); jLabel1.setText("O(∩_∩)O哈哈~"); jLabel1.setBounds(new Rectangle(82, 37, 129, 22)); } public void jButton1_actionPerformed(ActionEvent e) { this.dispose(); Panel_result pres = new Panel_result(); 此处如何补充? } JButton jButton1 = new JButton(); JLabel jLabel1 = new JLabel();} 各位,谁给具体实现一下,在线苦等ing... 如何在Mac系统下安装Oracle? java 掉进程,哪位大侠帮忙分析下原因,急急急 成千上万条数据的临时存储……疑问? 小弟是菜鸟,问几个基础的Java问题 刚开始学JAVA,请大家指点 求助:关于AWT 多线程的程序,运行久了,有些线程会自动停止运行,这是为什么?如何不让他停止 请问如何在游戏菜单窗口内直接加载游戏内容? stringbuffer转为int的问题 SQL语句的一个错误,请帮忙纠正一下 JEditorPane中使用javascript 关于如何向JComboBox添加选项
romove掉现有的面板 add一个新的就行了啊 不知道 具体什么要求
主窗口:Frame1
原面板:Panel_Main
对话窗:Diag_Logoff
新面板:Panel_Result代码一:主窗口Frame1public class Frame1 extends JFrame {
JPanel contentPane;
JMenuBar jMenuBar1 = new JMenuBar();
JMenu jMenu1 = new JMenu();
JMenuItem jMenuItem1 = new JMenuItem();
JMenu jMenu2 = new JMenu();
JMenuItem jMenuItem2 = new JMenuItem();
JPanel jPanel1 = new JPanel(); public Frame1() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
} /**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
this.setJMenuBar(jMenuBar1);
setSize(new Dimension(400, 300));
setTitle("Frame Title");
jMenu1.setText("使用");
jMenuItem1.setText("下机");
jMenuItem1.addActionListener(new Frame_jMenuItem1_actionAdapter(this));
jMenu2.setText("退出");
jMenuItem2.setText("退出");
jPanel1.setBounds(new Rectangle(10, 10, 398, 286));
jMenuBar1.add(jMenu1);
jMenuBar1.add(jMenu2);
jMenu1.add(jMenuItem1);
jMenu2.add(jMenuItem2);
contentPane.add(jPanel1);
Panel_Main pm = new Panel_Main();
this.setContentPane(pm); } public void jMenuItem1_actionPerformed(ActionEvent e) {
Dialog_Logoff dlf = new Dialog_Logoff(new Frame1(),"呵呵",true);
Point p = new Point(this.getX() + 35, this.getY() + 60);
dlf.setLocation(p);
dlf.setSize(350, 180);
dlf.setVisible(true); }
}代码二:对话窗Diag_Logoffpublic class Dialog_Logoff extends JDialog {
public Dialog_Logoff(Frame owner, String title, boolean modal) {
super(owner, title, modal);
try {
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
jbInit();
pack();
} catch (Exception exception) {
exception.printStackTrace();
}
} public Dialog_Logoff() {
this(new Frame(), "Dialog_Logoff", false);
} private void jbInit() throws Exception {
this.getContentPane().setLayout(null);
jButton1.setBounds(new Rectangle(85, 72, 83, 25));
jButton1.setText("返回");
jButton1.addActionListener(new Dialog_Logoff_jButton1_actionAdapter(this));
this.getContentPane().add(jLabel1);
this.getContentPane().add(jButton1);
jLabel1.setText("O(∩_∩)O哈哈~");
jLabel1.setBounds(new Rectangle(82, 37, 129, 22)); } public void jButton1_actionPerformed(ActionEvent e) {
this.dispose();
Panel_result pres = new Panel_result();
此处如何补充? } JButton jButton1 = new JButton();
JLabel jLabel1 = new JLabel();}