Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Sakib Rabbany Sajal
cs349-code
Commits
78e6f022
Commit
78e6f022
authored
Sep 30, 2017
by
Daniel Vogel
Browse files
small tweaks to event demos
parent
523ef3f6
Changes
2
Hide whitespace changes
Inline
Side-by-side
java/4-events/EventLoop.java
View file @
78e6f022
...
...
@@ -18,7 +18,7 @@ public class EventLoop extends JPanel {
EventLoop
()
throws
InterruptedException
,
InvocationTargetException
{
EventQueue
eq
=
Toolkit
.
getDefaultToolkit
().
getSystemEventQueue
();
// enable events for this JPanel
// enable events for this JPanel
if
(!
isJava7Like
())
setQueue
();
EventQueue
.
invokeAndWait
(
new
Runnable
()
{
...
...
@@ -66,15 +66,16 @@ public class EventLoop extends JPanel {
// mouse events come in here
public
void
dispatchEvent
(
AWTEvent
e
)
{
//System.out.println("dispatchEvent " + e.getID() );
if
(
e
.
getID
()
==
MouseEvent
.
MOUSE_DRAGGED
)
{
if
(
e
.
getID
()
==
MouseEvent
.
MOUSE_DRAGGED
)
{
MouseEvent
me
=
(
MouseEvent
)
e
;
x
=
me
.
getX
();
y
=
me
.
getY
();
System
.
out
.
println
(
"("
+
x
+
","
+
y
+
")"
);
repaint
();
}
repaint
();
super
.
dispatchEvent
(
e
);
}
// other kinds of events here
public
void
postEvent
(
AWTEvent
e
)
{
//System.out.println("postEvent " + e.getID() );
...
...
java/4-events/InheritanceEvents.java
View file @
78e6f022
...
...
@@ -26,13 +26,11 @@ public class InheritanceEvents extends JPanel {
protected
void
processMouseMotionEvent
(
MouseEvent
e
)
{
// only detects when button is down WHILE also moving
if
(
e
.
getID
()
==
MouseEvent
.
MOUSE_DRAGGED
)
{
if
(
e
.
getID
()
==
MouseEvent
.
MOUSE_DRAGGED
)
{
x
=
e
.
getX
();
y
=
e
.
getY
();
repaint
();
}
repaint
();
}
int
x
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment