1

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
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
user3485153
  • 27
  • 2
  • 5
  • Don't launch a frame out of an applet. Instead, launch the frame from a link using [Java Web Start](http://stackoverflow.com/tags/java-web-start/info). One important difference between a sand-boxed frame launched from an applet and from JWS is that while the JWS frame is allowed to call `System.exit(n)`, the applet frame cannot. BTW - Why AWT rather than Swing? See my answer on [Swing extras over AWT](http://stackoverflow.com/a/6255978/418556) for many good reasons to abandon using AWT components. One good reason is `JFrame.setDefaultCloseOperation(n)`, an easy replacement for `KeyLstnr`. – Andrew Thompson Apr 02 '14 at 07:35

1 Answers1

1

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.

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.

Arrem
  • 1,005
  • 9
  • 10