无法导入 javax.swing.JFrame
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23209125/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to import javax.swing.JFrame
提问by UNEVERIS
I've been looking all over the internet and Can't find an answer.
我一直在寻找整个互联网,但找不到答案。
I'm using Eclipse and need to import JFrame from javax.swing. But hovering over the the declaration (which in Eclipse should give you an option to import it) the import option does not show up. Instead I manually typed out the import path, but get an error.
我正在使用 Eclipse,需要从 javax.swing 导入 JFrame。但是将鼠标悬停在声明(在 Eclipse 中应该为您提供导入它的选项)上,导入选项不会显示。相反,我手动输入了导入路径,但出现错误。
Going even further, I used the package explorer to attempt to fine it... couldn't. I have the latest version of Eclipse, and the Latest JRE and JDK. But still is not working.
更进一步,我使用包资源管理器尝试对其进行优化......不能。我有最新版本的 Eclipse,以及最新的 JRE 和 JDK。但仍然无法正常工作。
Code:
代码:
package com.BickDev.Game;
import java.awt.Canvas;
import java.awt.Dimension;
import javax.swing.JFrame;
public class Game extends Canvas implements Runnable {
private static final long serialVersionUID = 1L;
public static final int WIDTH = 320;
public static final int HEIGHT = WIDTH / 12 * 9;
public static final int SCALE = 2;
public final String TITLE = "Troy's Game Test";
private boolean running = false;
public void run() {
}
public static void main(String args[]) {
Game game = new Game();
Dimension size = new Dimension(WIDTH * SCALE, HEIGHT * SCALE);
game.setPreferredSize(size);
game.setMaximumSize(size);
game.setMinimumSize(size);
JFrame frame = new JFrame(game.TITLE);
}
}
the import javax.swing.JFrame now gives the error
导入 javax.swing.JFrame 现在给出错误
Access restriction: The type JFrame is not accessible due to restriction on required library C:\ProgramFiles\Java\jre8\lib\rt.jar
No idea what this means...
不明白这是什么意思...
Please help....
请帮忙....
*UPDATE found the JFrame class.. but cannot access it.
*UPDATE 找到了 JFrame 类。但无法访问它。
采纳答案by user3623053
When you make a new java project at JRE choose "Use an execution environment JRE and from there select JavaSE-1.7 or 1.8 and just should solve the problem. I had the same problem like you before.
当您在 JRE 上创建一个新的 Java 项目时,选择“使用执行环境 JRE,然后从那里选择 JavaSE-1.7 或 1.8 就可以解决问题。我以前也遇到过和您一样的问题。
回答by baderkhane
- Right-click on the project
- Select properties
- Java build path
- Library > Add Library > Add JRE SYSTEM Library
- Execution Environment
- Select JavaSE-1.7
- Finish
- 右键单击项目
- 选择属性
- Java构建路径
- 库 > 添加库 > 添加 JRE 系统库
- 执行环境
- 选择 JavaSE-1.7
- 结束