简体   繁体   English

Java:将类导入Jframe

[英]Java: Import a class to Jframe

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. 我是java新手,我想知道将类导入JFrame的最佳方法是什么,因为我有一些小的应用程序,我想在除了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? 那么如何将所有这些放入窗口呢?

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. 你可能想看看oracle的swing教程 ,这就是你需要学习如何使用它来制作一个框架/窗口。 You can make a nice GUI (Graphic User Interface) for your game with that, rather than just using Eclipse's console ;) 你可以用它为你的游戏制作一个漂亮的GUI(图形用户界面),而不仅仅是使用Eclipse的控制台;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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