⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chesspad.java

📁 这是五子棋的一个小游戏 和简单的 我只用了java就搞定了 大家可以试试
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
class ChessPad extends Panel implements MouseListener,ActionListener{
	int z=0;
	Button b1 = new Button("帮助");
	Button b2 = new Button("关于五子棋");
	Button b3 = new Button("重新开局");
	TextField t1=new TextField(" 请 黑 棋下子");
	TextField t2 = new TextField();
	ChessPad(){
		setLayout(null);
		setBackground(Color.gray);
		addMouseListener(this);
		
		add(t1);
		add(t2);
		t1.setBounds(90, 0, 500, 26);
		t2.setBounds(410, 70, 70, 26);
		t1.setEditable(false);
		t2.setEditable(false);
		add(b1);
		add(b2);
		add(b3);
		b1.setBounds(410, 170, 70, 26);
		b2.setBounds(410, 270, 70, 26);
		b3.setBounds(410, 370, 70, 26);
		b1.addActionListener(this);
		b2.addActionListener(this);
		b3.addActionListener(this);
	}
	
	public void paint(Graphics g) {
		for (int i = 40; i <= 400; i = i + 20) {
			g.drawLine(40, i, 400, i);
		}
		for (int j = 40; j <= 400; j = j + 20) {
			g.drawLine(j, 40, j, 400);
		}
		g.fillOval(97, 97, 6, 6);
		g.fillOval(337, 97, 6, 6);
		g.fillOval(97, 337, 6, 6);
		g.fillOval(337, 337, 6, 6);
		g.fillOval(217, 217, 6, 6);
	}
	public void mousePressed(MouseEvent e) {
		int x,y;
		int a, b;
		if (e.getModifiers() == InputEvent.BUTTON1_MASK) {
			x = (int) e.getX();
			y = (int) e.getY();
			if ( (x + 5) / 20 < 2 || (y + 5) / 20 < 2 || (x - 5) / 20 > 19 ||(y - 5) / 20 > 19) {}
			else {
				a = (x + 10) / 20;
				b = (y + 10) / 20;
				int i=a-2;
				int j=b-2;
				if(z==0){
					Black blackpoint = new Black(this);
					this.add(blackpoint);
					blackpoint.setBounds(a * 20 - 9, b * 20 - 9, 17, 17);
					t1.setText(" 请 白 棋下子");
					z=1;
				}
				else{
					White whitepoint = new White(this);
					this.add(whitepoint);
					whitepoint.setBounds(a * 20 - 9, b * 20 - 9, 17, 17);
					t1.setText(" 请 黑 棋下子");
					z=0;
				}
				t2.setText(" "+i+" "+j);
			}
		}
	}
	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()==b3){
			this.removeAll();
			add(t1);add(t2);add(b1);add(b2);add(b3);
			z = 0;
			t1.setText(" 请 黑 棋下子");
			t2.setText("");
		}
		if(e.getSource()==b1){
			Help help=new Help();
		}
		if(e.getSource()==b2){
			About about=new About();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -