我目前正在尝试让一个MouseListener来监听一个java applet,但它无法正常工作我不确定以下代码有什么问题,是否有人能够帮助找到错误?此外,我意识到java applet几乎已经折旧了,但是对于我正在做的某些事情它是必要的。
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();
}
}