一个很小白的java问题

放纵的纯粹 放纵的纯粹 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

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).
...全文
评论 2
收藏 已收藏
分享
返回顶部
放纵的纯粹
Java 51,407 成员 86,128 内容