如果新建一个JFrame  frametestone 在里面新建一个JButton button 
然后新建一个JFrame  frametesttwo 并添加按钮事件,怎样点击button按钮出现frametesttwo ,关闭frametestone?菜鸟请指教!

解决方案 »

  1.   

    给这个button添加一个onclick listener事件
      

  2.   

    jb.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {

    //System.exit(1);
    //System.out.print("yeah");
    JFrame jf=new JFrame();
    jf.setVisible(true);
    }

    });
      

  3.   

    给这个button添加一个onclick listener事件然后监听一下即可
      

  4.   

    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;import javax.swing.*;public class TT extends JFrame implements ActionListener{ /**
     * @param args
     */
    JButton b;
    public TT()
    {
    b = new JButton("button ");
    b.addActionListener(this);
    this.add(b);
    this.setSize(300,200);
    this.setVisible(true);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    new TT();
    }
    @Override
    public void actionPerformed(ActionEvent arg0) {
    // TODO Auto-generated method stub
    this.dispose();
    JFrame jf = new JFrame("My Frame");

    jf.setSize(300,200);
    jf.setLocation(200, 300);
    jf.setVisible(true);
    jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }}
      

  5.   


    请问一下如果添加两个按钮?  再就是如果我想用三个按钮建立三个ActionEvent类分别定义对象怎么点击按钮的时候打开下一个窗口,关闭this窗口呢?
      

  6.   

    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;import javax.swing.*;public class TT extends JFrame implements ActionListener{    /**
         * @param args
         */
        JButton a,b,c;
        public TT()
        {   a = new JButton("buttona ");
            b = new JButton("buttonb ");
            c = new JButton("buttonc ");
            a.addActionListener(this);
            b.addActionListener(this);
            c.addActionListener(this);
            this.add(a);
            this.add(b);
            this.add(c);
            this.setLayout(new GridLayout(1, 3));
            this.setSize(300,200);
            this.setVisible(true);
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            new TT();
        }
        @Override
        public void actionPerformed(ActionEvent arg0) {
            // TODO Auto-generated method stub
            this.dispose();
           if (arg0.getSource() == a )
            {JFrame jfA = new JFrame("My FrameA");
            jfA.setSize(300,200);
            jfA.setLocation(200, 300);
            jfA.setVisible(true);
            jfA.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}
           else if  (arg0.getSource() == b){
            JFrame jfB = new JFrame("My FrameB");
               jfB.setSize(300,200);
               jfB.setLocation(200, 300);
               jfB.setVisible(true);
               jfB.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
           }else if  (arg0.getSource() == c) {
            JFrame jfC = new JFrame("My FrameB");
               jfC.setSize(300,200);
               jfC.setLocation(200, 300);
               jfC.setVisible(true);
               jfC.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
        }}
      

  7.   

    再请教一个问题,,建立一个JFRame 怎么在鼠标一进入这个窗口的时候就在右上角显示这个鼠标所在的坐标。
      

  8.   

    添加一个onclick listener事件