Java写的围棋游戏的源代码.doc_第1页
Java写的围棋游戏的源代码.doc_第2页
Java写的围棋游戏的源代码.doc_第3页
Java写的围棋游戏的源代码.doc_第4页
Java写的围棋游戏的源代码.doc_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Java.txtA BSB import java.awt.*;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(blackname), text_4=new TextField(whitename); 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 players name,and click input button before you start chess!,reminder,JOptionPane.WARNING_MESSAGE); else if(blackname.equals(blackname) JOptionPane.showMessageDialog(this,please input the black players name,and click input button,reminder,JOptionPane.WARNING_MESSAGE); else if(whitename.equals(whitename) JOptionPane.showMessageDialog(this,please input the white players 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/202|y/2019|y/2020) 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(blackname) JOptionPane.showMessageDialog(this,please input the black players name,reminder,JOptionPane.WARNING_MESSAGE); else if(whitename.equals(whitename) JOptionPane.showMessageDialog(this,please input the white players name,reminder,JOptionPane.WARNING_MESSAGE); else inputButton.setEnabled(false); text_3.removeFocusListener(this); text_3.setEnabled(false); text_4.setEnabled(false); button.setEnabled(true); text_1.setEnabled(true); text_1.setText(blackname+ please); text_2.setEnabled(true); else if(e.getSource()=button) inputButton.setEnabled(true); text_3.setEnabled(true); text_4.setEnabled(true); button.setEnabled(false); text_1.setEnabled(false); text_2.setEnabled(false); this.removeAll(); chessColor=1; add(button); button.setBounds(35,36,60,26); add(text_1); text_1.setBounds(115,36,90,24); text_1.setText(black please); add(text_2); text_2.setBounds(315,36,90,24); text_2.setText(); add(inputButton); inputButton.setBounds(35,5,60,26); add(text_3); text_3.setText(blackname); text_3.addFocusListener(this); text_3.setBounds(115,5,90,24); add(text_4); text_4.setText(whitename); text_4.setBounds(315,5,90,24); blackname=; whitename=; class ChessPoint_black extends Canvas implements MouseListener ChessPad chesspad=null; ChessPoint_black(ChessPad p) setSize(20,20); chesspad=p; addMouseListener(this); public void paint(Graphics g) g.setColor(Color.black); g.fillOval(0,0,20,20); public void mousePressed(MouseEvent e) if(e.getModifiers()=InputEvent.BUTTON3_MASK) chesspad.remove(this); chesspad.chessColor=1; chesspad.text_2.setText(); chesspad.text_1.setText(chesspad.blackname+ please); public void mouseReleased(MouseEvent e) public void mouseEntered(MouseEvent e) public void mouseExited(MouseEvent e) public void mouseClicked(MouseEvent e) if(e.getClickCount()=2) chesspad.remove(this); class ChessPoint_white ext

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论