JPanel: addMouseListener(MouseListener mous) : JPanel « javax.swing « Java by API






JPanel: addMouseListener(MouseListener mous)

  
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class MainClass extends JPanel {

  public MainClass() {

      addMouseListener(new MouseAdapter() { 
          public void mousePressed(MouseEvent me) { 
            System.out.println(me); 
          } 
        }); 

  }

  public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.getContentPane().add(new MainClass());

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
    frame.setSize(200, 200);
    frame.setVisible(true);
  }
}

           
         
    
  








Related examples in the same category

1.JPanel: addAncestorListener(AncestorListener lis)
2.JPanel: addContainerListener(ContainerListener l)
3.JPanel: addMouseMotionListener(MouseMotionListener lis)
4.JPanel: addKeyListener(KeyListener l)
5.JPanel: getFocusTraversalKeys(int id)
6.JPanel: isFocusCycleRoot()
7.JPanel: paintComponent(Graphics g)
8.JPanel: repaint()
9.JPanel: setBackground(Color c)
10.JPanel: setBorder(Border border)
11.JPanel: setComponentPopupMenu(JPopupMenu popup)
12.JPanel: setFocusCycleRoot(boolean value)
13.JPanel: setFocusTraversalPolicyProvider(boolean value)
14.JPanel: setLayout(null)
15.JPanel: setOpaque(boolean isOpaque)
16.JPanel: setPreferredSize(Dimension preferredSize)
17.JPanel: setToolTipText(String htmlString)
18.extends JPanel