Commit 78e6f022 authored by Daniel Vogel's avatar Daniel Vogel
Browse files

small tweaks to event demos

parent 523ef3f6
...@@ -18,7 +18,7 @@ public class EventLoop extends JPanel { ...@@ -18,7 +18,7 @@ public class EventLoop extends JPanel {
EventLoop() EventLoop()
throws InterruptedException, InvocationTargetException { throws InterruptedException, InvocationTargetException {
EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue(); EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue();
// enable events for this JPanel // enable events for this JPanel
if (!isJava7Like()) setQueue(); if (!isJava7Like()) setQueue();
EventQueue.invokeAndWait(new Runnable() { EventQueue.invokeAndWait(new Runnable() {
...@@ -66,15 +66,16 @@ public class EventLoop extends JPanel { ...@@ -66,15 +66,16 @@ public class EventLoop extends JPanel {
// mouse events come in here // mouse events come in here
public void dispatchEvent(AWTEvent e) { public void dispatchEvent(AWTEvent e) {
//System.out.println("dispatchEvent " + e.getID() ); //System.out.println("dispatchEvent " + e.getID() );
if (e.getID() == MouseEvent.MOUSE_DRAGGED) if (e.getID() == MouseEvent.MOUSE_DRAGGED) {
{
MouseEvent me = (MouseEvent)e; MouseEvent me = (MouseEvent)e;
x = me.getX(); x = me.getX();
y = me.getY(); y = me.getY();
System.out.println("(" + x + "," + y + ")");
repaint();
} }
repaint();
super.dispatchEvent(e); super.dispatchEvent(e);
} }
// other kinds of events here // other kinds of events here
public void postEvent(AWTEvent e) { public void postEvent(AWTEvent e) {
//System.out.println("postEvent " + e.getID() ); //System.out.println("postEvent " + e.getID() );
......
...@@ -26,13 +26,11 @@ public class InheritanceEvents extends JPanel { ...@@ -26,13 +26,11 @@ public class InheritanceEvents extends JPanel {
protected void processMouseMotionEvent(MouseEvent e) protected void processMouseMotionEvent(MouseEvent e)
{ {
// only detects when button is down WHILE also moving // only detects when button is down WHILE also moving
if (e.getID() == MouseEvent.MOUSE_DRAGGED) if (e.getID() == MouseEvent.MOUSE_DRAGGED) {
{
x = e.getX(); x = e.getX();
y = e.getY(); y = e.getY();
repaint();
} }
repaint();
} }
int x; int x;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment