0

I am writing an application where the flow of the execution would go like

  1. User selects menu item

Based on which menu item

  1. User is prompted for input in the form of a mouse click on a separate transparent window (JFrame)
  2. Code is implemented based on user input
  3. (2) and (3) are repeated set number of times

The user prompt seems simple - I attach a mouse Listener to the window as

class Trainer extends MouseAdapter {
Point p;

public Trainer() {
    p = new Point(0,0);
}

public void mouseClicked(MouseEvent e) {
    p = MouseInfo.getPointerInfo().getLocation();
    output.append("test" + newline);
    output.setCaretPosition(output.getDocument().getLength());
    glass.setVisible(false);
}
}

The last line in the mouseClicked method basically hides the transparent window and needs to be reshown for the next user prompt (not so important)

I have tried 1) using 1,3,5, etc as an event triggered by the menu select but this results in having an event within an event which I don't think is allowed/possible (?) 2) Sequencing each as a separate event - cumbersome but I am still faced with - how do 3, 5, etc know when 2, 4 etc have been triggered 3) Possibly I am supposed to be using a new Thread. I am new to Java and tutorial on this subject are pretty confusing - a good source for a clear discussion/tutorial on this would be great.

To be clear the user, selects a menu item. Based on this choice, there is a back and forth exchange with the user being prompted for a mouse click and a response based on this click (updating variables, deciding on the next task, etc). The user is prompted to click on a part of the screen outside the application - think of asking the user to select a red part on the desktop background. This requires a temporary transparent window to catch this event - I dont think dialog windows cuts it. ALL discussions and examples given on the use of transparent windows are flawed IMO not a single one works. If I could make a Window (JFrame, or any other construct) with menu items, a section that can have text and the rest of the window being (semi)-transparent so I could see the desktop backdrop, things would be greatly simplified.

user3799584
  • 917
  • 1
  • 9
  • 18
  • 1) "event within event" is a misleading way to put it. Events can be fired anytime and will be processed asynchonously, firing events within event handling code is allowed. 2) Do not attach a mouse listener to the window, rather add actionlisteners/selectionlisteners to the menuitems, I'd tell you how but I don't know exactly what do you mean by "menu item" (JMenuItem? items in a JList?) 3) Do not use [multiple JFrames](http://stackoverflow.com/questions/9554636/the-use-of-multiple-jframes-good-bad-practice), use JDialogs to prompt the user for input. – DSquare Jul 10 '14 at 17:09
  • @ DSquare It is not firing events during the event handling but waiting for an event to occur. It is my limited understanding that events are queued and processed sequentially so this cannot happen. I have updated my post to clarify what the user is prompted to do. This cannot IMO be handled by dialog windows. – user3799584 Jul 10 '14 at 20:16

0 Answers0