当前位置: 技术问答>java相关
求助,谁有五子棋java源代码?帮个忙,以一千分送之。
来源: 互联网 发布时间:2017-04-16
本文导语: 单机版的,不用很精致的 我的qq是14464467 mail是ghyd@sina.com | import javax.swing.*; import java.awt.*; import java.awt.event.*; public final class ChessPanel extends JPanel { private int width = 20; private int n = 19...
单机版的,不用很精致的
我的qq是14464467
mail是ghyd@sina.com
我的qq是14464467
mail是ghyd@sina.com
|
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public final class ChessPanel extends JPanel {
private int width = 20;
private int n = 19;
private int[][] chess;
private int current = 1;
public static void main(String[] args) {
JFrame aFrame = new JFrame();
aFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
aFrame.addWindowListener(new WindowAdapter() {
public void windowClosed(WindowEvent e) {
System.exit(0);
}
});
aFrame.getContentPane().add(new ChessPanel());
aFrame.setSize(450, 450);
aFrame.show();
}
public ChessPanel() {
chess = new int[n][n];
this.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
int i = (e.getX() + width / 2) / width - 1;
int j = (e.getY() + width / 2) / width - 1;
if (chess[i][j] == 0) {
chess[i][j] = current;
current = -current;
ChessPanel.this.repaint();
}
}
});
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
for (int i = 0; i
import java.awt.*;
import java.awt.event.*;
public final class ChessPanel extends JPanel {
private int width = 20;
private int n = 19;
private int[][] chess;
private int current = 1;
public static void main(String[] args) {
JFrame aFrame = new JFrame();
aFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
aFrame.addWindowListener(new WindowAdapter() {
public void windowClosed(WindowEvent e) {
System.exit(0);
}
});
aFrame.getContentPane().add(new ChessPanel());
aFrame.setSize(450, 450);
aFrame.show();
}
public ChessPanel() {
chess = new int[n][n];
this.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
int i = (e.getX() + width / 2) / width - 1;
int j = (e.getY() + width / 2) / width - 1;
if (chess[i][j] == 0) {
chess[i][j] = current;
current = -current;
ChessPanel.this.repaint();
}
}
});
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
for (int i = 0; i
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
站内导航:
特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!