📄 chesspanel.java
字号:
/*
* ChessPanel.java
*
* Created on 2008年3月4日, 下午3:11
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package eight;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
/**
*
* @author 刘杨
*/
public class ChessPanel extends JPanel{
public Chess [][]ChessButton=new Chess[12][12];;
private JPanel panel=new JPanel();
public Main frame;
private int m=8;
private boolean success=false;
/** Creates a new instance of ChessPanel */
public ChessPanel(Main frame){
this.frame=frame;
for(int i=0;i<12;i++){
for(int j=0;j<12;j++) {
ChessButton[i][j]=new Chess(this);
ChessButton[i][j].setSize(50,50);
}
}
setpanel(8);
}
public void setpanel(int m){
//初始化ChessPanel
panel.removeAll();
this.m=m;
for(int i=0;i<m;i++){
for(int j=0;j<m;j++) {
if( ChessButton[i][j].judge(i,j) == false)
ChessButton[i][j].setpic(1);
else
ChessButton[i][j].setpic(2);
this.add(ChessButton[i][j]);
ChessButton[i][j].setLocation(j*50, i*50);
ChessButton[i][j].m=this.getm();
}
}
for(int i=0;i<12;i++)
for(int j=0;j<12;j++)
ChessButton[i][j].refresh();
this.frame.size = m*50;
if(frame.isFirstTime == false) {
frame.setSize(m*50 + frame.w,m*50 + frame.h);
}
}
public int getm(){
return this.m;
}
public void setsuccess(boolean s) {
success=s;
}
public boolean getsuccess() {
return success;
}
public void searchflict() {
for(int i=0;i<m;i++)
for(int j=0;j<m;j++)
if(ChessButton[i][j].flict(i,j)==false&&ChessButton[i][j].getChessSetBoolean()==false)
if(ChessButton[i][j].judge(i,j)==false) {//如果该位置类型属于第一种
ChessButton[i][j].setpic(7);
} else{
ChessButton[i][j].setpic(8);
}
}
public void setpanelagain(int m){
for(int i=0;i<m;i++){
for(int j=0;j<m;j++) {
if(ChessButton[i][j].getChessSetBoolean()==false)
if( ChessButton[i][j].judge(i,j) == false)
ChessButton[i][j].setpic(1);
else
ChessButton[i][j].setpic(2);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -