-2

I am working on an assignment in which I need to combine two programs that I have created into one functioning program. The end result I am hoping for is a program that once launched, opens a log in window, then once logged in, the user gets to play a tic tac toe game. Basically I just was wonder how to have a window within which when you click a button, a new window opens that can run extensive code.

4

1 回答 1

1

If you're using Swing framework, Create a second JFrame and set its visibility to false, and when the button is clicked, set it visibility to true.

public class MyFrame extends JFrame {
    private JButton jbt = new JButton("Open Window");
    private AnotherFrame jfrm = new AnotherFrame();

    public MyFrame(){
        add(jbt);
        jfrm.setVisibility(false);
        add(jfrm);

        jbt.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                jfrm.setVisibility(true);
            }
        });
    }

    private AnotherFrame extends JFrame {

        public AnotherFrame(){

       }

    }
}
于 2013-11-07T18:36:17.220 回答