0

所以,我想修改我的控制台应用程序以使用 GUI(因为每次我想运行它时在控制台中输入“java -jar”很痛苦,我想使用 Java Web Start),但我'不完全确定从哪里开始转型。这是我的程序的工作原理。

主文件如下所示:

package vector;

import java.io.*;

public class Vector extends GameFile
{
    public static void main(String[] args)
        throws IOException
    {
        int gameMode = 1;       /*1: Return to title screen.
                                  2: Start a new game.
                                  3: Load from a checkpoint.
                                  4: Quit the game.*/
        while(true){
            switch(gameMode)
            {
            default:
                gameMode = intro.transition();
                break;
            case 2:
                eventHandler.next(gameMode);
                break;
            case 3:
                gameMode = ls.loadCheckpoint();
                eventHandler.next(gameMode);
                break;
            case 4:
                ut.print("Goodbye.");
                return;
            }
        }
    }
}

(ut.print 是 System.out.println 快捷方式)

它与大多数其他文件一起扩展了 GameFile:

package vector;

import iostream.*;
import util.*;
import pda.*;

public class GameFile {
    public static BasicUtils ut = new BasicUtils();
    public static IntroScreen intro = new IntroScreen();
    public static Checkpoint ls = new Checkpoint();
    public static EventHandler eventHandler = new EventHandler();
    public static ColdStorage events = new ColdStorage();
    public static PDA pda = new PDA();
}

这让我可以轻松地在代码中引用它们。以下是介绍屏幕的工作原理:

package iostream;

/*IMPORT RELEVANT FILES*/
import vector.*;

public class IntroScreen extends GameFile{

    public int transition(){
        ut.print("---    ---  ------------ ------------ ------------   --------   -----------  ");
        ut.print("***    ***  ************ ************ ************  **********  ***********  ");
        ut.print("---    ---  ----         ---          ------------ ----    ---- ----    ---  ");
        ut.print("***    ***  ************ ***              ****     ***      *** *********    ");
        ut.print("---    ---  ------------ ---              ----     ---      --- ---------    ");
        ut.print(" ********   ****         ***              ****     ****    **** ****  ****   ");
        ut.print("  ------    ------------ ------------     ----      ----------  ----   ----  ");
        ut.print("   ****     ************ ************     ****       ********   ****    **** ");
        ut.print("-----------------------------------------------------------------------------");
        ut.print("(1) BEGIN NEW GAME       -        (2) LOAD CHECKPOINT        -       (3) QUIT");
        int errsPrinted=0;
        while(true)
        {
            int menu;
            try {
                menu = ut.input.nextInt();
                switch(menu)
                {
                case 1:
                    return 2; // Start game.
                case 2:
                    return 3; // Load game.
                case 3:
                    return 4; // Quit game.
                }
            }
            catch(Exception e) {
                ut.print("That's not a valid option.");
                errsPrinted++;
                if(errsPrinted>9)
                {
                    return 4; // Quit game.
                }
            }

        }
    }
}

其余的代码没有太大的不同。屏幕输入和 printlns 快捷方式啊。但不知何故,我需要弄清楚如何找到一种方法将所有这些捆绑到一个 GUI 中,并能够从几个不同的文件中对其进行操作。有人对如何开始这样做有任何提示吗?我有点不知所措。

4

0 回答 0