我现在用java写了一个窗口,上面包含一些菜单,鼠标点击一个菜单让它跳转到另一个窗口,并且原先的窗口消失?应该怎么写啊!
急!急!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

解决方案 »

  1.   

    swing?
    用listener可以嗎  
    點擊了以后執行new一個新窗口  和  隱藏或關閉當前窗口的操作?
      

  2.   

    /******just a demo*****************/public class MyFrame extends JFrame implements ActionListener{/***********
    other codes
    */
    public MyFrame(){
    JMenuItem item=new JMenuItem("跳转");
    item.addActionListener(this);
    }
    public void actionPerformed(ActionEvent e) 
     this.dispose();// 关闭MyFrame
      new AnotherFrame();//打开AnotherFrame
    }public class AnotherFrame extends JFrame{
    /****************/
    }
    没问题了吧?
      

  3.   

    帖下那个新窗口的代码看看,没有刷新,用一下validate()可能就好了
      

  4.   

    现在在Frame中定义一个JTextField,在定义一个JButton
    JTextField field1=new JTextField(12);
    JButton button1=new JButton("confirm");
    怎么写一个监听器
    当按下button1按钮时在另一个地方显示field1内用户输入的内容,并将field1的内容存入一个String中以便后面程序调用!
    急!!!!!!!!!!!!!!!!!!!!!!!!!!1
      

  5.   

    JFrame frame=new JFrame();
    JTextField field1=new JTextField(12);  
    JButton button1=new JButton("confirm");
    在frame窗口中添加上面两个组件
    现在在field1中输入内容,当按下button1键时输出field1中的内容
    怎么添加这个事件了?就没有人知道了嗎
      

  6.   

    就只要输出JTextField的getText()吗?
    首先用声明一个String的成员变量,在JTextField输入文本后,保存至这个字符串
    if(e.getSource()==button1) {
      JOptionPane.showMessageDialog(this,string);}
      

  7.   

    我用getText()获得内容后,
    然后在按下button1按钮,时间处理怎么得到的是空值啊!