lab12
This commit is contained in:
21
lab/lab12/Question1/MyPanel.java
Normal file
21
lab/lab12/Question1/MyPanel.java
Normal 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());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user