This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Building Blockchain Apps and have Michael Yuan on-line!
See this thread for details.
Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Newbie Swing Question

Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a rookie in java. (About 6 months). I am creating my own projects to try and learn new areas of Java.
I want to create a tic-tac-toe game. I know how to do it using JFrame, JPanel, JButtons (9 of them for o's and x's) with listeners set up for the buttons.
Note: I would like to create an application and not an applet.
I want to design it a different way for practice. All I want is a "Window" (I assume JFrame) with an area for displaying the x and o's when a user clicks on a certain area of the window.
As I see the program, it would start and have a blank screen with just the # (large display on the screen). When the user clicks on a valid area (mouse click where an x or o would be located in reference to the #), an x or o would appear or the mouse click would be ignored if they clicked on an are that already had an x or o.
I envision a JFrame with a JPanel with a GridLayout with 1 row x 1 column with a listener setup for the grid cell? I would then determine where in the grid cell the mouse was clicked.
Am I on the right track or is there an easier way to go about it? Can you direct me with code snippets or functions/classes/methods to look at?

[This message has been edited by Scott Matthews (edited July 12, 2001).]
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you want a 1x1 Grid Layout? It would be easier to have each button in its own cell. Then create a listener for the mouse click to change a button's label from number to X/O.
Everybody's invited. Even this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!