有 2 节课 -
public class MainClass {
public static void main(String[] args) {
JFrame frame = new JFrame();
....
Component mouseClick = new MyComponent() ;
frame.setVisible(true);
}
public class MyComponent extends JComponent implements MouseListener {
@Override
public void mouseClicked(MouseEvent arg0) {
System.out.println("here was a click ! ");
}
...
}
我试图在frame
监听器上设置鼠标单击,但是当我运行它然后按下鼠标单击时没有任何反应。
如何使它工作?