Solved

How to invoke mouse clicked event?

Posted on 2001-06-27
2
280 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
2 Comments
 
LVL 3

Accepted Solution

by:
yuri1976 earned 10 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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
micro services spring boot application error 3 197
reverse digits of a number using for loop 5 45
java stored proc example 9 32
hibernate example issues from command prompt 10 42
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

803 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