22 lines
512 B
Java
22 lines
512 B
Java
import java.awt.*;
|
|
import javax.swing.*;
|
|
import java.awt.event.MouseAdapter;
|
|
import java.awt.event.MouseEvent;
|
|
|
|
public class MyPanel extends JPanel {
|
|
public MyPanel(LayoutManager layout) {
|
|
super(layout);
|
|
|
|
// add anonymouse listener
|
|
addMouseListener(new MouseAdapter() {
|
|
@Override
|
|
public void mouseClicked(MouseEvent e) {
|
|
// print if left clicked
|
|
if (e.getButton() == MouseEvent.BUTTON1) {
|
|
System.out.println("Left button clicked at " + e.getX() + "," + e.getY());
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|