java
1package othello; 2 3import java.awt.Color; 4import java.awt.Dimension; 5import java.awt.Graphics; 6import java.awt.event.MouseEvent; 7import java.awt.event.MouseListener; 8import java.util.Observer; 9 10import static othello.CommonConst.*; 11import javax.swing.JPanel; 12 13import javafx.beans.InvalidationListener; 14import javafx.beans.Observable; 15 16public class Board extends JPanel implements MouseListener,Observable{ 17 int[][] boardarray = new int[MASS][MASS]; 18 19 public Board() { 20 // TODO 自動生成されたコンストラクター・スタブ 21 setPreferredSize(new Dimension(HI, WI)); 22 addMouseListener(this); 23 } 24 25 public void paint(Graphics graphi) { 26 graphi.setColor(BOARDCOLOR); 27 graphi.fillRect(0, 0, HI, WI); 28 29 graphi.setColor(LINECOLOR); 30 for (int i = 0; i < MASS; i++) { 31 graphi.drawLine(0, i * SIZE, WI, i * SIZE); 32 graphi.drawLine(i * SIZE, 0, i * SIZE, HI); 33 } 34 boardarray[3][3] = 1; 35 boardarray[3][4] = 2; 36 boardarray[4][3] = 2; 37 boardarray[4][4] = 1; 38 for (int y = 0; y < MASS; y++) { 39 for (int x = 0; x < MASS; x++) { 40 if (boardarray[x][y] == 1) { 41 graphi.setColor(Color.BLACK); 42 graphi.fillOval(x * SIZE, y * SIZE, SIZE, SIZE); 43 } else if (boardarray[x][y] == 2) { 44 graphi.setColor(Color.WHITE); 45 graphi.fillOval(x * SIZE, y * SIZE, SIZE, SIZE); 46 } 47 48 } 49 50 } 51 52 } 53 54public void update(Observable o, Object arg) { 55 repaint(); 56 } 57 58 @Override 59 public void mouseClicked(MouseEvent e) { 60 // TODO 自動生成されたメソッド・スタブ 61 62 } 63 64 @Override 65 public void mousePressed(MouseEvent e) { 66 // TODO 自動生成されたメソッド・スタブ 67 int x = e.getX(); 68 int y = e.getY(); 69 x /= SIZE; 70 y /= SIZE; 71 if (Decision.canReverse(x, y, boardarray, turn)==false){ 72 System.out.println("ここには置けません"); 73 }else{ 74 boardarray[x][y]=turn; 75 } 76 System.out.println(x + "," + y); 77 } 78 79
上記のコードでオセロを作ったのですが、駒が再描画されないのでうまくいきません。まだ、その他バグはありますがまず再描画させて動きを確認しながら他のバグは潰していきたいと思います。よろしくお願いします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。