如何在applet中运行此程序?

时间:2014-05-19 08:25:56

标签: java applet console-application

package Homework;

import java.util.Scanner;

class FantasyGame{

    public static void main ( String args[])

    {
        Scanner scan = new Scanner(System.in);
        System.out.println("Welcome to Supercalifragilisticexpialidocious Quest!");
        System.out.println("Enter the name of your character: ");
        String name;
        name = scan.nextLine();
        System.out.println("Welcome to Supercalifragilisticexpialidocious Quest, " + (name) + "! " + "You will now assign attributes to your character, the total value assigned must not exceed 15 or be under 0, or the points will be assigned by default! (Type any NUMBER to continue)");
        int ans = scan.nextInt();
        System.out.println("Enter Strength (0-15): ");
        int str = scan.nextInt();
        System.out.println("Enter Health (0-15): ");
        int hp = scan.nextInt();
        System.out.println("Enter Luck (0-15): ");
        int lck = scan.nextInt();
        if (str + hp + lck <= 15)
        {
        System.out.println("Congratulations! You have successfully created your character!");
        System.out.println("Name: " + (name));
        System.out.println("Strength: " + (str));
        System.out.println("Health: " + (hp));
        System.out.println("Luck: " + (lck));
        }

        if (str + hp + lck > 15)
        {
        System.out.println("You have give your character too many attribute points! Default values have been assigned.");
        System.out.println("Name: " + (name));
        System.out.println("Strength: " + (5));
        System.out.println("Health: " + (5));
        System.out.println("Luck: " + (5));
        }


    }

}

我想为我的历史课程制作一个基于文本的游戏,我知道基本的Java足以制作一个只有变量和东西的小游戏,但我不知道如何制作它以便它直接作为一个小程序,黑色背景和白色文本显示并响应您键入的内容,如上面的代码在控制台中执行。

我已经尝试过命令提示符方法,但我得到的只是“Access is Denied。”

另外,当我尝试在eclipse中导出时,启动配置总是进入我不想要的类。对不起,我真的很困惑,需要很多帮助。

3 个答案:

答案 0 :(得分:1)

编写一个简单的applet,http://docs.oracle.com/javase/tutorial/deployment/applet/来自oracle的这个教程会很好地指导你完成它,重新排列你的代码不应该太难了

答案 1 :(得分:1)

我明白了。我只是将我的程序导出为.jar并使用了Jar2Exe,它运行得很好。谢谢!

答案 2 :(得分:0)

你没有让你上课公开,这就是你收到错误的原因&#34;访问被拒绝&#34;因为它不再可见编译器无法找到该类。只需写下

....
//change is here 
public class FantasyGame
{
....
}
....

谢谢!