Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to invoke mouse clicked event?

Posted on 2001-06-27
2
Medium Priority
?
308 Views
Last Modified: 2012-05-04
hi,
i want to write a program where this program will move the mouse to certain location and then clicked on the specified location. any idea how to do this??? i'm developing this programming using Java.

may be somebody can tell me what method i should use to invoke the mouse clicked event.

thank you.
0
Comment
Question by:pleasure
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Accepted Solution

by:
yuri1976 earned 40 total points
ID: 6234293
have a look at the java.awt.Robot class

Here's an example:

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class TestRobot {

  public TestRobot() {
  }

  public static void main(String[] args) {
    final JFrame frame = new JFrame("Test Robot");
    frame.setSize(400,400);
    frame.setLocation(400,400);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel panel = new JPanel();
    JButton button = new JButton("Double click toolbar");
    button.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent ev) {
        try {

          Robot robot = new Robot();
          Point point = frame.getLocationOnScreen();
          Point titleBarCoord = new Point(point.x+50, point.y+8);

          robot.mouseMove(titleBarCoord.x, titleBarCoord.y);
          robot.mousePress(InputEvent.BUTTON1_MASK);
          robot.mouseRelease(InputEvent.BUTTON1_MASK);
          robot.mousePress(InputEvent.BUTTON1_MASK);
          robot.mouseRelease(InputEvent.BUTTON1_MASK);

        } catch (AWTException ex) {
          System.out.println("Error using Robot");
        }
      }
    });
    panel.add(button);
    frame.getContentPane().add(panel);
    frame.setVisible(true);
  }
}
0
 

Author Comment

by:pleasure
ID: 6237107
it's works..thank you
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question