4

I am new to java and I am wondering what is the best way to go about importing a class to a JFrame since I have a few minor applications I would like to make run in a window other then eclipse.

Here is some of the code I am working with (Its a modified version of some code in the dummies book):

import static java.lang.System.out;
import java.util.Scanner;
import java.util.Random;

public class GuessAgain {

/**
 * @param args
 */
public static void main(String[] args) {
    // Set up input and main info
    Scanner input = new Scanner(System.in);
    int numGuesses = 0;
    int randomNumber = new Random().nextInt(10) + 1;

    // Display welcome message
    out.println("~-=********************=-~");
    out.println("    The Guessing Game!    ");
    out.println("~-=********************=-~");

    // Give instruction
    out.print("Please enter a number between 1 and 10: ");
    int inputNumber = input.nextInt();
    numGuesses++;

    // Recurse till user gets the answer
    while (inputNumber != randomNumber) {
        out.println();
        out.println("~-=********************=-~");
        out.println("     Please try again     ");
        out.println("~-=********************=-~");
        out.print("Enter another number between 1 and ten: ");
        inputNumber = input.nextInt();
        numGuesses++;
    }
    out.print("You won after: " + numGuesses + " guesses");

}

}

So how do I go about putting all of that into a window?

4

1 に答える 1

4

You'll probably want to take a look at oracle's swing tutorial, that's what you need to learn how to use in order to make a frame/window. You can make a nice GUI (Graphic User Interface) for your game with that, rather than just using Eclipse's console ;)

于 2012-08-07T04:11:12.227 に答える