| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1920 人关注过本帖
标题:五子棋就差判断输赢了,求大神指点
取消只看楼主 加入收藏
sally02468
Rank: 2
来 自:山东
等 级:论坛游民
帖 子:17
专家分:14
注 册:2015-10-17
结帖率:100%
收藏
 问题点数:0 回复次数:0 
五子棋就差判断输赢了,求大神指点
第一个类
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);
               
            }
            
        }
   
    }
}
搜索更多相关主题的帖子: 五子棋 package public import method 
2015-12-05 23:17
快速回复:五子棋就差判断输赢了,求大神指点
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013268 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved