Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help in starting with GUI programming  RSS feed

 
Ranajoy Saha
Ranch Hand
Posts: 99
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Everyone

Recently, I made a Tic Tac Toe program. It's quite tedious for users to put the co-ordinates every time they want to make a move, so I am thinking of implementing this on a GUI, but I have no knowledge what so ever about GUI based programs, I've tried googling but either the stuff that's coming up isn't helpful enough or the stuff that I don't understand. It would be very nice, if someone experienced would guide me here. Thanks in advance.

Regards,
Ranajoy Saha

OUTPUT:
Welcome to TicTacToe
Here is your play area....

1 2 3
1 - - -

2 - - -

3 - - -

Moves : 0
Player 'X' is to move
Enter row number [1,2,3] :2
Enter column number [1,2,3] :3


1 2 3
1 - - -

2 - - X

3 - - -

Moves : 1
Player 'O' is to move
Enter row number [1,2,3] :1
Enter column number [1,2,3] :1


1 2 3
1 O - -

2 - - X

3 - - -

Moves : 2
Player 'X' is to move
Enter row number [1,2,3] :2
Enter column number [1,2,3] :2


1 2 3
1 O - -

2 - X X

3 - - -

Moves : 3
Player 'O' is to move
Enter row number [1,2,3] :2
Enter column number [1,2,3] :1


1 2 3
1 O - -

2 O X X

3 - - -

Moves : 4
Player 'X' is to move
Enter row number [1,2,3] :3
Enter column number [1,2,3] :1


1 2 3
1 O - -

2 O X X

3 X - -

Moves : 5
Player 'O' is to move
Enter row number [1,2,3] :1
Enter column number [1,2,3] :3


1 2 3
1 O - O

2 O X X

3 X - -

Moves : 6
Player 'X' is to move
Enter row number [1,2,3] :3
Enter column number [1,2,3] :2


1 2 3
1 O - O

2 O X X

3 X X -

Moves : 7
Player 'O' is to move
Enter row number [1,2,3] :1
Enter column number [1,2,3] :2


1 2 3
1 O O O

2 O X X

3 X X -

Player 'O' has won!

TicTacToe.java


TicTacToePlay.java
 
Knute Snortum
Sheriff
Posts: 3559
86
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This site will get you going with GUI. If you have Java 8 to work with, I would suggest using JavaFX, otherwise Swing.

TicTacToe is a difficult GUI to begin with. You might want to try a simpler program first.

Edit: I have a GitHub project that uses JavaFX, if you want to look at it. Full disclosure: I am not an expert at this.
 
Campbell Ritchie
Sheriff
Posts: 53779
128
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you got an interface in your program where you can enter the number of the square for the next move? Have you got an interface which returns the current state of the board? You need to be able to writeor similar. Then it will be quite easy to put a 3×3 grid of JButtons on a display and use each button to signal a move made.

Yes, you would appear to have such an interface. I would suggest you want a GUI with 9 JButtons and a JLabel which displays things like, “X to play”.

[edit:]Moving to our GUIs forum.
 
Ranajoy Saha
Ranch Hand
Posts: 99
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Knute Snortum, I'll go to the GitHub right away and begin my work. Campbell Ritchie, yes, I have an interface in the program in which the user needs to enter the number of the square for the next move.

Taking the square number from the user



Passing the values to the inserAt(int x, int y) method



The insertAt() method itself

 
Tim Nachreiner
Ranch Hand
Posts: 36
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a simple gui to get you started. You need to put two images in the tictactoe package also: named X.png and O.png.





 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!