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

  • SEARCH
  • Home
  • 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 7182947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:52:42+00:00 2026-05-28T17:52:42+00:00

I want to make a virtual mouse(pointer), that can be controlled by java only.

  • 0

I want to make a virtual mouse(pointer), that can be controlled by java only.
But i cant find anywhere where i can do this?
I want to make it draw a red dot as mouse.
And i want it tosimulatie all mouse events.

  • 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-28T17:52:43+00:00Added an answer on May 28, 2026 at 5:52 pm
    I want to make a virtual mouse(pointer), that can be controlled by java only. 
    

    one of possible directions

    enter image description here

    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.Graphics;
    import java.awt.Color;
    import java.awt.Component;
    
    public class SSCCE {
    
        private JFrame componentsFrame = new JFrame();
        private JFrame remoteFrame = new JFrame();
        private int lastMouseX, lastMouseY;
        final JPanel panel = new JPanel();
    
        public SSCCE() {
            panel.add(new JButton("A Button"));
            panel.add(new JComboBox(new String[]{"A", "Combo", "Box"}));
            panel.add(new JSlider());
            panel.add(new JList(new String[]{"A", "List"}));
            panel.add(new JCheckBox("Check Box"));
            componentsFrame.add(panel);
            componentsFrame.setGlassPane(new JPanel() {
    
                private static final long serialVersionUID = 1L;
    
                @Override
                public void paintComponent(Graphics g) {
                    g.setColor(Color.red);
                    g.drawLine(lastMouseX - 8, lastMouseY, lastMouseX + 8, lastMouseY);
                    g.drawLine(lastMouseX, lastMouseY - 8, lastMouseX, lastMouseY + 8);
                }
    
                @Override
                public boolean isOpaque() {
                    return false;
                }
    
                @Override
                public boolean isVisible() {
                    return true;
                }
            });
            componentsFrame.setEnabled(false);
            componentsFrame.pack();
            componentsFrame.setVisible(true);
    //        
            MouseAdapter mouseImpl = new MouseAdapter() {
    
                private Component lastPressed;
    
                @Override
                public void mousePressed(MouseEvent e) {
                    redirectMouseEvent(e);
                }
    
                @Override
                public void mouseReleased(MouseEvent e) {
                    redirectMouseEvent(e);
                }
    
                @Override
                public void mouseClicked(MouseEvent e) {
                    redirectMouseEvent(e);
                }
    
                @Override
                public void mouseMoved(MouseEvent e) {
                    redirectMouseEvent(e);
                }
    
                @Override
                public void mouseDragged(MouseEvent e) {
                    redirectMouseEvent(e);
                }
    
                private void redirectMouseEvent(MouseEvent e) {
                    Component redirectTo = SwingUtilities.getDeepestComponentAt(panel, e.getX(), e.getY());
                    if (e.getID() == MouseEvent.MOUSE_PRESSED) {
                        lastPressed = redirectTo;
                    } else if (e.getID() == MouseEvent.MOUSE_DRAGGED || e.getID() == MouseEvent.MOUSE_RELEASED) {
                        redirectTo = lastPressed;
                    }
                    if (redirectTo != null) {
                        lastMouseX = e.getX();
                        lastMouseY = e.getY();
                        panel.repaint(); //this line is just to update the glass pane
                        e = SwingUtilities.convertMouseEvent(panel, e, redirectTo);
                        java.awt.Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(e);
                    }
                }
            };
            remoteFrame.getContentPane().addMouseListener(mouseImpl);
            remoteFrame.getContentPane().addMouseMotionListener(mouseImpl);
            remoteFrame.setSize(componentsFrame.getSize());
            remoteFrame.setLocation(0, componentsFrame.getY() + componentsFrame.getHeight());
            remoteFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            remoteFrame.setVisible(true);
        }
    
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    SSCCE sSCCE = new SSCCE();
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a virtual path (example: ~/Images/Banner.jpg) and I want to make that an
I want to make an entity that has an autogenerated primary key, but also
I want to make an application with plugins that also can have plugins (which
By using a cursor I want to make a virtual table. After that, using
I know that I can write attr_accessor :tag_list to make a virtual attribute tag_list
I want to make an etag that matches what Apache produces. How does apache
I want to make a table in SqlServer that will add, on insert, a
I am building a virtual store, in kohana, and i want to make a
I am testing out a property system and I want to make sure that
I have set up virtual subdomain. and i want to make htaccess to achive

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.