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.