Solved

How to invoke mouse clicked event?

Posted on 2001-06-27
2
302 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 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

630 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