This commit is contained in:
2022-05-18 23:06:27 +08:00
parent 1357f94bfb
commit d0416b02bd
6 changed files with 140 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
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());
}
}
});
}
}