Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 10th, 2004, 11:05 PM   #1
BebopFusion
Programmer
 
Join Date: Oct 2004
Posts: 52
Rep Power: 5 BebopFusion is on a distinguished road
Send a message via ICQ to BebopFusion
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
BebopFusion is offline   Reply With Quote
Old Nov 15th, 2004, 2:25 AM   #2
drunkenCoder
Newbie
 
drunkenCoder's Avatar
 
Join Date: Nov 2004
Posts: 8
Rep Power: 0 drunkenCoder is on a distinguished road
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 );
   }
}
Of course you are probably going to want to change the way the buttons get their color assigned to them. It is completely random as it is now.
drunkenCoder is offline   Reply With Quote
Old Nov 15th, 2004, 10:00 PM   #3
BebopFusion
Programmer
 
Join Date: Oct 2004
Posts: 52
Rep Power: 5 BebopFusion is on a distinguished road
Send a message via ICQ to BebopFusion
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
BebopFusion is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:14 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC