Solved

How to invoke mouse clicked event?

Posted on 2001-06-27
2
291 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 Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

730 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