好像做不到java.awt.Robot
可以移动鼠标到指定位置
获得指定位置的屏幕颜色可是无法获得鼠标的位置

解决方案 »

  1.   

    是的 不过这样就复杂了 既然有这个需求 就干脆别用java了
      

  2.   

    import java.awt.*;
    import java.awt.event.*;/** 一个应用程序,用来演示内部类的使用 *//** 类ThreeListenInner,定义了三个内部类,分别用来处理鼠标移动事件、
      * 鼠标点击事件和窗口事件 */
    public class ThreeListenInner{
    private Frame f;
    private TextField tf; /** main()方法 */
    public static void main(String args[]){
    ThreeListenInner th=new ThreeListenInner();
    th.go();
    } /** 方法go() */
    public void go(){
    f=new Frame("Three listeners example");
    f.add("North",new Label("Click and drag the mouse"));
    tf=new TextField(30);
    f.add("South",tf);
    f.addMouseMotionListener(new MouseMotionHandler());
    f.addMouseListener(new MouseEventHandler());
    f.addWindowListener(new WindowEventHandler());
    f.setSize(300,300);
    f.setBackground(Color.blue);
    f.setVisible(true);
    } /** 内部类MouseMotionHandler,用来处理鼠标移动事件 */
    public class MouseMotionHandler extends MouseMotionAdapter{ /** mouseDragged()方法 */
    public void mouseDragged(MouseEvent e){
    String s="Mouse dragging:X = "+e.getX()+"Y = "+e.getY();
    tf.setText(s);
    }
    }//内部类MouseMotionHandler结束 /** 内部类MouseEventHandler,用来处理鼠标事件 */
    public class MouseEventHandler extends MouseAdapter{ /** mouseEntered()方法 */
        public void mouseEntered(MouseEvent e){
        String s="The mouse entered";
    tf.setText(s);
        } /** mouseExited()方法 */
    public void mouseExited(MouseEvent e){
        String s="The mouse has left the building";
    tf.setText(s);
    }
    }//内部类MouseEventHandler结束 /** 内部类WindowEventHandler,用来处理窗口事件 */
    public class WindowEventHandler extends WindowAdapter{ /** windowClosing()方法 */
    public void windowClosing(WindowEvent e){
    System.exit(1);
    }
    }//内部类WindowEventHandler结束
    }//类ThreeListenInner结束