java - 如何在小程序中运行该程序?

标签 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 足以制作一个只有变量和东西的小游戏,但我不知道如何制作它,以便它直接作为具有黑色背景和白色文本的小程序,它会显示并响应您键入的内容,就像上面的代码在控制台中所做的那样。

我尝试过命令提示符方法,但得到的只是“访问被拒绝”。

另外,当我尝试在 Eclipse 中导出时,启动配置总是转到我不想要的类。抱歉,我真的很困惑,需要很多帮助。

最佳答案

编写一个简单的小程序,http://docs.oracle.com/javase/tutorial/deployment/applet/ Oracle 的这个教程将很好地引导您完成它,那么重新排列您的代码应该不会太难

关于java - 如何在小程序中运行该程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23732994/

相关文章:

java - 我可以使用另一个 ArrayList 中的引用来更改一个 ArrayList 中的对象吗?

c# - 为控制台应用程序制作 UI

java - Maven ClassNotFoundException SpringServletContainerInitializer

java - 仅使用添加和删除来交换列表中的项目

java applet 无法打印 actionPerformed 中的值

SSL MITM 和 java 小程序

java - 获取 java.lang.SecurityException : attempted to open sandboxed jar as a Trusted-Library

c# - 最大化控制台窗口 - C#

c# - 如何在控制台应用程序中绘制矩形?

Java 流 - 映射列表到简化的映射列表