Java写的围棋游戏的源代码
Java写的围棋游戏的源代码
import java.awt.event.*;
import javax.swing.JOptionPane;
public class Chess extends Frame
{
ChessPad chesspad= new ChessPad();
Chess()
{
add(chesspad);
chesspad.setBounds(70,90,440,440);
Label label=new Label("click to point,doubled_click to remove,right click to back",Label.CENTER);
add(label);
label.setBounds(70,55,440,24);
label.setBackground(Color.orange);
addWindowListener
(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
setLayout(null);
setVisible(true);
setSize(600,550);
}
public static void main(String args[])
{
Chess chess=new Chess();
}
}
class ChessPad extends Panel implements MouseListener, ActionListener,FocusListener
{
int x = -1, y = -1, chessColor = 1;
String blackname="",whitename="";
Button button=new Button("start");
Button inputButton=new Button("input");
TextField text_1=new TextField("black please"),
text_2=new TextField(""),//white please
text_3=new TextField("black'name"),
text_4=new TextField("white'name");
ChessPad()
{
add(inputButton);
inputButton.setBounds(35,5,60,26);
inputButton.addActionListener(this);
inputButton.addFocusListener(this);
add(text_3);
text_3.setBounds(115,5,90,24);
text_3.addFocusListener(this);
text_3.setEditable(true);
add(text_4);
text_4.setBounds(315,5,90,24);
text_4.addFocusListener(this);
text_4.setEditable(true);
add(button);
button.setBounds(35,36,60,26);
button.setEnabled(false);
button.addActionListener(this);
add(text_1);
text_1.setBounds(115,36,90,24);
text_1.setEnabled(false);
text_1.setEditable(false);
add(text_2);
text_2.setBounds(315,36,90,24);
text_2.setEnabled(false);
text_2.setEditable(false);
setSize(440,440);
setLayout(null);
setBackground(Color.orange);
addMouseListener(this);
}
public void paint(Graphics g)
{
for(int i=80;i<=400;i=i+20)
{
g.drawLine(40,i,400,i);
}
g.drawLine(40,420,400,420);
for(int j=40;j<=380;j=j+20)
{
g.drawLine(j,80,j,420);
}
g.drawLine(400,80,400,420);
g.fillOval(97,137,6,6);
g.fillOval(337,137,6,6);
g.fillOval(97,377,6,6);
g.fillOval(337,377,6,6);
g.fillOval(217,257,6,6);
}
public void focusGained(FocusEvent e)
{
Component com=(Component)e.getSource();
if(com==text_3)
{
text_3.setText("");
}
else if(com==text_4)
{
text_4.setText("");
}
}
public void focusLost(FocusEvent e)
{
}
public void mousePressed(MouseEvent e)
{
if(blackname.length()==0||whitename.length()==0)
{
JOptionPane.showMessageDialog(this,"please input the player's name,and click input button before you start chess!","reminder&
quot;,JOptionPane.WARNING_MESSAGE);
}
else if(blackname.equals("black'name"))
{
JOptionPane.showMessageDialog(this,"please
Java写的围棋游戏的源代码
input the black player's name,and click input button","reminder",JOptionPane.WARNING_MESSAGE);
}
else if(whitename.equals("white'name"))
{
JOptionPane.showMessageDialog(this,"please input the white player's name,and click input button","reminder",JOptionPane.WARNING_MESSAGE);
}
else if(e.getModifiers()==InputEvent.BUTTON1_MASK)
{
x = (int)e.getX();
y = (int)e.getY();
int a=(x+10)/20,b=(y+10)/20;
ChessPoint_black chesspoint_black=new ChessPoint_black(this);
ChessPoint_white chesspoint_white=new ChessPoint_white(this);
if(x/20<2||y/20<4||x/20>19||y/20>20)
{
}
else
{
if(chessColor==1)
{
this.add(chesspoint_black);
chesspoint_black.setBounds(a*20-10,b*20-10,20,20);
chessColor=chessColor*(-1);
text_2.setText(this.whitename+" please");
text_1.setText("");
}
else if(chessColor==-1)
{
this.add(chesspoint_white);
chesspoint_white.setBounds(a*20-10,b*20-10,20,20);
chessColor=chessColor*(-1);
text_1.setText(this.blackname+" please");
text_2.setText("");
}
}
}
}
public void mouseReleased(MouseEvent e)
{
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}
public void mouseClicked(MouseEvent e)
{
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==inputButton)
{
blackname=text_3.getText();
whitename=text_4.getText();
if(blackname.length()==0||whitename.length()==0)
{
JOptionPane.showMessageDialog(this,"you did not complete the information!","reminder",JOptionPane.WARNING_MESSAGE);
}
else if(blackname.equals("black'name"))
{
JOptionPane.showMessageDialog(this,"please input the black player's name","reminder",JOptionPane.WARNING_MESSAGE);
}
else if(whitename.equals("white'name"))
{
JOptionPane.showMessageDialog(this,"please input the white player's name","reminder",JOptionPane.WARNING_MESSAGE);
}
else
{
inputButton.setEnabled(false);
text_3.removeFo
…… 此处隐藏:4633字,全部文档内容请下载后查看。喜欢就下载吧 ……
相关推荐:
- [公文资料]市场营销专员岗位职责
- [公文资料]综合部经理岗位职责
- [公文资料]会计助理岗位职责
- [公文资料]林业站站长职责
- [公文资料]菜品研发部岗位职责
- [公文资料]街道综治办工作职责
- [公文资料]酒店前台的工作职责
- [公文资料]销售部经理岗位职责
- [公文资料]工程部副经理岗位职责
- [公文资料]手术室护士工作职责
- [公文资料]银行客户经理职责
- [公文资料]汽车4s店市场专员职责
- [公文资料]服装店长工作职责
- [公文资料]采购总监岗位职责
- [公文资料]大学行政秘书工作职责
- [公文资料]学校财务人员岗位职责
- [公文资料]财务统计员岗位职责
- [公文资料]物业工程主管工作职责
- [公文资料]公司后勤工作职责
- [公文资料]采矿工程师岗位职责
- 门面出租合同样板(门面出租的合同)
- 自用房屋租赁合同 自住房租房合同(汇总
- 最新酒店劳动合同管理制度(11篇)(酒店
- 2025年无产权车库买卖合同实用(14篇)(
- 建筑工程农民工劳动合同十五篇(通用)(
- 最新深圳标准劳动合同 深圳劳动合同如
- 解除劳动合同通知书(实用6篇)(解除劳动
- 2025年二手房屋买卖合同范围精选(二十
- 最新融资贷款居间合同大全(22篇)(融资
- 2025年个人二手房屋买卖合同协议书四篇
- 2025年果树苗木买卖合约书 签订果树苗
- 广东省劳动合同书填写(21篇)(广东省劳
- 最新餐饮行业没有劳动合同 劳动法餐饮
- 农村土地买卖合同(汇总21篇)(农村土地
- 最新房屋转租合同模版21篇(通用)(标准
- 2025年进口合同号查询五篇(大全)(进口
- 农村建房包工包料合同(通用8篇)(农村建
- 2025年安装监控合同协议书(15篇)(2025
- 2025年企业租赁经营合同(模板9篇)(2025
- 最新郊区土地租赁合同(优质23篇)(最新




