permaculture playing cards
The moose likes Swing / AWT / SWT and the fly likes Newbie Swing Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Newbie Swing Question" Watch "Newbie Swing Question" New topic

Newbie Swing Question

Scott Matthews
Ranch Hand

Joined: Jun 28, 2001
Posts: 36
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

Joined: Feb 22, 2001
Posts: 156
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.
I agree. Here's the link:
subject: Newbie Swing Question
It's not a secret anymore!