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)
   classes, extending, modes, incompetence...
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: classes, extending, modes, incompetence...  (Read 721 times)
GaryFixler


classes, extending, modes, incompetence...
« on: Apr 11th, 2004, 8:42pm »

If I put g.show() in setup(), the image is drawn. I'm curious as to why it doesn't bridge the gap between setup and mousePressed. Am I mixing Active and Java modes?
 
class GImage
{
  BImage img;
   
  GImage (String i)
  {
    img = loadImage(i);
  }
   
  void show ()
  {
    image(img, 0, 0);
  }
}
 
GImage g;
 
void setup ()
{
  size(400, 300);
  g = new GImage("goog.jpg");
}
 
void mousePressed ()
{
  g.show();
}
 
I know a good number of languages now, but Processing is my newest, and Java isn't in the list. I know very little Java, and I'm looking for some good tutorials on classes and extending them. I need to get acquainted more with public, private, protected, extends, static, abstract, etc...
 
Thanks!
 

--
Gary Fixler
v3ga

WWW Email
Re: classes, extending, modes, incompetence...
« Reply #1 on: Apr 11th, 2004, 9:30pm »

Hello Gary,
 I see two problems related to your code. The first one is the loop() method which is not implemented. It is where you can draw something to the drawable area. Setup() is called once at the start , so if you draw your image there, that's ok, it is drawn to the screen (provided nothing is in the loop() method)  
Secondly, mousePressed is an event which is only sent once (when user has clicked a mouse button). Something like this would work :  
Code:

class GImage  
{  
  BImage img;  
    
  GImage (String i)  
  {  
    img = loadImage(i);  
  }  
    
  void show ()  
  {  
    image(img, 0, 0);  
  }  
}  
 
GImage g;  
boolean isShowImage = false;  
void setup ()  
{  
  size(400, 300);  
  g = new GImage("goog.jpg");  
}  
 
 void loop()
 {
  background(255);  
  if (isShowImage) g.show();  
    
 }
 
void mousePressed ()  
{  
  isShowImage = !isShowImage; // simple switch
}  

 
 
Hope it helps !
« Last Edit: Apr 11th, 2004, 9:31pm by v3ga »  

http://v3ga.net
GaryFixler


Re: classes, extending, modes, incompetence...
« Reply #2 on: Apr 11th, 2004, 9:36pm »

Interesting! Your reply got me thinking. Without a loop() in there, the setup is run, the mousePressed is created, but then the program ends.
 
By just putting an empty loop(){} after setup, the program continues to run, and the mousePressed now works! Cool. Of course, I'll be using the loop, but I was just curious why mousePressed wasn't functioning. I think that's solved now. As long as the program is running (looping), the mousePressed event can continue to be listened for.
 
Thanks very much. I'm still open to suggestions on quick starts into Java inheritance. I have some ideas that I feel are being held back by not understanding the class system. I'll keep looking in the meantime.
 

--
Gary Fixler
amoeba

WWW
Re: classes, extending, modes, incompetence...
« Reply #3 on: Apr 11th, 2004, 10:35pm »

Since classes, inheritance etc. in Processing is ultimately taken from Java, the java.sun.com site is not a bad place to start. Their New to Java is not too bad all considered, and the Learning the Java language "trail" should set you on the right path. Dry reading, but not too technical.
« Last Edit: Apr 11th, 2004, 10:36pm by amoeba »  

marius watz // amoeba
http://processing.unlekker.net/
mKoser

WWW Email
Re: classes, extending, modes, incompetence...
« Reply #4 on: Apr 11th, 2004, 11:34pm »

or you could trust the words of mr. processing:
http://acg.media.mit.edu/people/fry/explain/java/
 

mikkel crone koser | www.beyondthree.com | http://processing.beyondthree.com
amoeba

WWW
Re: classes, extending, modes, incompetence...
« Reply #5 on: Apr 12th, 2004, 12:16am »

Great link, thanks (and thanks to ben, of course..)  Guess this info should be a FAQ, I know I will certainly provide these links to my Processing students.
 

marius watz // amoeba
http://processing.unlekker.net/
GaryFixler


Re: classes, extending, modes, incompetence...
« Reply #6 on: Apr 12th, 2004, 4:27am »

Wow! This is enough to tide me over for a few months. Now I just need a USB-2-Brain cable so I don't have to copy all this info manually
 
Thanks for the great links, folks!
-g
 

--
Gary Fixler
Pages: 1 

« Previous topic | Next topic »