I am currently trying to get a MouseListener to listen to a java applet, however it is not working I am unsure about what is wrong with the following code, would anyone be able to help find the error? Also, I realize that java applets are pretty much depreciated, however it is necessary for the certain thing I am doing.
public class loader extends JPanel {
private createApplet applet= new createApplet();
public loader(final boolean oldschool) {
setLayout(new BorderLayout());
add(applet.getApplet(), BorderLayout.CENTER);
MouseListener test = new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
System.out.println("test");
}
@Override
public void mousePressed(MouseEvent e) {
System.out.println("test");
}
@Override
public void mouseReleased(MouseEvent e) {
System.out.println("test");
}
@Override
public void mouseEntered(MouseEvent e) {
System.out.println("test");
}
@Override
public void mouseExited(MouseEvent e) {
System.out.println("test");
}
};
// Adds test mouse listener to instance of applet
applet.addMouseListener(test);
revalidate();
}
}
class createApplet extends Applet implements AppletStub {
Applet applet = this;
public createApplet () {
downloadAndCreate();
}
public void downloadAndCreate() {
// Code that downloads applet and sets it etc here
/*
Set the applet stub
*/
applet.setStub(this);
/*
Initialize the applet
*/
applet.init();
/*
Start the applet
*/
applet.start();
}
}