![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
|
I am making a cellular automota program and was wondering how I should go about the grid. I am doing it in swing as of now. The only thought that came to mind were JPanels that would have an image icon of blue for a live cell and white for dead. This would require a lot of typing unless I am able to create the 400 or so panels with a for statement. The problem is how would the syntax be written. I would just be throwing stuff out if I tried. Does anyone have sugtgestions?
p.s. Sorry to bug you with this question but GUI is not my strong point. I've been a command line programmer. Any suggestions are appreciated. Thank you for your time.
__________________
Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration. -S. Kelley |
|
|
|
|
|
#2 |
|
Newbie
Join Date: Nov 2004
Posts: 8
Rep Power: 0
![]() |
Maybe this is what your looking for??
import java.awt.*;
import javax.swing.*;
import java.util.*;
public class Cells extends JFrame
{
public Cells()
{
Container c = getContentPane();
JPanel p = new JPanel( new GridLayout( 40, 40 ) );
Random r = new Random( );
for (int i = 0; i<1600; i++)
{
JButton b = new JButton();
if ( r.nextInt( 100 ) < 50 )
b.setBackground( Color.BLUE );
else
b.setBackground( Color.WHITE );
p.add( b );
}
c.add( p );
setSize( 500, 500 );
setTitle( "Cellular Automata" );
setVisible( true );
}
public static void main(java.lang.String[] args)
{
Cells hey = new Cells();
hey.setDefau ltCloseOperation( JFrame.EXIT_ON_CLOSE );
}
} |
|
|
|
|
|
#3 |
|
Programmer
|
Thank you very much. I do not have the time to delve into it it at the moment but will hopefully be able to look at it more tomorrow. I appreciate your time as it looks good and interesting.
__________________
Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration. -S. Kelley |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|