📄 chessframe.java
字号:
import java.awt.*;
import java .io.*;
import menuBean;
import chessAbout;
import chessArray;
import chessBoard;
public class chessFrame extends Frame implements Runnable
{
public int width,height;
Dimension thisSize;
menuBean chM = new menuBean(this);
TextArea West=new TextArea("走棋",100,9,1);
TextArea East=new TextArea("落子",100,9,1);
TextField South=new TextField ("正在加载图象",30);
chessServer chSv=null;
chessPcName chP=null;
Thread thread=new Thread (this);
int pos=0;
chessBoard chB=new chessBoard();//定义棋盘
public chessFrame()
{
setTitle("让我们一起来下棋");
chM.CreateMenu(chessArray.mb ,chessArray.menu1 );
chessArray.offsize=Toolkit.getDefaultToolkit().getScreenSize();
width=chessArray.offsize.width;
height=chessArray.offsize.height;
setBounds(width/2-320,height/2-240,640,480);
//将框架置于屏幕中间
chessArray.chA(chessArray.arrayBak);//将棋子的位置数据化
/*将面板加入到框架中,之所以没有将此语句放在
构造函数中,是因为那时还没有获得框架的尺寸
*/
West.setBackground (Color.cyan );
West.setForeground (Color.red );
West.setEditable (false);
West.setFont (new Font ("",0,West.getBounds().width));
add("West",West);
East.setBackground (Color.cyan );
East.setForeground (Color.red );
East.setFont (new Font ("",0,East.getBounds().width));
East.setEditable (false);
add("East",East);
South.setBackground (Color.white);
South.setForeground (Color.red );
South.setEditable (false);
add("South",South);
this.setVisible (true);
add("Center",chB);
chB.addMan();//添加棋子
}
public void run()
{
while(true)
{
if(chessArray.repaintWarn )
{
this.South .setText (chessArray.information );
chessArray.repaintWarn =false;
}
if(chessArray.repaintStart )
{
if(West.getForeground ()==Color.black )West.setForeground (Color.blue );
else West.setForeground (Color.black);
West.append("\n"+chessArray.startInf);
if(chessArray.startInf.equals("走棋"))West.setText ("走棋");
chessArray.repaintStart =false;
}
if(chessArray.repaintEnd )
{
if(East.getForeground ()==Color.black )East.setForeground (Color.blue);
else East.setForeground (Color.black);
East.append("\n"+chessArray.endInf);
if(chessArray.endInf.equals("落子"))East.setText ("落子");
chessArray.repaintEnd =false;
}
try{
thread.sleep(1000*3);
}catch(InterruptedException e)
{ };
}
}
public boolean handleEvent(Event evt)
{
switch (evt.id)
{
case Event.WINDOW_DESTROY:
System.exit(0);
case Event.ACTION_EVENT:
if(evt.arg.equals("不玩了(Exit)"))
System.exit(0);
if(evt.arg.equals("重下(New)"))
{
if(chSv!=null||chP!=null){
if(chessArray.readyIn)
{
chessArray.information("等待对家走棋,不能选择重下");
return false;
}else
{
chessArray.information("正在告诉对家,您已选择重下");
chessArray.changeCount1=-1;
chessArray.chA(chessArray.arrayBak);
chessArray.repaint=true;
chessArray.change =false;//此时不允许走棋
chessArray.readyOut =true;
chessArray.changeCount1 =254;//告诉对家已选择重下
West.setText ("走棋");
East.setText ("落子");
}
return true;
}
}
if(evt.arg.equals("关于(About)")){
new chessAbout (new Frame());
return true;
}
if(evt.arg.equals("庄家"))
{
chSv= new chessServer (new Frame());
chSv.start ();
return true;
}
if(evt.arg.equals("挑战者"))
{
chP=new chessPcName (new Frame ());
return true;
}
for(int i=8;i<21;i++){
if(evt.arg.equals (chessArray.menu1 [0][i])){
chessArray.img=Toolkit.getDefaultToolkit().getImage (
"棋盘图案\\"+chessArray.menu1 [0][i]+".jpg");
chessArray.repaint =true;
chessArray.information ("图像已加载完毕;"+chessArray.information );
return true;
}
}
if(evt.arg.equals("其它..."))
{
String Sbak=chessArray.information ;
chessArray.information("正在打开文件对话框,请稍候......");
FileDialog fl=new FileDialog(new Frame(),"选择棋盘图案",0);
fl.setBounds (width/4,this.height /6,width/2,height/3);
fl.show( );
chessArray.information("请选择您想要的图案");
chessArray.img=Toolkit.getDefaultToolkit().getImage (
fl.getDirectory() +fl.getFile ());
chessArray.repaint =true;
chessArray.information ("图像已加载完毕"+Sbak);
return true;
}
return true;
default:
return false;
}
}
public void start()
{
thread.start();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -