TBD.my

Full Version: How To close this window and open new window ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
macam mana bila kita click button pertama atau button kedua dia tutup sendiri window tersebut dan keluarkan window baru iaitu game tersebut ?

Code:
public static void main(String argv[]) {
        JFrame frame = new JFrame("choose multiplayer");
        frame.setVisible(true);
        frame.setSize(400,200);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JLabel label = new JLabel("Choose MultiPlayer");
        JPanel panel = new JPanel();
        frame.add(panel);
        panel.add(label);
        JButton button = new JButton("1");
        panel.add(button);
        button.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent ae){
                
                start1Player();
                
            }
        });
        
        JButton button2 = new JButton("2");
        panel.add(button2);
        button2.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent ae){
                start2Player();

            }
        });