FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   ImageButton class......I'm a newbie
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: ImageButton class......I'm a newbie  (Read 261 times)
theboyofspewn


ImageButton class......I'm a newbie
« on: Oct 6th, 2004, 12:59am »

I'm unsure how to go about creating multiple image based buttons in processing.  I have written out all of the code as I understand it, creating a different class for each button to declare all of the functions of each different button.  When I attempt to run it I get an error because I declare the ImageButton class multiple times, though each declaration extends a different button class.  How would I go about solving this problem?
 
fjen

WWW
Re: ImageButton class......I'm a newbie
« Reply #1 on: Oct 6th, 2004, 2:18am »

hmm. it's kind of difficult to answer without code, can you post what you have so far?
 
there are many ways of doing what you want to do ... the easiest for you might be to have one kind (class) of button, give each instance different images to load via it's constructor ( MyButton  mybutton = new MyButton("image.gif", "image_over.gif", "image_pressed.gif"); ). then use the loop() to check wether a button is clicked (or mouse is over it) and what to do then ..
 
/F
 
fjen

WWW
Re: ImageButton class......I'm a newbie
« Reply #2 on: Oct 6th, 2004, 2:27am »

if you've build on this:
 
http://processing.org/learning/examples/image_button.html
 
just use this in the loop to handle the button:
Code:

void loop()  
{  
  button.update();
if (button.pressed) handleButton();  
  button.display();
}
void handleButton()
{
  // your code for button here //
}

 
... if you want to use more than one button just create more instances, say button1, button2, .. and then handle each of them the same way as shown above:
 
Code:

void loop()  
{  
  button.update(); button1.update(); button2.update();
if (button.pressed) handleButton();
if (button1.pressed) handleButton1();  
if (button2.pressed) handleButton2();  
  button.display(); button1.display(); button2.display();
}
void handleButton() { /* your code for button here */ }
void handleButton1() { /* your code for button1 here */ }
void handleButton2() { /* your code for button2 here */ }

 
/F
« Last Edit: Oct 6th, 2004, 2:28am by fjen »  
theboyofspewn


Re: ImageButton class......I'm a newbie
« Reply #3 on: Oct 6th, 2004, 4:04am »

Thanks much for the help.  I think I have figured it out, and it seems to be working now.
 
Pages: 1 

« Previous topic | Next topic »