add lab11
This commit is contained in:
20
lab/lab11/Question1/MyPanel.java
Normal file
20
lab/lab11/Question1/MyPanel.java
Normal file
@@ -0,0 +1,20 @@
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
public MyPanel() {
|
||||
// Anonymous class.
|
||||
this.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
// Check whether the left mouse button is
|
||||
if (e.getButton() == MouseEvent.BUTTON1) {
|
||||
// get the coordinate
|
||||
System.out.println("(" + e.getX() + "," + e.getY() + ")");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user