Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.List;
- import java.awt.event.*;
- import javax.swing.*;
- import java.util.*;
- import java.util.Timer;
- public class Board extends JPanel implements ActionListener {
- boolean isFirst = false;
- int ii;
- int jj;
- int iii;
- int jjj;
- WhiteChecker w;
- BlackChecker b;
- public Image img;
- Timer time;
- static int xxx;
- public Board() {
- Checker.init();
- addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent e) {
- if (isFirst == false) {
- for (int j = 0; j < 8; j++) {
- for (int i = 0; i < 8; i++) {
- if (Checker.hist[i][j] == clickX(e.getX()))
- {ii = i;
- jj = j;System.out.println(ii+" "+jj);}
- }
- }
- for (int j = 0; j < 8; j++) {
- for (int i = 0; i < 8; i++) {
- if (Checker.hist[i][j] == clickY(e.getY()))
- {iii = i;
- jjj = j;System.out.println(iii+" "+jjj);}
- }
- }
- isFirst = true;
- } else {
- Checker.curr[iii][jjj] = clickY(e.getY());
- Checker.curr[ii][jj] = clickX(e.getX());System.out.println("x="+clickX(e.getX()));System.out.println("y="+clickY(e.getY()));
- isFirst = false;
- }
- };
- });
- setFocusable(true);
- ImageIcon i = new ImageIcon("src/1.gif");
- img = i.getImage();
- time = new Timer(5, this);
- time.start();
- }
- public void init() {
- }
- public void move() {
- }
- public int clickY(int y) {
- int minY = 0;
- int maxY = 700;
- int ret;
- for (int j = 0; j < 8; j++) {
- for (int i = 0; i < 8; i++) {
- if (Checker.hist[i][j] > y && (maxY > Checker.hist[i][j])) {
- maxY = Checker.hist[i][j];
- }
- if (Checker.hist[i][j] < y && (minY < Checker.hist[i][j])) {
- minY = Checker.hist[i][j];
- }
- }
- }
- if ((maxY - y) > (y - minY)) {
- ret = minY;
- } else {
- ret = maxY;
- }
- return ret;
- }
- public int clickX(int x) {
- int minX = 0;
- int maxX = 700;
- int ret;
- for (int j = 0; j < 8; j++) {
- for (int i = 0; i < 8; i++) {
- if (Checker.hist[i][j] > x && (maxX > Checker.hist[i][j])) {
- maxX = Checker.hist[i][j];
- }
- if (Checker.hist[i][j] < x && (minX < Checker.hist[i][j])) {
- minX = Checker.hist[i][j];
- }
- }
- }
- if ((maxX - x) > (x - minX)) {
- ret = minX;
- } else {
- ret = maxX;
- }
- return ret;
- }
- public void actionPerformed(ActionEvent e) {
- repaint();
- }
- public void paint(Graphics g) {
- Graphics g2d=g;
- g2d.drawImage(img, 0, 0, null);
- for (int j = 0; j < 8; j++) {
- for (int i = 0; i < 8; i++) {
- if (Checker.hist[i][j]==1) {
- g2d.drawImage(b.getImage(), 28+i*34,
- 7+j*35, null);
- }
- }
- }
- for (int j = 0; j < 8; j++) {
- for (int i = 0; i < 8; i++) {
- if (Checker.hist[i][j]==2) {
- g2d.drawImage(w.getImage(), 28+i*34,
- 7+j*35, null);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement