I have a JFrame that is my main application, the application moves the mouse via the Robot
class. I would like to run my class that extends Thread
and have it be able to start, pause, and stop a predefined list of mouse moving events, and also be able to write in the main JFrames text area to let the user know what is happening.
Currently I start the thread in an infinite loop of mouse movement, with updates to the main text area throughout the loop. It worked well but after started rewriting my application in Netbeans the designer I used to design the JFrames is using a, I think, swing text area which is not updating its text while the thread MouseMover is running.
I have defined the class as such
public class MouseMover extends Thread
{
MainView theApp;
public void run()
{
try
{
rob = new Robot();
}
catch (AWTException e1) {mainView.newStatusLine("The Robot could not be created");return;}
while(true) {}
}
public void setApp(MainView view)
{
theApp = view;
public void doIt()
{
while(true){
// move mouse around screen
rob.mouseMove(0, 100);
theApp.statusTextArea.setText("moved the mouse");
}
}
}
And I define the thread as such
public class MainView extends javax.swing.JFrame
{
static MouseMover mover;
public MainView()
{
mover = new MouseMover();
}
public void on_goBtn()
{
mover.doIt();
}
}
I have been told when asking similar questions I am starting the thread wrong, I am trying to fix it now and add some more functionality. So how do I properly start the MouseMover thread so my JFrame stays responsive while the thread can also write to its text area? And the kicker, how might I be able to "pause" the doIt() method of MouseMover?