我有两个课程,其中一个是我的JFrame
,第二个是Main_Loop
和MouseListener
。
如何调用鼠标侦听器执行?
public class Main_Frame extends Main_Loop{
public static void main(String[]args){
//SETTING UP THE JFRAME
JFrame frame = new JFrame();
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(700,500);
JPanel panel = new JPanel();
panel.setLayout(null);
frame.add(panel);
Main_Loop cl = new Main_Loop();
while (true){
System.out.println(cl.clicked);
}
public class Main_Loop implements MouseListener {
public int mouseY,x;
public int mouseX;
public boolean clicked;
public void mouseClicked(MouseEvent arg0) {
mouseY = arg0.getX();
mouseX = arg0.getY();
clicked = true;
}
public void mouseEntered(MouseEvent arg0) {
}
public void mouseExited(MouseEvent arg0) {
}
public void mousePressed(MouseEvent arg0) {
}
public void mouseReleased(MouseEvent arg0) {
}
}