Eclipse multiple classes question
in
Integration and Hardware
•
10 months ago
Hello, everyone.
I am currently working on an applet which was started in Processing but which I then decided to finish using Eclipse. I've encountered a small issue however :
is it possible to create multiple instances with different parameters directly ?
By this I mean that the Eclipse Processing syntax, when using multiple classes would be
//PApplet
class blabla extends PApplet {
public void setup(){ ...
}
public void draw(){ ....
}
etc...
whatev = new Whatever(this)
...
}
class Whatever {
int thinga;
int thingb;
//Constructor
Public Whatever(int a, int b){
thing a = a;
thingb = b;
}
Whatever(PApplet p){
parent = p;
thing a = 1;
thing b = 2;
}
}
the parts in bold are what I have an issue with.
When I create a new instance in the class which extends PApplet, it will always start with 1 and 2 as parameters for thinga and thingb.
Isn't there any way to instantiate the way one does in Java without Processing ?
i.e. whatev1 = new Whatever(1,2);
whatev2 = new Whatever(2,3);
As such, I don't have to write a few extra lines to set whatev2's parameters to 2 and 3. If I want to create 1000 instances with different parameters, Processing's way of creating instances makes it slightly less practical. That is, unless I am missing something.
I also ecountered an issue when trying to load an image :
a huge OutOfMemory Exception when loading an image from data :
the following line inside setup() :
img = loadImage("carte_vhd_5240.jpg");
yields
Exception in thread "Image Fetcher 0" java.lang.OutOfMemoryError: Java heap space
at java.awt.image.DataBufferInt.<init>(Unknown Source)
at java.awt.image.Raster.createPackedRaster(Unknown Source)
at java.awt.image.DirectColorModel.createCompatibleWritableRaster(Unknown Source)
at sun.awt.image.ImageRepresentation.createBufferedImage(Unknown Source)
at sun.awt.image.ImageRepresentation.setPixels(Unknown Source)
at sun.awt.image.ImageDecoder.setPixels(Unknown Source)
at sun.awt.image.JPEGImageDecoder.sendPixels(Unknown Source)
at sun.awt.image.JPEGImageDecoder.readImage(Native Method)
at sun.awt.image.JPEGImageDecoder.produceImage(Unknown Source)
at sun.awt.image.InputStreamImageSource.doFetch(Unknown Source)
at sun.awt.image.ImageFetcher.fetchloop(Unknown Source)
at sun.awt.image.ImageFetcher.run(Unknown Source)
Exception in thread "Animation Thread" java.lang.OutOfMemoryError: Java heap space
at processing.core.PImage.<init>(PImage.java:285)
at processing.core.PApplet.loadImageMT(PApplet.java:5300)
at processing.core.PApplet.loadImage(PApplet.java:5145)
at processing.core.PApplet.loadImage(PApplet.java:5071)
at interfacegraphique.setup(interfacegraphique.java:23)
at processing.core.PApplet.handleDraw(PApplet.java:2103)
at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:190)
at processing.core.PApplet.run(PApplet.java:2006)
at java.lang.Thread.run(Unknown Source)
i am trying to make a small applet to visualise object trajectories. I am also wondering whether I should drop Processing altogether and stick with Eclipse, as the applet will require data processed with java and I have trouble linking Processing and Eclipse. How much more difficult would this applet be to create using Eclipse only ?
I am currently working on an applet which was started in Processing but which I then decided to finish using Eclipse. I've encountered a small issue however :
is it possible to create multiple instances with different parameters directly ?
By this I mean that the Eclipse Processing syntax, when using multiple classes would be
//PApplet
class blabla extends PApplet {
public void setup(){ ...
}
public void draw(){ ....
}
etc...
whatev = new Whatever(this)
...
}
class Whatever {
int thinga;
int thingb;
//Constructor
Public Whatever(int a, int b){
thing a = a;
thingb = b;
}
Whatever(PApplet p){
parent = p;
thing a = 1;
thing b = 2;
}
}
the parts in bold are what I have an issue with.
When I create a new instance in the class which extends PApplet, it will always start with 1 and 2 as parameters for thinga and thingb.
Isn't there any way to instantiate the way one does in Java without Processing ?
i.e. whatev1 = new Whatever(1,2);
whatev2 = new Whatever(2,3);
As such, I don't have to write a few extra lines to set whatev2's parameters to 2 and 3. If I want to create 1000 instances with different parameters, Processing's way of creating instances makes it slightly less practical. That is, unless I am missing something.
I also ecountered an issue when trying to load an image :
a huge OutOfMemory Exception when loading an image from data :
the following line inside setup() :
img = loadImage("carte_vhd_5240.jpg");
yields
Exception in thread "Image Fetcher 0" java.lang.OutOfMemoryError: Java heap space
at java.awt.image.DataBufferInt.<init>(Unknown Source)
at java.awt.image.Raster.createPackedRaster(Unknown Source)
at java.awt.image.DirectColorModel.createCompatibleWritableRaster(Unknown Source)
at sun.awt.image.ImageRepresentation.createBufferedImage(Unknown Source)
at sun.awt.image.ImageRepresentation.setPixels(Unknown Source)
at sun.awt.image.ImageDecoder.setPixels(Unknown Source)
at sun.awt.image.JPEGImageDecoder.sendPixels(Unknown Source)
at sun.awt.image.JPEGImageDecoder.readImage(Native Method)
at sun.awt.image.JPEGImageDecoder.produceImage(Unknown Source)
at sun.awt.image.InputStreamImageSource.doFetch(Unknown Source)
at sun.awt.image.ImageFetcher.fetchloop(Unknown Source)
at sun.awt.image.ImageFetcher.run(Unknown Source)
Exception in thread "Animation Thread" java.lang.OutOfMemoryError: Java heap space
at processing.core.PImage.<init>(PImage.java:285)
at processing.core.PApplet.loadImageMT(PApplet.java:5300)
at processing.core.PApplet.loadImage(PApplet.java:5145)
at processing.core.PApplet.loadImage(PApplet.java:5071)
at interfacegraphique.setup(interfacegraphique.java:23)
at processing.core.PApplet.handleDraw(PApplet.java:2103)
at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:190)
at processing.core.PApplet.run(PApplet.java:2006)
at java.lang.Thread.run(Unknown Source)
i am trying to make a small applet to visualise object trajectories. I am also wondering whether I should drop Processing altogether and stick with Eclipse, as the applet will require data processed with java and I have trouble linking Processing and Eclipse. How much more difficult would this applet be to create using Eclipse only ?
1