简体   繁体   中英

How do I run this program in an applet?

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));
        }


    }

}

I want to make a text-based game for my history class and I know basic Java enough to make a small one with just variables and stuff but I don't know how I can make it so that it runs directly as an applet with a black background and white text that shows up and responds to what you type, like the code above does in the console.

I've tried the command prompt method but all I get is "Access is Denied."

Also, when I try to export in eclipse, the launch configuration always goes to a class I don't want. Sorry but I am really confused and need a lot of help on this.

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

I figured it out. I just exported my program as a .jar and used Jar2Exe and it worked perfectly. Thanks!

You have not made you class public and that is why you are getting error "Access is denied" because it is not visible any more. Compiler is not able to find that class. Just write

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

Thanks !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM