我是 java 新手,我想知道将类导入 JFrame 的最佳方法是什么,因为我有一些小应用程序我想在 Eclipse 以外的窗口中运行。
这是我正在使用的一些代码(它是傻瓜书中某些代码的修改版本):
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");
}
}
那么我该如何将所有这些都放入一个窗口中呢?