Loading...
Logo
Processing Forum
i´m new to this forum and need help..
i use netbeans and i want to create a ui library.

with the method "registerDraw()" and declaring the function "draw()" inside the class, it works properly.
but when i want to "registerMouseEvent()" and declare the function "mouseEvent()" an error occurs.

Copy code
  1. Exception in thread "Animation Thread" java.lang.RuntimeException: There is no public mouseEvent() method in the class processing2.sketch$HFader
  2. at processing.core.PApplet.die(PApplet.java:2571)
  3. at processing.core.PApplet.registerWithArgs(PApplet.java:974)
  4. at processing.core.PApplet.registerMouseEvent(PApplet.java:935)
  5. at processing2.sketch$HFader.<init>(sketch.java:68)
  6. at processing2.sketch.setup(sketch.java:26)
  7. at processing.core.PApplet.handleDraw(PApplet.java:1608)
  8. at processing.core.PApplet.run(PApplet.java:1530)
  9. at java.lang.Thread.run(Thread.java:680)
in the processing ide it works, but not in netbeans.

Copy code
  1. import processing.core.*;

  2. public class sketch extends PApplet {
  3.     
  4.     PApplet app = this;

  5.     HFader hf1;

  6.     public void setup() {
  7.         size(600, 600);
  8.         frameRate(30);
  9.         noStroke();
  10.         
  11.         hf1 = new HFader();
  12.     }

  13.     public void draw() {
  14.         
  15.     }

  16.     public class HFader {

  17.         HFader() {
  18.             app.registerDraw(this);
  19.             app.registerMouseEvent(this);
  20.         }
  21.         
  22.         public void draw() {
  23.             println("draw");
  24.         }
  25.         
  26.         public void mouseEvent(MouseEvent e) {
  27.             println("mouseEvent: " + e);
  28.         }
  29.     }
  30. }
even when i want to declare the method mouseEvent wit its parameter, netbeans says that it doesnt find a class called MouseEvent

hope someone can help me.
sorry for the bad english...

regards

Replies(2)

Processing will add the appropriate imports by default but Netbeans and Eclipse won't. It means that you need to add the import yourself.

In your code at line 3 add

import java.awt.event.MouseEvent;

The draw method works because it is only using Java classes imported by Processing.

Line 33 is the CORRECT syntax for the mouse event handling method when you use the registerMouseEvent() method.

Although your code has the correct syntax it only works because HFader is an inner class making the variable app  visible to it. If you are going to create a UI library then classes like HFader should be top-level classes to do this they must be declared in their own file. The 2 code segments below show how this can be done in Netbeans or Eclipse. The file names are important in that they are classname.java I have also called renamed your class to Sketch since by convention class names start with a capital letter.

File Sketch.java
Copy code
  1. import processing.core.*;

  2. public class Sketch extends PApplet {
  3.     
  4.       HFader hf1;

  5.       public void setup() {
  6.          size(600, 600);
  7.       frameRate(30);
  8.       noStroke();
  9.         
  10.       hf1 = new HFader(this);
  11.    }

  12.    public void draw() {
  13.         
  14.    }
  15. }
and

file HFader.java
Copy code
  1. import processing.core.*;
  2. import java.awt.event.MouseEvent;

  3. public class HFader {
       private static PApplet app;

  4.    HFader(PApplet papp) {
  5.       app = papp;
  6.       app.registerDraw(this);
  7.       app.registerMouseEvent(this);
  8.    }
  9.         
  10.       public void draw() {
  11.          println("draw");
  12.    }
  13.         
  14.    public void mouseEvent(MouseEvent e) {
  15.       println("mouseEvent: " + e);
  16.    }
  17. }


THANK YOU!!!

Your answer helps me a lot!