How can I do to create a custom event and send it programmatically to a component?
E.g. If I had a JButton
and wanted to create an ActionEvent
or a MouseEvent
and than send it as
if an user had pressed on it which code I'd to use?
The following code not work:
JButton btn = new JButton("Click...");
MouseAdapter my = new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
area.setText("Button clicked!!!");
}
};
btn.addMouseListener(my);
MouseEvent me = new MouseEvent(btn, MouseEvent.BUTTON1, 1, 0, 1, 1, 1, false);
btn.dispatchEvent(my);