WindowListener 是接口,不是类,实现接口不用是extends,要用implements,应该写成class MyWindowListener implements WindowListener,实现接口还有要实现这个接口中的所有方法。。
import java.awt.*;
import java.awt.event.*;
public class myframe extends Frame
{
public myframe()
{
this.addWindowListener(new MywindowListener());
Frame f=new Frame();
f.setTitle("my web") ;
f.setSize(400,400) ;
f.setLocation(400,400) ;
f.setBackground(Color.BLUE ) ;
f.setLayout(new GridLayout(3,2));
Button btn1=new Button("north");
Button btn2=new Button("south");
Button btn3=new Button("west");
Button btn4=new Button("east");
Button btn5=new Button("center");
f.add(btn1);
f.add(btn2);
f.add(btn3);
f.add(btn4);
f.add(btn5);
f.setVisible(true);
}
public static void main(String[] args)
{
new myframe();
}
class MywindowListener implements WindowListener {
public void windowActivated(WindowEvent e)
{
System.out.println("Window Activated");
}
public void windowClosed(WindowEvent e)
{
System.out.println("Window Closed");
System.exit(0);
}
public void windowClosing(WindowEvent e)
{
System.out.println("Window Closing....");
Window w=e.getWindow();
w.dispose();
}
public void windowDeactivated(WindowEvent e)
{
System.out.println("Window Deactivated");
}
public void windowDeiconified(WindowEvent e)
{
System.out.println("Window Deiconified");
}
public void windowIconified(WindowEvent e)
{
System.out.println("Window Iconified");
}
public void windowOpened(WindowEvent e)
{
System.out.println("Window Opened");
}
}
}
line 29:36是哪行啊