黑马程序员技术交流社区

标题: 请问是哪里出错了 [打印本页]

作者: 逍遥客    时间: 2014-8-8 22:13
标题: 请问是哪里出错了
import javax.swing.*;
public class JFrameDemo {

        public static void main(String[] args) {
                JFrame frame = new JFrame("add");
                JPanel pane = new JPanel();
                JLabel label = new JLabel("add");
                pane.add(label);
                frame.setContentPane(pane);
                frame.setSize(450, 500);
                frame.setVisible(true);
               
        }

}
这个程序能运行,但是为啥总是JFrame,JPane等行前显示红色小叉???这是错误原因Access restriction: The method setContentPane(Container) from the type JFrame is not accessible due to restriction on required library D:\Java\jdk1.7.0_51\jre\lib\rt.jar。。。如何解决
作者: 逍遥客    时间: 2014-8-8 22:41
这个问题,我把ecalipse的设置改了下,它默认把这些受访问限制的API设成了ERROR,只要把  Windows-Preferences-Java-Complicer-Errors/Warnings  里面的Deprecated and restricted API中的Forbidden references(access rules)选为Warning就可以编译通过了。但是在别的电脑没修改也没出错,这是为啥




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2