Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Newbie Swing Question

 
Scott Matthews
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).]
 
Angela Lamb
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic