Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 671381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:22:03+00:00 2026-05-14T00:22:03+00:00

I have a JWindow and a JFrame both I have made runnable and both

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T00:22:03+00:00Added an answer on May 14, 2026 at 12:22 am

    You are confusing Threads with Objects. When you have an Object that is a Runnable that just gives a starting point for a Thread. However this doesn’t mean that when another thread (in this case the Event thread that handles the MouseListener) calls a method in your Runnable that it executed by the thread that is executing the Runnable. When a method is called, it never switches to another thread. If you want this you need a mechanism. For instance a queue that the MouseListener can post tasks to, and in your Runnable.run() you then keep looking for a new task.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have just started using Visual Studio Professional's built-in unit testing features, which as I
I have a jwindow(set to be always on top) that you can click to
I have a little JWindow with a logo on it that users can drag
Have noticed issue while testing iphone app that if one quickly opens/dismisses a modal
Have you seen library for flexible working with terminal(Unix like)? I want to implement
Have just started using Google Chrome , and noticed in parts of our site,
Have you ever seen any of there error messages? -- SQL Server 2000 Could
Have you guys had any experiences (positive or negative) by placing your source code/solution
Have you used VS.NET Architect Edition's Application and System diagrams to start designing a
Have you determined a maximum number of characters allowed in FCKEditor ? I seem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.