This week's book giveaway is in the Spring forum.
We're giving away four copies of Modern frontends with htmx and have Wim Deblauwe on-line!
See this thread for details.
Win a copy of Modern frontends with htmx this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need help in starting with GUI programming

 
Ranch Hand
Posts: 106
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79082
376
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 106
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Ranch Hand
Posts: 93
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.





 
I don't always make ads but when I do they're tiny
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic