我在Mac上并尝试使用较新版本的eclipse编写java,但它们无法正常工作.旧版本的eclipse正在运行,但我最近安装了Eclipse Luna,当我打开它时,它说:"JVM的1.6.0_31版本不适用于此产品.版本:需要1.7或更高版本." 但我安装了最新版本的java.我安装了最新版本的JDK,如果我没弄错,JVM是Java虚拟机,但我不知道如何更新它.我对java有所了解,但是我对JVM这样的东西很开心,所以请在解释答案时尽量做到尽可能具体.还解释了为什么它的工作原理以及之前没有工作的原因.我在发布之前在这个网站上搜索过,一个类似问题的答案就是输入
export JAVA_HOME=/usr/libexec/java_home -v 1.7
Run Code Online (Sandbox Code Playgroud)
进入终端,但终端给了我错误:
-bash: export: `/usr/libexec/java_home': not a valid identifier
-bash: export: `-v': not a valid identifier
-bash: export: `1.7': not a valid identifier
Run Code Online (Sandbox Code Playgroud)
所以请帮助,我不知道该怎么做.
我编写了一个返回JLabel的函数,另一个函数将它添加到JFrame中,但是,似乎没有添加JLabel.我在JLabel上测试了不同的东西,比如颜色和文字,但它没有显示出来.我正常地将JLabel添加到JFrame,这很有用.我真的希望能够将我的功能添加到JFrame中.
我有一个JButton创建一个新框架,这是代码:
inputButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JFrame realSim = new JFrame();
JPanel realSim2 = new JPanel();
newFrame(realSim, realSim2);
realSim2.add(Planet.createPlanet(1));
Planet.createPlanet(1).setBounds(100, 100, 20, 20);
Planet.createPlanet(1).setText("Ello, just testing!");
}
}
);
Run Code Online (Sandbox Code Playgroud)
Planet.createPlanet()是返回JLabel的函数.这是该函数的代码:
public static JLabel createPlanet(int planetNum)
{
JLabel planetRep = new JLabel();
switch (planetNum)
{
case 1: planetColor = Color.WHITE;
break;
case 2: planetColor = Color.RED;
break;
case 3: planetColor = Color.ORANGE;
break;
case 4: planetColor = Color.YELLOW;
break;
case 5: planetColor = Color.GREEN;
break;
case 6: …Run Code Online (Sandbox Code Playgroud) 例如,如果我说:
for(i = 2; i < 2; i++)
Run Code Online (Sandbox Code Playgroud)
显然,这是一个无用的 for 循环,但也许 i = a,并且 a 是由其他东西设置的。那么在这种情况下会发生什么呢?