Differentiating between left, middle, right mouse click

Here’s some sample code.

Main.java:

import javax.swing.event.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
 
public class Main extends JFrame
{
   public Main() {
      addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent we) { 
            System.exit(1);
         }
      });
 
      getContentPane().addMouseListener(new MouseAdapter() {
         public void mouseClicked(MouseEvent me) {
            if ((me.getModifiers() & InputEvent.BUTTON1_MASK) != 0) {
               System.out.print("Left");
            }
            else if ((me.getModifiers() & InputEvent.BUTTON2_MASK) != 0) {
               System.out.print("Middle");
            }
            else if ((me.getModifiers() & InputEvent.BUTTON3_MASK) != 0) {
               System.out.print("Right");
            }
            System.out.println(" mouse button was clicked!");
         }
      });
   }
  
   public static void main(String []args) {
      Main main = new Main();
      main.setSize(300, 300);
      main.setVisible(true);
   }
}