java - Creating simple TicTacToe GUI game -
I am trying to create a simple tick-to-play game using the GUI. I have a button that shows the player's turn (when the button is pressed, it changes its text to 0 or 1 (drawing X or O)). Although I'm stuck with a problem here, I do not know that my testing within the MouseListener applies to all the JC component objectives (to expand my class tic tacca) and all 9 panels, which are gridlight 3,3) are filled with the same drawing ...
Here is my tick ticket class
public class TicTacToe JComponent {Private int ovalOrx = 0; Public TicTacToe () {super.setPreferredSize (new dimension (300,300)); } Public Zero Paint Component (Graphics G) {g.setColor (Color.BLACK); G.drawLine (0, 0, getWidth (), 0); // headline g.drawline (0, 0, getHeight ()); // left line g.drawline (0, 300, getWidth (), GetHeight ()); // bot line live getthought (getWidth), getHeight (), getWidth (), 0); // Right line if (ovalonex == 1) {g.setColor (Color.RED); G.drawLine (0,0,100,100); G.drawLine (0, 100, 100,0); } If (ovalonex == 2) {g.setColor (Color.BLUE); G.drawOval (0,0,100,100); }} Public zero drawX () {ovalOrX = 1; Repaint (); } Public Zero DrawCrack () {ovalOrX = 2; Repaint (); }}
And here's my Jeffram class:
Public class TicTacToeFrame extends JFrame {Personal Static FINAL FREQUENSIVE FRAME_WIDTH = 300; Personal fixed final distance FRAME_HEIGHT = 300; Private Jepinel MainPanel; Private TicTacToe view; Private Tecto s00; Private Tecto s01; Private Tecto s02; // Top top raw personal TicTacToe s10; Private TicTacToe s11; Private TicTacToe s12; // Finish Crude Private TicTacToe s20; Private Tictacu s21; Private TicTacToe s22; Private int button = 0; Private Jebton Oaks; Class AddButtonListener Apply ActionListener {Public Zero Action Action (EventEvent Event) {if (buttonInt == 0} {buttonInt ++; } And if (Button == 1) {buttonInt = 0; } OX.setText ("Player:" + no button); I if (buttonInt == 0) {for (int i = 0; i
return value of event.getPoint ()
Regarding the source component, a TicTacToe
is not a whole frame in this case, therefore, it will always be all right for TictacToe
because they are all the same size. Use Istead, to determine the source object.
Also, it is advisable to put all of you to list the TicTacToe
object in a TicTacToe [] []
.
Comments
Post a Comment