Using Switch....Case to change how a class is called .... is it possible?
in
Programming Questions
•
2 years ago
The following code works (if you have the class water_surface anyway). However, I want to change the image used by the class interactively or with a timer. For this, I thought of using a switch case situation. Unfortunately, if I uncomment the commented part of the code, processing throws a generic processing.app.debug.RunnerException: unexpected token: void
at processing.app.Sketch.preprocess(Sketch.java:1326)
at processing.app.Sketch.preprocess(Sketch.java:1205)
at processing.app.Sketch.build(Sketch.java:1568)
at processing.app.Sketch.build(Sketch.java:1553)
at processing.app.Editor$DefaultRunHandler.run(Editor.java:1485)
at java.lang.Thread.run(Thread.java:619)
error and highlights the line containing : void setup(){
I've looked the switch...case over and compared it to other working code and the only difference I can see is that I am calling a class in the switch statement. There doesn't seem to be a problem calling the class in draw outside of the switch...case statement. Is there something in the switch...case statement that I am missing?
at processing.app.Sketch.preprocess(Sketch.java:1326)
at processing.app.Sketch.preprocess(Sketch.java:1205)
at processing.app.Sketch.build(Sketch.java:1568)
at processing.app.Sketch.build(Sketch.java:1553)
at processing.app.Editor$DefaultRunHandler.run(Editor.java:1485)
at java.lang.Thread.run(Thread.java:619)
error and highlights the line containing : void setup(){
I've looked the switch...case over and compared it to other working code and the only difference I can see is that I am calling a class in the switch statement. There doesn't seem to be a problem calling the class in draw outside of the switch...case statement. Is there something in the switch...case statement that I am missing?
- PImage img1;
PImage img2;
PImage img3;
PImage img4;
PImage img5;
PImage bgimg;
public int dwidth;
public int dheight;
int bgno;
water_surface mywater_surface;
void setup() {
size(640, 420);
dwidth = 640;
dheight = 420;
img1 = loadImage("gully.jpg");
img2=loadImage("bunny-disquise.png");
img3=loadImage("bg__big_a.png");
bgno = 1;
bgimg = img2;
mywater_surface = new water_surface(bgimg);
}
void draw(){
// switch(bgno) {
// case '1':
// bgimg = img1;
// mywater_surface = new water_surface(bgimg);
// break;
// case '2':
// bgimg = img2;
// mywater_surface = new water_surface(bgimg);
// break;
// case default:
// bgimg = img3;
// mywater_surface = new water_surface(bgimg);
// break;
// }
mywater_surface.drawwater();
}
public void mouseDragged(){
mywater_surface.makeTurbulence(mouseX,mouseY);
}
public void mousePressed() {
mywater_surface.makeTurbulence(mouseX,mouseY);
}
1