【发布时间】:2014-04-05 18:43:47
【问题描述】:
我完全是一个初学者。这是学校的项目。我只需要知道,谁能告诉我为什么这不会运行?
import javax.swing.JOptionPane;
public class WordGame
{
public static void main(String[] args)
{
String name;
name= JOptionPane.showInputDialog("Enter your name");
String age;
age= JOptionPane.showInputDialog("Enter your age");
String city;
city= JOptionPane.showInputDialog("Enter the name of a city");
String college;
college= JOptionPane.showInputDialog("Enter the name of a college");
String profession;
profession= JOptionPane.showInputDialog("Enter profession");
String animal;
animal= JOptionPane.showInputDialog("Enter a type of animal");
String pet;
pet= JOptionPane.showInputDialog("Enter a pet name");
String str="There once was a person named "+ name+
" \n who lived in CITY. At the age of "+age+
", "+ name +" went to college at \n"+ college+" ."+ name
+" graduated and went to work as a \n"+profession+" . Then, "+ name
+" adopted a(n) "+ animal +" \n named "+ pet+
". They both lived happily ever after!";
JOptionPane.showMessageDialog(null, str);
}
}
【问题讨论】:
-
请描述问题。什么不起作用?为什么?发生了什么?你期望会发生什么?
-
您看到了什么错误或奇怪的行为?
-
这是我得到的错误。编译错误时间:0 内存:0 信号:0 Main.java:2:错误:WordGame 类是公共的,应该在一个名为 WordGame.java 的文件中声明 public class WordGame
-
我正在使用 ideone.com 来测试它。我不知道这是否是问题的一部分。
-
@user2302865 我会说是的,这就是问题所在。它似乎无法分配内存。此外,它无法保存文件。
标签: java swing joptionpane