I'm writing a class that will allow users on other computers to control the contents of a JPanel, for use in a shared display system. java.awt.Robot will allow me to perform mouse clicks and keyboard input, but it does not have a mouseDragged(MouseEvent evt) method. My client has clientMouseReleased (and Pressed) methods as part of a MouseAdapter listener that look like:
private void clientMouseReleased(java.awt.event.MouseEvent evt)
{
try
{
switch (evt.getButton())
{
case 1:
remoteDesktop.mouseRelease(evt.getX(), evt.getY(), InputEvent.BUTTON1_MASK);
break;
case 2:
remoteDesktop.mouseRelease(evt.getX(), evt.getY(), InputEvent.BUTTON2_MASK);
break;
case 3:
remoteDesktop.mouseRelease(evt.getX(), evt.getY(), InputEvent.BUTTON3_MASK);
break;
}
}
catch (Exception e)
{
e.printStackTrace();
JOptionPane.showMessageDialog(this, e.getMessage());
}
}
Where the remoteDesktop is a class containing a java.awt.Robot, and it executes a Robot.mouseMove and Robot.mouseRelease (or Robot.mousePress) in method the client calls. I'd like to be able to write the mouseDragged in the same way, i.e., like this:
private void clientMouseDragged(java.awt.event.MouseEvent evt)
{
try
{
switch (evt.getButton())
{
case 1:
remoteDesktop.mouseDragged(evt.getX(), evt.getY(), InputEvent.BUTTON1_MASK);
break;
case 2:
remoteDesktop.mouseDragged(evt.getX(), evt.getY(), InputEvent.BUTTON2_MASK);
break;
case 3:
remoteDesktop.mouseDragged(evt.getX(), evt.getY(), InputEvent.BUTTON3_MASK);
break;
}
}
catch (Exception e)
{
e.printStackTrace();
JOptionPane.showMessageDialog(this, e.getMessage());
}
}