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.
Page Index Toggle Pages: 1
extend class (Read 1315 times)
extend class
Jul 22nd, 2006, 1:49pm
 
hi,

maybe a stupid mistake but i have problems to extend a class..
i have not much experience in java / processing oop.


public class myButton extends MyGUIButton {
   
 public myButton(processing.core.PApplet root, int x, int y)
 {
   super.MyGUIButton(root, x, y);
 }
}

error:
120:3: Semantic Error: No applicable overload was found for a constructor with signature "MyGUIButton()" in type "mkv.MyGUI.MyGUIButton". Perhaps you wanted the overloaded version "MyGUIButton(processing.core.PApplet $1, int $2, int $3);" instead?

the constructor exists with these arguments..

maybe someone can help me?

thanks, tazumi
Re: extend class
Reply #1 - Jul 22nd, 2006, 10:01pm
 
I'm in a similar situation. I have a function I've written that I was to extend pgraphics2 with, and I get the same error.
Re: extend class
Reply #2 - Jul 23rd, 2006, 9:03am
 
just call super() not super.MyGUIButton()

class Foo
{
 String name;
 Foo(String aname) {
   name = aname;
 }
 
 void printName() {
   println(name);
 }
}

class Bar extends Foo
{
 Bar(String aname) {
   super(aname);
 }
}

Foo f = new Foo("Steve");
f.printName();


Bar b = new Bar("ima bar");
b.printName();

Re: extend class
Reply #3 - Jul 23rd, 2006, 12:41pm
 
hi,

thanks a lot.. it works fine.

cheers
tazumi
Re: extend class
Reply #4 - Jul 23rd, 2006, 7:14pm
 
Ok, I'm not having any luck, I'd love some help...

Quote:


int counter;
int arc_start_x;
int arc_start_y;
int arc_height;
int random_height;


//  this won't work because myClass is extending PGraphics2, which takes 3 arguments to construct,
//  so this applet will launch, but fail because it's missing arguments
// myClass big = new myClass();

// this doesn't work because it won't find my extensions to pgraphics2 .. I'm so confused.
myClass big = new myClass(2000,2000,null);

// this will work but will fail on calling my function, obviously
// PGraphics2 big = new PGraphics2(2000,2000,null);


void setup() {

 //  so, shouldn't I be doing something in the setup after object construction to set these arguments as defaults?
 // big.height1(2000);
 // big.width1(2000);

 big.background(128);
 big.defaults();
 big.smooth();  

}

void draw()
{
 int randomNumber = int(random(width));
 for(int x=0;x<=2;x++)
 {

   // uncomment these, and they work fine because they're not in the class extension.
   big.stroke(int(random(255)),int(random(255)),100);  
   big.line(counter*10, randomNumber, int(random(2000)), int(random(2000)));
   int arc_start_x = int(random(2000));
   int arc_start_y = int(random(2000));
   int arc_height = int(random(1900,1900));

   // BONK...
   big.myFunction(arc_height, arc_start_x, arc_start_y);

 }
 // etc..


 counter++;
 if(counter >= 100)
 {
   //  big.endFrame();
   // make sure the file is written to the sketch folder
   String path = savePath("big-"+int(random(100000000,1000000000))+".png");
   big.save(path);  
   noLoop();

 }
}



class myClass extends PGraphics2
{

 void myFunction(int arc_height, int arc_start_x, int arc_start_y)
 {
   arc_height = abs(arc_height);
   arc(arc_start_x, arc_start_y, arc_height, arc_height, TWO_PI-PI/2, TWO_PI);

 }

}



Re: extend class
Reply #5 - Jul 23rd, 2006, 8:10pm
 
Ok, so to be clear, my goal here is to create sketches  using my own functions inside large files that I can save to disk.

So, I got it to stop complaining about nullPointerException on the setup object function calls, by extending PGraphics instead of PGraphics2, but... now I can't save the image because that's in PGraphics2, I'm guessing.

Quote:


int counter;
int arc_start_x;
int arc_start_y;
int arc_height;
int random_height;



//  this won't work because myClass is extending PGraphics2, which takes 3 arguments to construct,
//  so this applet will launch, but fail because it's missing arguments
myClass big = new myClass();

// this doesn't work because it won't find my extensions to pgraphics2 .. I'm so confused.
// myClass big = new myClass(2000,2000,null);

// this will work but will fail on calling my function, obviously
// PGraphics2 big = new PGraphics2(2000,2000,null);


void setup() {

 //  so, shouldn't I be doing something in the setup after object construction to set these arguments as defaults?
 // big.height1(2000);
 // big.width1(2000);

 big.background(128);
 big.defaults();
 big.smooth();  

}

void draw()
{
 int randomNumber = int(random(width));
 for(int x=0;x<=2;x++)
 {

   // uncomment these, and they work fine because they're not in the class extension.
   big.stroke(int(random(255)),int(random(255)),100);  
   big.line(counter*10, randomNumber, int(random(2000)), int(random(2000)));
   int arc_start_x = int(random(2000));
   int arc_start_y = int(random(2000));
   int arc_height = int(random(1900,1900));

   // BONK...
   big.myFunction(arc_height, arc_start_x, arc_start_y);

 }
 // etc..


 counter++;
 if(counter >= 100)
 {
   //  big.endFrame();
   // make sure the file is written to the sketch folder
   String path = savePath("big-"+int(random(100000000,1000000000))+".png");
   big.save(path);  
   noLoop();

 }
}



class myClass extends PGraphics
{

 int height1 = 2000;
 int width1 = 2000;


 void myFunction(int arc_height, int arc_start_x, int arc_start_y)
 {
   arc_height = abs(arc_height);
   arc(arc_start_x, arc_start_y, arc_height, arc_height, TWO_PI-PI/2, TWO_PI);

 }

}





here's the error

Quote:
java.lang.RuntimeException: Error while saving image.

at processing.core.PImage.save(PImage.java:2215)

at Temporary_271_588.draw(Temporary_271_588.java:57)

at processing.core.PApplet.handleDisplay(PApplet.java:1336)

at processing.core.PGraphics.requestDisplay(PGraphics.java:535)

at processing.core.PApplet.run(PApplet.java:1152)

at java.lang.Thread.run(Thread.java:613)


because the save function is in PGraphics2, not PGraphics, yeah?  How do I extend PGraphics2 and construct an object without parameters?  
Re: extend class
Reply #6 - Jul 25th, 2006, 11:01am
 
i am not sure but you do not call de constructor of the base class(?)


class myClass extends PGraphics2
{  
 // constructor of extended class, calls the constructor
 // of the base class (with fixed arguments)
 myClass()
 {
   super(arg1, arg1, arg3)
 }
 
 // alternative with arguments to pass to the base      
 // constructor
 myClass(int arg1, int arg2, int arg3)
 {
   super(arg1, arg1, arg3)
 }


 void myFunction(int arc_height, int arc_start_x, int arc_start_y)
 {
   //...

 }
}

someone correct me if i am wrong..


Re: extend class
Reply #7 - Jul 25th, 2006, 9:34pm
 
OH, create the PGrapics2 object inside my function? I will definitely need to poke around that idea.. thank you for the tip!
Re: extend class
Reply #8 - Jul 25th, 2006, 11:14pm
 
Well, I'm getting not the same type of problem now.  Inside of my class it appears to be valid to create a PGraphics2 object, thereby invoking the constructor with the valid arguments...  but now I'm having a problem on saving...


Quote:


int counter;
int arc_start_x;
int arc_start_y;
int arc_height;
int random_height;

// Ok, so this is the new deal... call PGraphics2 inside of my class?
myClass big = new myClass();

void setup() {
 big.background(128);
 big.defaults();
 big.smooth();  
}

void draw()
{
 int randomNumber = int(random(width));
 for(int x=0;x<=2;x++)
 {

   // uncomment these, and they work fine because they're not in the class extension.
   big.stroke(int(random(255)),int(random(255)),100);  
   big.line(counter*10, randomNumber, int(random(2000)), int(random(2000)));

   int arc_start_x = int(random(2000));
   int arc_start_y = int(random(2000));
   int arc_height = int(random(1900,1900));

   // working? can't tell.
   big.myFunction();

   arc_height = abs(arc_height);
   big.arc(arc_start_x, arc_start_y, arc_height, arc_height, TWO_PI-PI/2, TWO_PI);

 }

 counter++;
 if(counter >= 100)
 {
   // big.endFrame();
   // make sure the file is written to the sketch folder
   String path = savePath("big-"+int(random(100000000,1000000000))+".png");
   big.save(path);  
   noLoop();

 }
}

class myClass extends PGraphics
{
 // things seem to be working better with this... except saving the file doesn't work. :-\
 PGraphics2 big = new PGraphics2(2000,2000,null);

 void myFunction()
 {

   big.stroke(int(random(255)),int(random(255)),100);  
   big.line(counter*10, int(random(200)), int(random(2000)), int(random(2000)));

 }

}






error message:

Quote:
java.lang.RuntimeException: Error while saving image.

at processing.core.PImage.save(PImage.java:2215)

at Temporary_4897_7142.draw(Temporary_4897_7142.java:49)

at processing.core.PApplet.handleDisplay(PApplet.java:1336)

at processing.core.PGraphics.requestDisplay(PGraphics.java:535)

at processing.core.PApplet.run(PApplet.java:1152)

at java.lang.Thread.run(Thread.java:613)



ok, I thought it could be that I was trying to extend PGraphics instead of PGraphics2.  Here's the error message when I change "extends PGraphics" to "extends PGraphics2":

Quote:
java.lang.NullPointerException

at processing.core.PGraphics2.clear(PGraphics2.java:932)

at processing.core.PGraphics.background(PGraphics.java:3279)

at Temporary_1601_2818.setup(Temporary_1601_2818.java:12)

at processing.core.PApplet.handleDisplay(PApplet.java:1269)

at processing.core.PGraphics.requestDisplay(PGraphics.java:535)

at processing.core.PApplet.run(PApplet.java:1152)

at java.lang.Thread.run(Thread.java:613)

Re: extend class
Reply #9 - Jul 26th, 2006, 3:10pm
 
to back up a bit, i don't understand what you're trying to do. it doesn't sound like you need to subclass PGraphics or PGraphics2 at all, but rather that you want to either 1) just do a sketch with size(bignumber, bignumber) and call saveFrame() to save its contents. or, you should use createGraphics(), as described in the faq:
http://processing.org/faq/advanced.html#big
Re: extend class
Reply #10 - Jul 26th, 2006, 8:56pm
 
I have a function that I've written that draws a specific compound 2d mark... I could omit this step and just throw all the code into the draw() routine, as I've done here:

http://www.somejunkwelike.com/gallery/main.php?g2_itemId=34383&g2_imageViewsIndex=2

But, I was trying to get my head around some more OOP... Thanks for the additional tip, I'll give createGraphics() a try... hopefully next time this thread floats up, it will be because I figured it out.
Page Index Toggle Pages: 1