关于No enclosing instance of type MyProject is accessible的报错

来源:互联网 发布:php面向对象知识总结 编辑:程序博客网 时间:2024/05/16 07:42

我是一个JAVA菜鸟初学者,遇到了这样的问题和大家分享一下解决办法。

public class MyProject {

public static void main(String args[]){
JFrame w = new JFrame();
w.setSize(300,400);

MyPanel mp = new MyPanel();
w.add(mp);

w.addMouseListener(mp);
mp.addMouseListener(mp);

w.setVisible(true);

}

    class MyPanel extends JPanel implements MouseListener{

这里不能用动态类,需要在class前加上static。

0 0
原创粉丝点击