We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › GUI for application
Page Index Toggle Pages: 1
GUI for application (Read 346 times)
GUI for application
Sep 3rd, 2006, 1:24pm
 
for the 'game of Life' application found at ( http://www.metaphorical.net/code/processing/index2.html?page=life ) ) I'd like to add some GUI elements. Now it just starts and contunues to run for ever. I assume this takes on processing power when using this on a webpage, so i'd like to add a "start" and "stop" image button.

Second, how is the color define of the active cell. When ever i change the value also the value of the inactive cells change. Used is this code
Code:

void life() {

for (int i=0; i<W; i++) {
for (int k=0; k<H; k++) {

fill( 255, ((life[i][k]) ? 0 : 255), 255 );
rect( i*cellw, k*cellh, cellw, cellh );

}
}

}

Having never worked with 'Processing' or any other programming software i'm kinda stuck here. I'd look at the source of the 'buttons' examples ( > http://www.processing.org/learning/examples/button.html ), but didn't manage to get it working. The buttons get positioned in the running application while i need to to be at the border in an empty zone. Next step is to have them start and stop the application (or even reset)

Or is there another way to do this (via a html button ??)

Any help is much appriciated. Thx
Re: GUI for application
Reply #1 - Sep 4th, 2006, 6:47am
 
This is a somewhat shameless plug for a project I'm working on, but the Interfascia library is designed to make it easy to add things like buttons to your processing sketch.

In your case, you'd need to add the following before void setup():
Code:
GUIController c;
IFButton startButton, stopButton;


And you'd need this code inside setup():
Code:
c = new GUIController(this);
startButton = new IFButton("Start", 20, 20, 40);
stopButton = new IFButton("Stop", 80, 20, 40);

c.add(startButton);
c.add(stopButton);

startButton.addActionListener(this);
stopButton.addActionListener(this);


And finally, you'll need to add the following method:
Code:
void actionPerformed(GUIEvent e) {
if (e.getSource() == startButton) {
running = true;
} else if (e.getSource() == stopButton) {
running = false;
}
}
Page Index Toggle Pages: 1