Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi-Touch in Swing

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?

like image 834
Matt Clark Avatar asked Mar 03 '14 22:03

Matt Clark


People also ask

What is meant by multi-touch?

In mobile computing, multi-touch refers to the capability of a touchscreen (or a touchpad) to recognize two or more points of contact on the surface concurrently.

What is multi-touch capabilities?

Definition. In computing, multi-touch is technology which enables a touchpad or touchscreen to recognize more than one or more than two points of contact with the surface.

What is multi-touch in Mobile?

A multi-touch gesture is when multiple pointers (fingers) touch the screen at the same time. This lesson describes how to detect gestures that involve multiple pointers. Refer to the following related resources: Input Events API Guide.


1 Answers

First I want to say that I would really recommend using JavaFX for such an application. You can also integrate your JavaFX project in existing swing applications using JFXPanel.

However I have heard about MT4j which is a framework for multitouch in Java application which also supports Swing. I have not worked with it. So I can not tell you how good it works.

like image 161
Lars Avatar answered Sep 21 '22 18:09

Lars