From 9049fd7d4d2223c72543246f12411e867616e33b Mon Sep 17 00:00:00 2001 From: ps4v2qgi6 Date: Sat, 13 Apr 2024 17:43:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=94=E5=AD=90=E6=A3=8B=E5=B0=8F=E6=B8=B8?= =?UTF-8?q?=E6=88=8F=E4=B8=BB=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/GameMain.java | 109 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 src/GameMain.java diff --git a/src/GameMain.java b/src/GameMain.java new file mode 100644 index 0000000..660cd4a --- /dev/null +++ b/src/GameMain.java @@ -0,0 +1,109 @@ +package 马可莹; + +import java.awt.BorderLayout; +import java.awt.Button; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.Font; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +import javax.swing.JDialog; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JPanel; + +public class GameMain extends JFrame { + + Chessboard qpan; + + public GameMain() { + qpan = new Chessboard(); + // 创建菜单栏 + JMenuBar menubar = new JMenuBar(); + + JMenu menu = new JMenu("游戏(G)"); + JMenuItem item1 = new JMenuItem("新游戏"); + JMenuItem item2 = new JMenuItem("退出"); + menu.add(item1); + menu.addSeparator(); + menu.add(item2); + menubar.add(menu); + + + // 按钮 + JPanel btn = new JPanel(); + btn.setLayout(new GridLayout(10, 1)); + Button btn1 = new Button("重新开始"); + Button btn2 = new Button("悔棋"); + btn.add(btn1); + btn.add(btn2); + + // 窗口设置 + BorderLayout bl = new BorderLayout(); + this.setTitle("五子棋"); + this.setSize(480, 490); + this.setLocationRelativeTo(null); + this.setVisible(true); + this.setResizable(false); + this.add(menubar, bl.NORTH); + this.add(qpan, bl.CENTER); + this.add(btn, bl.EAST); + + // 按钮事件 + btn1.addMouseListener(new MouseAdapter() { + + @Override + public void mouseClicked(MouseEvent e) { + // TODO Auto-generated method stub + qpan.againGame(); + } + + }); + //悔棋 + btn2.addMouseListener(new MouseAdapter() { + + @Override + public void mouseClicked(MouseEvent e) { + // TODO Auto-generated method stub + qpan.huiqi(); + } + + }); + + // 新游戏 + item1.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + qpan.againGame(); + } + }); + + // 退出 + item2.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + System.exit(0); + } + }); + + } + + public static void main(String[] args) { + // TODO Auto-generated method stub + new GameMain(); + } + +} +