日期:2014-05-20  浏览次数:20658 次

请帮我看看那里错了 菜鸟
import   java.awt.*;
import   java.awt.event.*;
public   class   drowline{
Frame   f=new   Frame( "画线 ");
f.addWindowListener(new   MyWindowListener());
public   static   void   main   (String   []   args){
      new   drowline().init();
}
public   void   init(){
f.setSize(300,300);
f.setVisible(true);
f.addMouseListener(   new   MouseAdapter()
{int   x;
  int   y;
  public   void   mousePressed(MouseEvent   e){
  x=e.getX();
  y=e.getY();
  }
  public   void   mouseReleased   (MouseEvent   e){
  f.getGraphics().setColor(Color.blue);
  f.getGraphics().drawLine(x,y,e.getX(),e.getY());
 
  }

});
}
}
class   MyWindowListener   implements   WindowListener   {
public   void   windowClosing(WindowEvent   e){
e.getWindow().setVisible(false);
System.exit(0);

}
public   void   windowActivated(WindowEvent   e){
}
public   void   windowClosed(WindowEvent   e){
}
public   void   windowDeactivated(WindowEvent   e){
}
public   void   windowDeiconified(WindowEvent   e){
}
public   void   windowIconified(WindowEvent   e){
}
public   void   windowOpened(WindowEvent   e){
}

}
E:\ysheny\study\java\javap\drowline.java:5:   <identifier>   expected
                                f.addWindowListener(new   MyWindowListener());
                                                                      ^
1   error

谢谢   我是刚接触java

------解决方案--------------------
新建一个MyWindowListener类,然后引入到drowline中
例:import com.MyWindowListener
------解决方案--------------------
把f.addWindowListener(new MyWindowListener());放到init里
------解决方案--------------------
收到