We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi. I'm working on a "control window", meaning a secondary window that can control the primary one. In that control window I have a little representation of the main window. And i wish i could click on that little section and map mouseEvents to primary window. Issue is that mouseEvent class has no public method to modify x and y values. Is there any java trick I could implement? Thanks in advance.
Answers
Thanks. This is good. However I'm needing something else. Because for each key/mouse event I need to send an update to the other window using a real MouseEvent object (so maybe creating my own MouseEvent class and making appropiated setters would work).
EDITED. Nevermind. I'm making the controlwindow drawing area the same size than the target area. That way coordinated are the same and it works. Well, at least works with 800x600 resolution windows :) Maybe in a future I should came back to this "resizing/mapping coords" issue.
Just a last comment. I tried to alter these variables from one window to another and it crashes with: Exception in thread "Animation Thread" java.lang.NullPointerException. Why?
sketchWindow.mousePressed = true; sketchWindow.mouseX = event.getX(); sketchWindow.mouseY = event.getY();
Each PApplet got its own canvas and its own "Animation" & "Event Dispatch" threads.
Messing w/ them in the "wrong" time can be disastrous! :-SS
sketchWindow.mousePressed = true;
can't cause NPE b/c mousePressed is a primitiveboolean
variable and it's just being assignedtrue
.Now the expressions
event.getX()
&event.getY()
cause NPE if event isnull
.Or if getX() or getY() deals w/ something internal that can't be messed w/ at the "wrong" time.
If it's the latter, you're gonna need to find a way to
synchronized ()
those calls w/ 1 shared mutex.Nonetheless, I've come up w/ another rudimentary way to pass ControlWindow's mouseX & mouseY to the corresponding 1s in MainSketch.
I'm using noLoop() & redraw() as a way to coordinate the mouse events.
Making the whole thing an event-driven app: :ar!
Cool. Good stuff. Thanks so many for the explanation & code.