一个很小白的java问题
放纵的纯粹 2015-04-09 04:27:27
import java.awt.*;
public class wb{
public static void main(String[] args)
{
Frame w=new Frame();
w.setSize(300,400);
MyPanel mp=new MyPanel();
w.add(mp);
w.show();
}这个括号
class MyPanel extends Panel{
public void paint(Graphics g){
g.drawLine(30, 30, 100, 100);
}
}
这段程序,为什么当我把花括号移到最下面就会出现错误呢
import java.awt.*;
public class wb{
public static void main(String[] args)
{
Frame w=new Frame();
w.setSize(300,400);
MyPanel mp=new MyPanel();
w.add(mp);
w.show();
}
class MyPanel extends Panel{
public void paint(Graphics g){
g.drawLine(30, 30, 100, 100);
}
}
}
提示错误
No enclosing instance of type wb is accessible. Must qualify the allocation with an enclosing instance of type wb (e.g. x.new A() where x is an instance of wb).