File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Gui for Conway's Game of Life Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Gui for Conway Watch "Gui for Conway New topic

Gui for Conway's Game of Life

naveen yadav
Ranch Hand

Joined: Oct 23, 2011
Posts: 384

hi ranchers,

Need suggestion for developing the Gui interface of Conway Game of Life. I think Swing does not have components to display a grid of cells.

Please suggest a library or api to create a gui.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
If you really want to use Swing components, then a GridLayout (with each cell holding some custom component of yours) might work, although that would be a very unusual approach.

You could use a JTable with very small cells.

I'd probably use a Canvas with each cell represented by a cluster of 2x2 or 3x3 pixels.
naveen yadav
Ranch Hand

Joined: Oct 23, 2011
Posts: 384

how about creating a grid of rectangles using Graphics2D class ?
Darryl Burke

Joined: May 03, 2008
Posts: 5115

Graphics2D is for painting with. It doesn't create rectangles or any other Shape.

luck, db
There are no new questions, but there may be new answers.
naveen yadav
Ranch Hand

Joined: Oct 23, 2011
Posts: 384

public void paint(Graphics g) {

g.drawRect (100, 50, width, height);


Graphic class has drawRect() to draw rectangle, will it not work f i create grid of these rectangle ?
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Bear in mind that the size of the configurations you'll encounter can be unbounded. In other words you could require a very large area to draw on. You might want to provide scrolling, rather than trying to scale extremely large displays into a component of fixed size.
I agree. Here's the link:
subject: Gui for Conway's Game of Life
It's not a secret anymore!