简体   繁体   English

WindowListener不起作用

[英]WindowListener does not work

i'm programming on frame and applet window but problem is that,the code not working. 我正在框架和小程序窗口上编程,但问题是,代码无法正常工作。 help me to solve this problem and also help me how to close frame window because with the help of window listener the frame window is not closing. 帮助我解决此问题,也帮助我如何关闭框架窗口,因为在窗口侦听器的帮助下框架窗口没有关闭。

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<applet code="fra1.class" height=500 width=600></applet>*/

public class fra1 extends Applet implements WindowListener
{
String msg="This is applet window";
Frame f;
public void init()
{
setLayout(null);
f=new Frame();
f.setTitle("THE JAVA GAMER");
f.setSize(400,400);
f.setVisible(true);
f.add(new Label("This is frame window"),Label.LEFT);
f.addWindowListener(this);
}
public void start()
{
f.setVisible(true);
}
public void stop()
{
f.setVisible(false);
}
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
public void paint(Graphics g)
{
g.drawString(msg,100,100);
}
}

and giving me this error again and again: 并一次又一次地给我这个错误:

fra1 is not abstract and does not override abstract method windowdDeactivated
(java.awt.event.windowEvent) in java.awt.event.WindowListener public class
fra1 extends Applet implements WindowListener

If you're implementing a WindowListener you'll need to override all the methods it provides, so your class must contain all of these, not just the one you want. 如果要实现WindowListener ,则需要重写它提供的所有方法,因此您的类必须包含所有这些方法,而不仅仅是您想要的方法。

public class Foo implements WindowListener {
    @Override
    public void windowOpened(WindowEvent e) {

    }

    @Override
    public void windowClosing(WindowEvent e) {

    }

    @Override
    public void windowClosed(WindowEvent e) {

    }

    @Override
    public void windowIconified(WindowEvent e) {

    }

    @Override
    public void windowDeiconified(WindowEvent e) {

    }

    @Override
    public void windowActivated(WindowEvent e) {

    }

    @Override
    public void windowDeactivated(WindowEvent e) {

    }
}

Add the other methods to your class and it should compile. 将其他方法添加到您的类中,它将进行编译。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM