javagesturetrackpad

Listen for 3 finger gestures?


I am making a java application for my computer science teacher that allows him to give students test digitally by loading a number of PDFs from a Google Drive folder and displaying them onto a JScrollPane using Java Swing. The goal of this application is to make the test inescapable so that students can't cheat by going to google to find answers. Then, at the end of class, my teacher will tell the students a code that will allow them to exit the application by entering it into a JTextField. Currently, the JFrame of this application is set with the following settings:

Frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

This means that, for the most part, the application is inescapable, leaving the user stuck on the JFrame until they enter the code to exit. The problem I am facing is that there are certain ways to exit the app or minimize it through gestures built into the computer. Specifically, the one I am looking at involves swiping down with 3 fingers on the trackpad, which minimizes the application, allowing the user to open Google. To my knowledge, there is no way to temporarily disable the gestures built into the computer, so the next best option that I can see is listen for the user to put 3 fingers onto the trackpad and then deny the user the ability to scroll. Is there a way to do this ? Additionally, if there are other ways that you can think of to exit this app without the exit code, what are those ways ? And how would I stop the user from taking advantage of them ?

Frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
Frame.setUndecorated(true);
Frame.setVisible(true);
Frame.setAlwaysOnTop(true);
Frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

Additionally, if there are other ways that you can think of to exit this app without the exit code, what are those ways ? And how would I stop the user from taking advantage of them ?


Solution

  • You can try using a WindowAdapter to block Minimization of your JFrame. The WindowAdapter should just overwrite the default Action of your JFrame, when Minimize is pressed (or Gesture is recorded).

    private WindowAdapter getWindowAdapter(JFrame frm) {
    return new WindowAdapter() {
      @Override
      public void windowIconified(WindowEvent we) {
        frm.setState(JFrame.NORMAL);
      }
    };
    

    And add the WindowListener to your JFrame:

    frm.addWindowListener(getWindowAdapter(frm));