package Game;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;


public class Main {
	
	
	static JButton btn_StartGame = new JButton ("開始遊戲");
	static JButton btn_ComputerGame = new JButton ("電腦對戰");
	static JButton btn_InternetGame = new JButton ("網路對戰");

	public static void main(String[] args) {
		
		new Main().Do();
		
	}
	
	void Do(){
		
		JFrame frm = new JFrame ("井字遊戲") ;
		Container cp = new Container();
		cp = frm.getContentPane () ;
		
		// 取消預設之BorderLayout
		cp.setLayout(null); 
		
		// 調整"開始遊戲"的 Button
		btn_StartGame.setBounds(150, 80, 100, 40);
		btn_StartGame.addActionListener(new Play(frm));  // 傳入frm
		
		// 調整"電腦對戰"的Button
		btn_ComputerGame.setBounds(150, 150 , 100, 40);
		
		// 調整"網路對戰"的Button
		btn_InternetGame.setBounds(150, 220 , 100, 40);
		
		// 把button加入Layout
		cp.add(btn_StartGame);
		cp.add(btn_ComputerGame);
		cp.add(btn_InternetGame);
		
		// 調整 Layout
		frm.setSize(400,400);
		frm.setLocationRelativeTo(null); // 置中
		
		frm.setVisible(true);
		
	}
	
	static class Play implements ActionListener{
		
		// 建構子接收frm
		JFrame frm ;
		public Play(JFrame frm){
			this.frm = frm ;
		}
		
		public void actionPerformed(ActionEvent e){
			
			btn_StartGame.setVisible(false);
			btn_ComputerGame.setVisible(false);
			btn_InternetGame.setVisible(false);
			
			new GameButton(frm) ;
			
		}
		
	}

}


/////



package Game;

import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;
import javax.swing.event.*;

class GameButton implements ActionListener {
	
	// 建構子接收frm
	JFrame frm ;
	Container cp ;
	public GameButton(JFrame frm){
		
		// 設定 frm , 從frm得到cp
		this.frm = frm ;
		cp = frm.getContentPane () ;
		
		JButton button1 = new JButton ("");
		button1.setBounds(50, 80, 100, 40);
		cp.add(button1);
		
		JButton button2 = new JButton ("");
		button2.setBounds(150, 80, 100, 40);
		cp.add(button2);
		
		JButton button3 = new JButton ("");
		button3.setBounds(250, 80, 100, 40);
		cp.add(button3);
		
		JButton button4 = new JButton ("");
		button4.setBounds(50, 120, 100, 40);
		cp.add(button4);
		
		JButton button5 = new JButton ("");
		button5.setBounds(150, 120, 100, 40);
		cp.add(button5);
		
		JButton button6 = new JButton ("");
		button6.setBounds(250, 120, 100, 40);
		cp.add(button6);
		
		JButton button7 = new JButton ("");
		button7.setBounds(50, 160, 100, 40);
		cp.add(button7);
		
		JButton button8 = new JButton ("");
		button8.setBounds(150, 160, 100, 40);
		cp.add(button8);
		
		JButton button9 = new JButton ("");
		button9.setBounds(250, 160, 100, 40);
		cp.add(button9);
		
	}
	
	public void actionPerformed(ActionEvent e){
		
		
	}

}
