I have a JWindow and a JFrame both I have made runnable and both implement a mouse listener. I have alot of testing to do for a project of mine and to simplify it I wish to be able to automate most of it, so I have starting my own mouse recorder and replayer (uses Java Robot Class).
Kinda like a simplified AutoHotKey or AutoIt thing... but it'll run on my Ubuntu machine aswell as my Windows one!!!
The JWindow I have made is translucent and covers the entire screen, when you click on it it disappears and replays the click to the object behind and then reappears. This is the recording process. When the User right clicks the is set to not visible and the recorded actions are replayed.
During replay I want the option to be able to exit the entire application and so I though the best way to do this would be to make the JFrame and the JWindow Runnable.
The JFrame is simply their to offer a close option from the application.
So, in my Main class I have
public static void Main(String[] args){
recorder = new Recorder();
gui = new GUI();
Thread tr = new Thread(recorder);
Thread tg = new Thread(gui);
tr.setName("Recorder");
tg.setName("GUI");
tr.start();
tg.start();
}
My understanding is Recorder and GUI are runnable objects and they are made into threads via the new Thread command. When I use .start() I am beginning the execution of the thread and from here on the system decides which thread is running at any particular time.
Onto the Recorder and GUI classes.
public class Recorder
implements Runnable, MouseListener {
//Constructor and other code
public void mouseClicked(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON1) {
//Record events
}else{
//Replay events
}
System.exit(0);
}
public void run() {
System.out.println("Recorder");
}
}
public class GUI
implements Runnable, MouseListener {
//Constructor, simply constructs JFrame and sets mouselistener to it
public void mouseClicked(MouseEvent e) {
System.exit(0);
}
public void run() {
System.out.println("GUI");
}
}
My application prints out Recorder and then GUI Allows me to record my events then right click on the JWindow to replay them...
but then when I click on the JFrame's close button or even in the frame because of the mouse listener it won't exit until all of the actions have been fully replayed?
One thing I did wonder is what ever I put in run is what is what keeps the thread running? So when System.out.println(""); is executed the thread dies? So I tried a while loop around them and my application successfully prints
GUI GUI GUI RECORDER RECORDER GUI RECORDER etc etc
So I can see that they threads are running concurrently... it's just that all of the other actions outside of the run don't seem to get executed... How can I include my mouse listener, etc within the threads execution?