Author Topic: Using mouse in jPCT applet version  (Read 4244 times)

Offline Tornado7

  • byte
  • *
  • Posts: 45
    • View Profile
Using mouse in jPCT applet version
« on: May 14, 2004, 12:02:03 pm »
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
 :)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Using mouse in jPCT applet version
« Reply #1 on: May 14, 2004, 04:07:08 pm »
What is mouseClick()? I suggest to overwrite

Code: [Select]
protected void processMouseEvent(MouseEvent e)

in the applet with something like:

Code: [Select]

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


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.

Offline Tornado7

  • byte
  • *
  • Posts: 45
    • View Profile
Using mouse in jPCT applet version
« Reply #2 on: May 17, 2004, 11:46:42 am »
Iíve tried the this example following your code:

Code: [Select]

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


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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Using mouse in jPCT applet version
« Reply #3 on: May 17, 2004, 04:56:46 pm »
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: [Select]
this.enableEvents(AWTEvent.MOUSE_EVENT_MASK);
somewhere in the beginning.

Offline Tornado7

  • byte
  • *
  • Posts: 45
    • View Profile
Using mouse in jPCT applet version
« Reply #4 on: May 18, 2004, 12:02:04 pm »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Using mouse in jPCT applet version
« Reply #5 on: May 19, 2004, 07:26:21 am »
Have you implemented a KeyListener together with the MouseListener?

Offline Tornado7

  • byte
  • *
  • Posts: 45
    • View Profile
Using mouse in jPCT applet version
« Reply #6 on: May 19, 2004, 11:15:01 am »
No, I havenít. Iíve implemented this morning, and now they works both. Thanks for your suggestions  :D