围棋(改进版)源代码-Java Applet小程序

上传人:鲁** 文档编号:488059138 上传时间:2022-10-21 格式:DOCX 页数:10 大小:15.85KB
返回 下载 相关 举报
围棋(改进版)源代码-Java Applet小程序_第1页
第1页 / 共10页
围棋(改进版)源代码-Java Applet小程序_第2页
第2页 / 共10页
围棋(改进版)源代码-Java Applet小程序_第3页
第3页 / 共10页
围棋(改进版)源代码-Java Applet小程序_第4页
第4页 / 共10页
围棋(改进版)源代码-Java Applet小程序_第5页
第5页 / 共10页
点击查看更多>>
资源描述

《围棋(改进版)源代码-Java Applet小程序》由会员分享,可在线阅读,更多相关《围棋(改进版)源代码-Java Applet小程序(10页珍藏版)》请在金锄头文库上搜索。

1、/*一个Java围棋程序源代码改进版(2010-05-12 09:55:19)转载标签: 杂谈 */ 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

2、 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

3、(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 startbutton=new Button(restart); Button inputButton=new Button(input); TextField text_1=new TextField(bl

4、ack 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); tex

5、t_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(startbutton); startbutton.setBounds(35,36,60,26); startbutton.setEnabled(false); startbutton.addActionListener(this); add(text_1); text_1.set

6、Bounds(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

7、=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(Focu

8、sEvent 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(e.getModifiers()=InputEvent.BUTTON1_MASK) x = (int)e.getX(); y = (int)e.getY(); int a=(x+10)/20,b=(y+

9、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(blackname.length()=0|whitename.length()=0) JOptionPane.showMessageDialog(this,please input the players name,and click input button befor

10、e 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,pl

11、ease input the white players name,and click input button,reminder,JOptionPane.WARNING_MESSAGE); 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(chessColo

12、r=-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

13、mouseClicked(MouseEvent e) public void actionPerformed(ActionEvent e) if(e.getSource()=inputButton) blackname=text_3.getText().trim(); whitename=text_4.getText().trim(); if(blackname.length()=0|whitename.length()=0) JOptionPane.showMessageDialog(this,you did not complete the information or you have input the illegal characteristics!,reminder,JOptionPane.WARNING_MESSAGE); else if(blackname.equals(blackname

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 商业/管理/HR > 营销创新

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号