I was under the impression that a touch screen emulated mouse events, however how would I handle multiple touch events?
I have tried adding a JPanel
with a MouseMotionListener
and outputting the values to the console. I however, am only getting values for the first touch on the screen.
I then tried splitting the screen down the middle, with a JPanel
on either side, and a separate MouseMotionListener
on each side, each one outputting to the console.
In this configuration, I still only see the values for the first finger on the screen.
Here is what I have so far:
JPanel jPaneL = new JPanel();
jPaneL.setName("Left");
jPaneL.addMouseMotionListener(mouseMotionL);
jPaneL.setBounds(0, 0, 960, 1280);
jPaneL.setBackground(Color.BLACK);
JPanel jPaneR = new JPanel();
jPaneR.setName("Right");
jPaneR.addMouseMotionListener(mouseMotionR);
jPaneR.setBounds(960, 0, 960, 1080);
jPaneR.setBackground(Color.RED);
jFrame.add(jPaneL);
jFrame.add(jPaneR);
And my MouseMotionListener, L
and R
are the exact same.
private static MouseMotionListener mouseMotionX = new MouseMotionListener() {
@Override
public void mouseDragged(MouseEvent e) {
String s = ((JPanel) e.getSource()).getName();
System.out.println(s);
}
@Override
public void mouseMoved(MouseEvent e) {
String s = ((JPanel) e.getSource()).getName();
System.out.println(s);
}
};
I have found libraries that support multi-touch, but I am looking to do this without using third-party libraries. How can I go about doing this using just native mouse listeners?