0

So, I'd like to modify my console application to use a GUI (because typing 'java -jar' in the console every time I want to run it is a pain and I'd like to use Java Web Start), but I'm not entirely sure where to even begin the transformation. Here is how my program works.

The main file looks like this:

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 is a System.out.println shortcut)

It, along with most of the other files, extends off of 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();
}

This lets me reference them in the code easily. Here's how the intro screen works:

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.
                }
            }

        }
    }
}

The rest of the code isn't much different; Screen inputs and printlns shortcuts ahoy. But somehow I need to figure out how to find a way to bundle all of this up into a GUI and be able to manipulate it from several different files. Does anyone have any tips as to how to start doing this? I'm at a bit of a loss.

user1796160
  • 477
  • 2
  • 5
  • 13
  • 1
    _because typing 'java -jar' in the console every time I want to run it is a pain_ Just double click the jar file – BackSlash Jul 14 '13 at 08:40
  • Welcome to stackoverflow. Please try to ask a specific question, you are more likely to get a meaning furl answer this way. http://stackoverflow.com/questions/how-to-ask has more information. – Micha Wiedenmann Jul 14 '13 at 08:40
  • If you are using Eclipse, you can graphically create your user interface for example with Windowbuilder, see http://www.eclipse.org/windowbuilder/. – Micha Wiedenmann Jul 14 '13 at 08:41
  • @BackSlash: That does not work. That is the reason why I have to type 'java -jar' in the console, and why I am trying to make a GUI, rather than having things display in the console. – user1796160 Jul 14 '13 at 08:42
  • @user1796160 even if you use the GUI instead of the command line, you'll have to type `java -jar yourApp.jar` in the console to launch it. – BackSlash Jul 14 '13 at 08:43
  • @Micha Wiedenmann: Thank you! I'd call that a meaningful answer. ;) – user1796160 Jul 14 '13 at 08:43
  • @BackSlash: Is there a reason why? I'd really like to turn my jar into a JNLP file, but nothing pops up when it's opened that way. – user1796160 Jul 14 '13 at 08:44
  • @user1796160 If you want to turn it to JNLP i think it will run. Anyway i'd suggest not to use awt, but [use swing instead](http://docs.oracle.com/javase/tutorial/uiswing/components/) and, i'd suggest not to use window builders, IMHO you should learn how to program a GUI before using a builder – BackSlash Jul 14 '13 at 08:47
  • I've already turned it into a JNLP here: http://rubyrpg.x10.mx/downloads/Vector.jnlp Unfortunately nothing seems to pop up when it's run. – user1796160 Jul 14 '13 at 08:48
  • @user1796160 Java Web Start does assume a GUI app, so you can't use console – BackSlash Jul 14 '13 at 08:51
  • @MichaWiedenmann Yes it was a general statement. I think it's always the best to learn how to program GUIs, and _then_ use builders. – BackSlash Jul 14 '13 at 08:52
  • @BackSlash + MichaWiedenmann Alright, well, I think I'm going to try and make a GUI with Windowbuilder for this one, but if I make one in the future, I'll try and program it. It's hard here because the program wasn't designed for it from the start. Thank you both for all your help. – user1796160 Jul 14 '13 at 08:55
  • 1
    Why AWT rather than Swing? See this answer on [Swing extras over AWT](http://stackoverflow.com/a/6255978/418556) for many good reasons to abandon using AWT components. If you need to support older AWT based APIs, see [Mixing Heavyweight and Lightweight Components](http://www.oracle.com/technetwork/articles/java/mixing-components-433992.html). – Andrew Thompson Jul 14 '13 at 09:06

0 Answers0