展开全部
简单的五子棋程序
新建一个chess类,其中代码如下
package work;
import java.awt.Color;
public class Chess {
public static final int diamter=30;
private int x;//在网格中的索引,0~e68a84e8a2ad62616964757a686964616f3133323865663715
private int y;//在网格中的索引,0~15
private Color color;
public Color getColor() {
return color;
}
public void setColor(Color color) {
this.color = color;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public Chess(int x, int y, Color color) {
super();
this.x = x;
this.y = y;
this.color = color;
}
}
然后在同一个包中新建FirstFrame类。代码如下
package work;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
//主函数
public class FirstFrame{
public static void main(String[] args) {
FirstFrame1 f=new FirstFrame1();
f.setVisible(true);
}
}
//窗体函数
class FirstFrame1 extends JFrame implements ActionListener{
JMenuBar menuBar;
JMenu sysMenu;
JMenuItem startMenuItem;
JMenuItem backMenuItem;
JMenuItem exitMenuItem;
DrawPanel myPanel=new DrawPanel();
public FirstFrame1(){
super("娃哈哈");
add(myPanel);
menuBar=new JMenuBar();
setJMenuBar(menuBar);
sysMenu=new JMenu("系统(s)");
sysMenu.setMnemonic('s');
menuBar.add(sysMenu);