java – Dispatch MouseEvent

Is there any way to schedule mouseevent, just like using dispatchkeyevent

I know I have two choices

1) Add mouse events to all recursive components

2) Use transparent glass plate

Does Java support this, or do I have to use one of the above options?

thank you

Solution

You tried Java awt. Component. DispatchEvent (awtevent)?

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

JButton jb = new JButton("Press!");
MouseEvent me = new MouseEvent(jb,// which
    MouseEvent.MOUSE_CLICKED,// what
    System.currentTimeMillis(),// when
    0,// no modifiers
    10,10,// where: at (10,10}
    1,// only 1 click 
    false); // not a popup trigger

jb.dispatchEvent(me);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>