ADD file via upload

pull/3/head
nxist2202005089 1 year ago
parent e508d977a8
commit 21679d0e2c

@ -0,0 +1,124 @@
package main;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
//画布
public class GamePanel extends JPanel implements ActionListener {
private JMenuBar jmb=null;
private GameFrame mainFrame = null;
private final int ROWS=15;//hang
private final int COLS =15;//lie
public GamePanel(GameFrame mainFrame){
this.setOpaque(false);
this.setLayout(null);
this.mainFrame = mainFrame;
createMenu ();
}//caidan
@Override
public void paint(Graphics g){
super.paint(g);
//绘制
drawGrid(g);
//绘制五个小点
draw5Point(g);
}
private void draw5Point(Graphics g) {
//左点
int x=142;
int y=142;
g.fillArc(x,y,8,8,0,360);
x=462;
g.fillArc(x,y,8,8,0,360);
//右点
x=142;
y=462;
g.fillArc(x,y,8,8,0,360);//坐下
x=462;
g.fillArc(x,y,8,8,0,360);//右下
x=302;
y=302;
g.fillArc(x,y,8,8,0,360);//中间
}
private void drawGrid(Graphics g) {
int start=26;
int x1=26;
int y1=26;
int x2=586;
int y2=26;
int dis = 40 ;//绘制15条横线
for (int i=0;i<ROWS;i++) {
y1 = i*dis+start;
y2 = y1;
g.drawLine(x1, y1, x2, y2);
}
y1=26;
y2=586;
for (int i=0;i<COLS;i++) {
x1 = i * dis + start;
x2 = x1;
g.drawLine(x1, y1, x2, y2);
}
}
private Font creatFont(){
return new Font("思源宋体",Font.BOLD,18);
}
private void createMenu() {
jmb = new JMenuBar();
Font tFont = creatFont();
JMenu jMenu1 = new JMenu("游戏");
jMenu1.setFont(tFont);
JMenu jMenu2 = new JMenu("战绩");
jMenu2.setFont(tFont);
JMenu jMenu3 = new JMenu("帮助");
jMenu3.setFont(tFont);
JMenuItem jmi1 = new JMenuItem(" 新游戏");
jmi1.setFont(tFont);
JMenuItem jmi2 = new JMenuItem(" 退出");
jmi2.setFont(tFont);
JMenuItem jmi3 = new JMenuItem(" 操作帮助");
jmi3.setFont(tFont);
JMenuItem jmi4 = new JMenuItem(" 胜利条件");
jmi4.setFont(tFont);
JMenuItem jmi5 = new JMenuItem(" 历史战绩");
jmi5.setFont(tFont);
jMenu1.add(jmi1);
jMenu1.add(jmi2);
jMenu3.add(jmi3);
jMenu3.add(jmi4);
jMenu2.add(jmi5);
jmb.add(jMenu1);
jmb.add(jMenu2);
jmb.add(jMenu3);
mainFrame.setJMenuBar(jmb);
jmi1.addActionListener(this);
jmi2.addActionListener(this);
jmi3.addActionListener(this);
jmi4.addActionListener(this);
jmi1.setActionCommand("restart");
jmi2.setActionCommand("exit");
jmi3.setActionCommand("help");
jmi4.setActionCommand("win");
}
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("菜单");
String command = e.getActionCommand();
System.out.println("指令"+command);
}
}
Loading…
Cancel
Save