五子棋就差判断输赢了,求大神指点
第一个类package fivechess;
public class Main1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
MyFrame frm = new MyFrame("五子棋");
}
}
第二个类
package fivechess;
import java.awt.*;
import java.awt.event.ActionEvent;
import javax.swing.*;
public class MyFrame extends JFrame{
JPanel pane_S,pane;
GridLayout gridLayout;//声明网格布局
JButton btn[];//声明按钮数组
Frame frm;
public MyFrame(String s) {
super(s);
JDialog log1=new JDialog(frm,"欢迎进入The one五子棋",true);
log1.setSize(300,300);
log1.setLocationRelativeTo(null);
log1.setVisible(true);
this.setVisible(false);
JDialog log2=new JDialog(frm,"The one's five chess",true);
log2.setSize(800,700);
log2.setLocationRelativeTo(null);
pane = new JPanel();
log2.add(pane);
//setContentPane(pane);
pane.setLayout(null);
pane_S = new JPanel();
pane.add(pane_S);
//pane_S.setLayout(null);
pane_S.setBounds(40, 40, 500, 500);
//addMouseListener((MouseListener) this);
//addMouseListener(this);//给当前窗口添加鼠标事件监听
/*for(int i=0;i<20;i++)
{
gridLayout = new GridLayout(i,20);
}*///创建14行,14列的网格布局
gridLayout=new GridLayout(17,17);
pane_S.setLayout(gridLayout);
Draw []btn=new Draw[17*17];
for(int i=0;i<17*17;i++)
btn[i]=new Draw("");
for(int i=0;i<17*17;i++)
{
pane_S.add(btn[i]);
//btn[i].setBackground(Color.gray);
}
//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
log2.setVisible(true);
}
}
第三个类
package fivechess;
import java.awt.event.*;
import javax.swing.*;
public class Draw extends JButton implements ActionListener{
static boolean bl=false;
static boolean flag=false;//游戏开始的标志
ImageIcon i1=new ImageIcon("C:\\Users\\Administrator\\workspace\\fivechess\\image\\bg1.png");
ImageIcon i2=new ImageIcon("C:\\Users\\Administrator\\workspace\\fivechess\\image\\2.png");
ImageIcon i3=new ImageIcon("C:\\Users\\Administrator\\workspace\\fivechess\\image\\1.png");
Draw(String s){
super(s);
this.setIcon(i1);
this.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==this){
if(bl==true){
this.setIcon(i2);
bl=false;//brack
setEnabled(false);
setDisabledIcon(i2);
}
else if(bl==false){
this.setIcon(i3);//white
bl=true;
setEnabled(false);
setDisabledIcon(i3);
}
}
}
}