Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Gui for Conway's Game of Life

 
naveen yadav
Ranch Hand
Posts: 384
Java MyEclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 384
Java MyEclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how about creating a grid of rectangles using Graphics2D class ?
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Graphics2D is for painting with. It doesn't create rectangles or any other Shape.
 
naveen yadav
Ranch Hand
Posts: 384
Java MyEclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20768
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic