I have two classes one of them is where my JFrame
is built and the second one is my Main_Loop
and MouseListener
.
How could I call the mouse listener to execute?
FIRST CLASS:
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);
}
SECOND CLASS:
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) {
}
}