jPCT - a 3d engine for Java > Support

Using mouse in jPCT applet version

(1/2) > >>

Tornado7:
Hi,

I’m experimenting on using mouse in my jPCT applet following, as trace, your way to map keys in your Bounce applet example; so I’ve initialized a variable:

private boolean click=false;

I’ve definited the following method:

public boolean mouseClick(Event e, int key) {
        ProcessKey(key,true);
        return (true);
 }

in ProcessKey I’ve added the following “case”:

case (MouseEvent.MOUSE_CLICKED):     {wire=event; break;}


where ‘wire’ is the the wireframe mode, here just as example. At last, I’ve added the following ‘if’ in the timer():

if (wire) {
                         wireframe=!wireframe;
                }

but, running the applet, nothing happens (using the 1 key, for example, the wireframe mode works, so the problem is just on the mouse event).
I’ve to add a mouse listener….. or something else?

Bye and thanks
 :)

EgonOlsen:
What is mouseClick()? I suggest to overwrite


--- Code: ---protected void processMouseEvent(MouseEvent e)
--- End code ---


in the applet with something like:


--- Code: ---
protected void processMouseEvent(MouseEvent e) {
   super.processMouseEvent(e);
   if (e.getID()==MouseEvent.MOUSE_CLICKED) {
      wire=!wire;
   }
}

--- End code ---


That should work. You shouldn't abuse processKey() for mouse events, because it was meant to handle events from the keyboard, not from the mouse.

Tornado7:
I’ve tried the this example following your code:


--- Code: ---
public void processMouseEvent(MouseEvent e) {
     super.processMouseEvent(e);
     if (e.getID()==MouseEvent.MOUSE_CLICKED) {
         System.out.println("I’m pressing the Mouse Click Button");
     }
  }

--- End code ---


but, looking in Sun Java Console, nothing happens…. I’m becoming crazy
 :?

EgonOlsen:
I see...the method doesn't get called, because the component (the applet in this case) doesn't get mouse events by default. You may either implement your own mouse listener or, if you want to use the method above, enable this type of event in your applet by calling
 
--- Code: ---this.enableEvents(AWTEvent.MOUSE_EVENT_MASK);
--- End code ---

somewhere in the beginning.

Tornado7:
I’ve tried both solutions: I’ve added  this.enableEvents(AWTEvent.MOUSE_EVENT_MASK); in init method, and I’ve tried the other solution:

I’ve implemented the MouseListener interface:

public class ThreeDSimApplet extends Applet implements Runnable, MouseListener

and I’ve added the required methods:

public void mouseClicked(MouseEvent event) {
   if (event.getButton()==MouseEvent.BUTTON1) {
        mouseX=event.getX();
             mouseY=event.getY();
         
             System.out.println(mouseX+" ," + mouseY);
   }
 }
 
 public void mousePressed(MouseEvent event) {
 }
 
 public void mouseReleased(MouseEvent event) {
 }
 
 public void mouseEntered(MouseEvent event) {
 }

 public void mouseExited(MouseEvent event) {
 }    

in both solution the mouse click now works but…… the keyboard events are disabled…… Is it possible to catch both events?

Navigation

[0] Message Index

[#] Next page

Go to full version