• 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 ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • 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.
 
You would be much easier to understand if you took that bucket off of your head. And that goes for the tiny ad too!
ScroogeXHTML 8.7 - RTF to HTML5 and XHTML converter
https://coderanch.com/t/730700/ScroogeXHTML-RTF-HTML-XHTML-converter
    Bookmark Topic Watch Topic
  • New Topic