This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Game Code #1

By: Tyeeeee1 on Dec 13th, 2012  |  syntax: Java  |  size: 40.04 KB  |  views: 112  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import java.io.*;
  2. import javax.swing.*; //Needed for the swing class
  3. import java.awt.*;
  4. import java.awt.event.*; //Needed for action event listeners for the buttons
  5. import java.awt.image.*;
  6.  
  7. class GlobalVariables //Create variables here if you want to use them anywhere. To refrence the variable use GlobalVariables.variableName
  8. {
  9.         public static String characterName = "temp";
  10.         public static String characterAlignment = "temp";
  11.         public static byte characterLevel = 1;
  12.         public static short characterSTR = 0;
  13.         public static short characterAGIL = 0;
  14.         public static short characterDEX = 0;
  15.         public static short characterINT = 0;
  16.         public static short characterCON = 0;
  17.         public static short characterCHAR = 0;
  18.         public static short characterSPWR = 0;
  19.         public static short characterHPWR = 0;
  20.         public static short characterXP = 0;
  21.         public static short characterHP = 0;
  22.         public static short characterMANA = 0;
  23.         public static short characterGold = 0;
  24.        
  25.         public static Font abaddonFont;
  26.        
  27.         /*
  28.         * A few of the main primitive data types.
  29.         *
  30.         * byte = -128 to 127
  31.         * short = -32,768 to 32,767
  32.         * int = -2,147,483,648 to 2,147,483,647
  33.         * long = -9,223,372,036,775,808 to 9,223,372,036,775,807
  34.         * boolean = true or false
  35.         */
  36. }
  37.  
  38. class SavingClass
  39. {
  40.         public static void saveGame() throws Exception //Change the return type (void) to something else later.
  41.         {
  42.                 BufferedWriter saveFile = new BufferedWriter(new FileWriter("TextSave.txt"));
  43.                
  44.                 saveFile.write("test1, test2"); //Saves the variables listed to the first line of the CSV file. If you wanted to make another line then you would end this one with \r\n so that a new line is created. Then you would make another write method
  45.                
  46.                 saveFile.close(); //Closes the file writer now that we're finished.
  47.         }
  48. }
  49.  
  50. class LoadingClass
  51. {
  52.         public static void loadGame() throws Exception //Change the return type (void) to something else later.
  53.         {
  54.                 String exampleString1;
  55.                 String exampleString2;
  56.                
  57.                 BufferedReader saveFile = new BufferedReader(new FileReader("TextSave.txt"));
  58.                
  59.                 exampleString1 = saveFile.readLine();
  60.                 exampleString2 = saveFile.readLine();
  61.                
  62.                 saveFile.close();
  63.                
  64.                 System.out.println(""+exampleString1+" "+exampleString2+"");
  65.         }
  66. }
  67.  
  68. class CreateGameWindowFirst extends JFrame
  69. {
  70.         //The below method is used for the creation of the game window.
  71.         public CreateGameWindowFirst() //If there is a return type set for this method then the code below will not show.
  72.         {
  73.                 setSize(640, 480); //Sets the size of the game window
  74.                 setLocationRelativeTo(null); //Centers the window on the users screen.
  75.                 setTitle("The Game - By Tyler MacEachern"); //Sets the title of the game window
  76.                 setDefaultCloseOperation(EXIT_ON_CLOSE); //Basically this makes it so when you hit the red X the window and program will close.
  77.                 setResizable(false); //Makes it so that the user cannot resize the JFrame.
  78.                
  79.                 final JPanel gamePanel = new JPanel(); //Creates a new JPanel to put everything on.
  80.                 getContentPane().add(gamePanel);
  81.                
  82.                 gamePanel.setLayout(null); //Makes it so you can manually positon everything on the JPanel using XY coords.
  83.                
  84.                 CreateMainMenu gameWindow = new CreateMainMenu(gamePanel); //Tells the program to run the CreateMainMenu class so that the main menu will be created.
  85.                
  86.                 setVisible(true); //Makes the JFrame, also known ass gameWindow visible to the user.
  87.         }
  88. }
  89.  
  90. class CreateMainMenu extends JFrame
  91. {
  92.         public CreateMainMenu(final JPanel gamePanel)
  93.         {
  94.                 //Create the main menu's look with buttons and that
  95.                 Insets insets = gamePanel.getInsets(); //Gets the amount of space that the gameWindow's boarders take up so that you can use it to better position your JButtons and stuff.
  96.        
  97.                 final JButton newGameButton = new JButton(""); //Creates a button object for the New Game button on the main menu.
  98.                 final JButton loadGameButton = new JButton(""); //Creates a button object for the Load Game button on the main menu.
  99.                 final JButton optionsButton = new JButton(""); //Creates a button object for the Options button on the main menu.
  100.                 final JButton exitButton = new JButton(""); //Creates a button object to exit the game. (Shuts down the program)
  101.                
  102.                 gamePanel.add(newGameButton); //Adds the New Game button to the JPanel
  103.                 newGameButton.setBounds(250 + insets.left, 100 + insets.top, 120, 40); //X coords, Y Coords. Width, Height.
  104.                 newGameButton.setBorder(null); //Disables the thin black box around the button
  105.                 newGameButton.setFocusPainted(false); //Makes it so that when you select the button there wont be a little box around the words to signify that the button is currently selected.
  106.                 newGameButton.setContentAreaFilled(false); //Gets rid of the grey fill when you select the button.
  107.                 Icon newGameButtonIcon = new ImageIcon("button_newGame_normal.png"); //Creates a new ImageIcon object that will be used as the newGameButton.
  108.                 newGameButton.setIcon(newGameButtonIcon); //Covers the newGameButton icon with the button_newGame_normal.png image.
  109.                 Icon newGameButtonIconRollover = new ImageIcon("button_newGame_rollover.png"); //Creates a new ImageIcon object that will be used as the rollover version of the newGameButton.
  110.                 newGameButton.setRolloverIcon(newGameButtonIconRollover); //Tells the newGameButton to, when the mouse is over it, change to the rollover version of the newGamebutton.
  111.                 Icon newGameButtonIconPressed = new ImageIcon("button_newGame_press.png"); //Creates a new ImageIcon object that will be used as the pressed version of the newGameButton.
  112.                 newGameButton.setPressedIcon(newGameButtonIconPressed); //Tells the newGameButton to, when the mouse is over it, change to the pressed version of the newGameButton.
  113.                 newGameButton.addActionListener(new ActionListener() {  //Action listener for the newGameButton
  114.                         public void actionPerformed(ActionEvent e)
  115.                         {
  116.                                 System.out.println("You've pressed the New Game Button on the main menu screen.");
  117.                                 gamePanel.remove(newGameButton); //Removes the newGameButton
  118.                                 gamePanel.remove(loadGameButton); //Removes the loadGamebutton
  119.                                 gamePanel.remove(optionsButton); //Removes the optionsButton
  120.                                 gamePanel.remove(exitButton); //Removes the exitButton
  121.                                 gamePanel.repaint(); //Re-loads the JPanel, also known as gamePanel, so that the deleted buttons disappear.
  122.                                 CreateCharacterCreationMenu gameWindow = new CreateCharacterCreationMenu(gamePanel); //Passes the gamePanel object to the LoadGameMenu class so that it can be used there
  123.                         }});
  124.  
  125.                 gamePanel.add(loadGameButton); //Adds the Load Game button to the JPanel
  126.                 loadGameButton.setBounds(250 + insets.left, 170 + insets.top, 120, 40); //X coords, Y Coords. Width, Height.
  127.                 loadGameButton.setBorder(null); //Disables the thin black box around the button
  128.                 loadGameButton.setFocusPainted(false); //Makes it so that when you select the button there wont be a little box around the words to signify that the button is currently selected.
  129.                 loadGameButton.setContentAreaFilled(false); //Gets rid of the grey fill when you select the button.
  130.                 Icon loadGameButtonIcon = new ImageIcon("button_loadGame_normal.png"); //Creates a new ImageIcon object that will be used as the loadGameButton.
  131.                 loadGameButton.setIcon(loadGameButtonIcon); //Covers the newGameButton icon with the button_loadGame_normal.png image.
  132.                 Icon loadGameButtonIconRollover = new ImageIcon("button_loadGame_rollover.png"); //Creates a new ImageIcon object that will be used as the rollover version of the loadGameButton.
  133.                 loadGameButton.setRolloverIcon(loadGameButtonIconRollover); //Tells the loadGameButton to, when the mouse is over it, change to the rollover version of the loadGamebutton.
  134.                 Icon loadGameButtonIconPressed = new ImageIcon("button_loadGame_press.png"); //Creates a new ImageIcon object that will be used as the pressed version of the loadGameButton.
  135.                 loadGameButton.setPressedIcon(loadGameButtonIconPressed); //Tells the loadGameButton to, when the mouse is over it, change to the pressed version of the loadGameButton.
  136.                 loadGameButton.addActionListener(new ActionListener() {  //Action listener for the loadGameButton
  137.                         public void actionPerformed(ActionEvent e)
  138.                         {
  139.                                 System.out.println("You've pressed the Load Game Button on the main menu screen.");
  140.                                 gamePanel.remove(newGameButton); //Removes the newGameButton
  141.                                 gamePanel.remove(loadGameButton); //Removes the loadGamebutton
  142.                                 gamePanel.remove(optionsButton); //Removes the optionsButton
  143.                                 gamePanel.remove(exitButton); //Removes the exitButton
  144.                                 gamePanel.repaint(); //Re-loads the JPanel, also known as gamePanel, so that the deleted buttons disappear.
  145.                                 CreateLoadGameMenu gameWindow = new CreateLoadGameMenu(gamePanel); //Passes the gamePanel object to the LoadGameMenu class so that it can be used there
  146.                         }});
  147.  
  148.                 gamePanel.add(optionsButton); //Adds the Options Game button to the JPanel
  149.                 optionsButton.setBounds(250 + insets.left, 240 + insets.top, 120, 40); //X coords, Y Coords. Width, Height.
  150.                 optionsButton.setBorder(null); //Disables the thin black box around the button
  151.                 optionsButton.setFocusPainted(false); //Makes it so that when you select the button there wont be a little box around the words to signify that the button is currently selected.
  152.                 optionsButton.setContentAreaFilled(false); //Gets rid of the grey fill when you select the button.
  153.                 Icon optionsButtonIcon = new ImageIcon("button_optionsButton_normal.png"); //Creates a new ImageIcon object that will be used as the optionseButton.
  154.                 optionsButton.setIcon(optionsButtonIcon); //Covers the newGameButton icon with the button_optionsButton_normal.png image.
  155.                 Icon optionsButtonIconRollover = new ImageIcon("button_optionsButton_rollover.png"); //Creates a new ImageIcon object that will be used as the rollover version of the optionsButton.
  156.                 optionsButton.setRolloverIcon(optionsButtonIconRollover); //Tells the optionsButton to, when the mouse is over it, change to the rollover version of the optionsbutton.
  157.                 Icon optionsButtonIconPressed = new ImageIcon("button_optionsButton_press.png"); //Creates a new ImageIcon object that will be used as the pressed version of the optionsButton.
  158.                 optionsButton.setPressedIcon(optionsButtonIconPressed); //Tells the optionsButton to, when the mouse is over it, change to the pressed version of the optionsButton.
  159.                 optionsButton.addActionListener(new ActionListener() {  //Action listener for the optionsButton
  160.                         public void actionPerformed(ActionEvent e)
  161.                         {
  162.                                 System.out.println("You've pressed the Options Button on the main menu screen.");
  163.                                 gamePanel.remove(newGameButton); //Removes the newGameButton
  164.                                 gamePanel.remove(loadGameButton); //Removes the loadGamebutton
  165.                                 gamePanel.remove(optionsButton); //Removes the optionsButton
  166.                                 gamePanel.remove(exitButton); //Removes the exitButton
  167.                                 gamePanel.repaint(); //Re-loads the JPanel, also known as gamePanel, so that the deleted buttons disappear.
  168.                                 CreateOptionsMenu gameWindow = new CreateOptionsMenu(gamePanel);
  169.                         }});
  170.                        
  171.                 gamePanel.add(exitButton); //Adds the Exit button to the JPanel.
  172.                 exitButton.setBounds(250 + insets.left, 310 + insets.top, 120, 40); //X coords, Y Coords. Width, Height.
  173.                 exitButton.setBorder(null); //Disables the thin black box around the button
  174.                 exitButton.setFocusPainted(false); //Makes it so that when you select the button there wont be a little box around the words to signify that the button is currently selected.
  175.                 exitButton.setContentAreaFilled(false); //Gets rid of the grey fill when you select the button.
  176.                 Icon exitButtonIcon = new ImageIcon("button_exitButton_normal.png"); //Creates a new ImageIcon object that will be used as the exitButton.
  177.                 exitButton.setIcon(exitButtonIcon); //Covers the newGameButton icon with the button_exitButton_normal.png image.
  178.                 Icon exitButtonIconRollover = new ImageIcon("button_exitButton_rollover.png"); //Creates a new ImageIcon object that will be used as the rollover version of the exitButton.
  179.                 exitButton.setRolloverIcon(exitButtonIconRollover); //Tells the exitButton to, when the mouse is over it, change to the rollover version of the exitbutton.
  180.                 Icon exitButtonIconPressed = new ImageIcon("button_exitButton_press.png"); //Creates a new ImageIcon object that will be used as the pressed version of the exitButton.
  181.                 exitButton.setPressedIcon(exitButtonIconPressed); //Tells the exitButton to, when the mouse is over it, change to the pressed version of the exitButton.
  182.                 exitButton.addActionListener(new ActionListener() {  //Action listener for the exitButton
  183.                         public void actionPerformed(ActionEvent e)
  184.                         {
  185.                                 System.out.println("You've pressed the Exit Button on the main menu screen.");
  186.                                 System.exit(0);
  187.                         }});
  188.         }
  189. }
  190.  
  191. class CreateLoadGameMenu extends JFrame
  192. {
  193.         public CreateLoadGameMenu(final JPanel gamePanel)
  194.         {
  195.                 Insets insets = gamePanel.getInsets(); //Gets the amount of space that the gameWindow's boarders take up so that you can use it to better position your JButtons and stuff.
  196.        
  197.                 final JButton backButton = new JButton(""); //Creates a button object for the Back button on the main menu.
  198.                 gamePanel.add(backButton); //Adds the Back button to the JPanel
  199.                 backButton.setBounds(10 + insets.left, 410 + insets.top, 120, 40); //X coords, Y Coords. Width, Height.
  200.                 backButton.setBorder(null); //Disables the thin black box around the button
  201.                 backButton.setFocusPainted(false); //Makes it so that when you select the button there wont be a little box around the words to signify that the button is currently selected.
  202.                 backButton.setContentAreaFilled(false); //Gets rid of the grey fill when you select the button.
  203.                 Icon backButtonIcon = new ImageIcon("button_backButton_normal.png"); //Creates a new ImageIcon object that will be used as the backButton.
  204.                 backButton.setIcon(backButtonIcon); //Covers the backButton icon with the button_backButton_normal.png image.
  205.                 Icon backButtonIconRollover = new ImageIcon("button_backButton_rollover.png"); //Creates a new ImageIcon object that will be used as the rollover version of the backButton.
  206.                 backButton.setRolloverIcon(backButtonIconRollover); //Tells the backButton to, when the mouse is over it, change to the rollover version of the backButton.
  207.                 Icon backButtonIconPressed = new ImageIcon("button_backButton_press.png"); //Creates a new ImageIcon object that will be used as the pressed version of the backButton.
  208.                 backButton.setPressedIcon(backButtonIconPressed); //Tells the backButton to, when the mouse is over it, change to the pressed version of the backButton.
  209.                 backButton.addActionListener(new ActionListener() {  //Action listener for the backGameButton
  210.                         public void actionPerformed(ActionEvent e)
  211.                         {
  212.                                 System.out.println("You've pressed the Back Button on the Load Game screen.");
  213.                                 gamePanel.remove(backButton);
  214.                                 gamePanel.repaint(); //Re-loads the JPanel, also known as gamePanel, so that the deleted buttons disappear.
  215.                                 CreateMainMenu gameWindow = new CreateMainMenu(gamePanel);
  216.                         }});
  217.         }
  218. }
  219.  
  220. class CreateOptionsMenu extends JFrame
  221. {
  222.         public CreateOptionsMenu(final JPanel gamePanel)
  223.         {
  224.                 Insets insets = gamePanel.getInsets(); //Gets the amount of space that the gameWindow's boarders take up so that you can use it to better position your JButtons and stuff.
  225.                
  226.                 final JButton backButton = new JButton(""); //Creates a button object for the Back button on the main menu.
  227.                 gamePanel.add(backButton); //Adds the Back button to the JPanel
  228.                 backButton.setBounds(10 + insets.left, 410 + insets.top, 120, 40); //X coords, Y Coords. Width, Height.
  229.                 backButton.setBorder(null); //Disables the thin black box around the button
  230.                 backButton.setFocusPainted(false); //Makes it so that when you select the button there wont be a little box around the words to signify that the button is currently selected.
  231.                 backButton.setContentAreaFilled(false); //Gets rid of the grey fill when you select the button.
  232.                 Icon backButtonIcon = new ImageIcon("button_backButton_normal.png"); //Creates a new ImageIcon object that will be used as the backButton.
  233.                 backButton.setIcon(backButtonIcon); //Covers the backButton icon with the button_backButton_normal.png image.
  234.                 Icon backButtonIconRollover = new ImageIcon("button_backButton_rollover.png"); //Creates a new ImageIcon object that will be used as the rollover version of the backButton.
  235.                 backButton.setRolloverIcon(backButtonIconRollover); //Tells the backButton to, when the mouse is over it, change to the rollover version of the backButton.
  236.                 Icon backButtonIconPressed = new ImageIcon("button_backButton_press.png"); //Creates a new ImageIcon object that will be used as the pressed version of the backButton.
  237.                 backButton.setPressedIcon(backButtonIconPressed); //Tells the backButton to, when the mouse is over it, change to the pressed version of the backButton.
  238.                 backButton.addActionListener(new ActionListener() {  //Action listener for the backGameButton
  239.                         public void actionPerformed(ActionEvent e)
  240.                         {
  241.                                 System.out.println("You've pressed the Back Button on the Options Menu screen.");
  242.                                 gamePanel.remove(backButton);
  243.                                 gamePanel.repaint(); //Re-loads the JPanel, also known as gamePanel, so that the deleted buttons disappear.
  244.                                 CreateMainMenu gameWindow = new CreateMainMenu(gamePanel);
  245.                         }});
  246.         }
  247. }
  248.  
  249. /*
  250. * When you make art assets for the buttons on the character creation menu you need to get rid of the text in the buttons
  251. *
  252. *
  253. */
  254.  
  255. class CreateCharacterCreationMenu extends JFrame
  256. {
  257.         //These tempStat variables are created outside of the method so that they will work without being declared final in the actionlistiner inner-classes.
  258.         byte tempStr = 3; //Creates a byte (number) variable to keep track of the character's Strength.
  259.         byte tempAgil = 3; //Creates a byte (number) variable to keep track of the character's Agility.
  260.         byte tempDex = 3; //Creates a byte (number) variable to keep track of the character's Dexterity.
  261.         byte tempInt = 3; //Creates a byte (number) variable to keep track of the character's Intellect.
  262.         byte tempCon = 3; //Creates a byte (number) variable to keep track of the character's Constitution.
  263.         byte tempChar = 3; //Creates a byte (number) variable to keep track of the character's Charisma.
  264.         byte tempHp = 3; //Creates a byte (number) variable to keep track of the character's Healing Power.
  265.         byte tempSp = 3; //Creates a byte (number) variable to keep track of the character's Spell Power
  266.         byte tempPointsToSpend = 8; //Creates a byte (number) variable to control the amount of stat points you have to spend.
  267.                
  268.         JLabel strAttributeLabel2 = new JLabel(""+tempStr+""); //Creates a label on which the character's current Strength will be displayed.
  269.         JLabel agilAttributeLabel2 = new JLabel(""+tempAgil+""); //Creates a label on which the character's current Agility will be displayed.
  270.         JLabel dexAttributeLabel2 = new JLabel(""+tempDex+""); //Creates a label on which the character's current Dexterity will be displayed.
  271.         JLabel intAttributeLabel2 = new JLabel(""+tempInt+""); //Creates a label on which the character's current Intellect will be displayed.
  272.         JLabel conAttributeLabel2 = new JLabel(""+tempCon+""); //Creates a label on which the character's current Constitution will be displayed.
  273.         JLabel charAttributeLabel2 = new JLabel(""+tempChar+""); //Creates a label on which the character's current Charisma will be displayed.
  274.         JLabel hpAttributeLabel2 = new JLabel(""+tempHp+""); //Creates a label on which the character's current Healing Power will be displayed.
  275.         JLabel spAttributeLabel2 = new JLabel(""+tempSp+""); //Creates a label on which the character's current Spell Power will be displayed.
  276.                
  277.         public CreateCharacterCreationMenu(final JPanel gamePanel)
  278.         {
  279.                 final JLabel strAttributeLabel1 = new JLabel("STR"); //Creates a label for the Strength stat.
  280.                 final JLabel agilAttributeLabel1 = new JLabel("AGIL"); //Creates a label for the Agility stat.
  281.                 final JLabel dexAttributeLabel1 = new JLabel("DEX"); //Creates a label for the Dexterity stat.
  282.                 final JLabel intAttributeLabel1 = new JLabel("INT"); //Creates a label for the Intellect stat.
  283.                 final JLabel conAttributeLabel1 = new JLabel("CON"); //Creates a label for the Constitution stat.
  284.                 final JLabel charAttributeLabel1 = new JLabel("CHAR"); //Creates a label for the Charisma stat.
  285.                 final JLabel hpAttributeLabel1 = new JLabel("HP"); //Creates a label for the Healing Power stat.
  286.                 final JLabel spAttributeLabel1 = new JLabel("SP"); //Creates a label for the Spell Power stat.
  287.        
  288.                 final JButton strAddButton = new JButton("+"); //Creates a button to add statpoints to the STR stat.
  289.                 final JButton agilAddButton = new JButton("+");  //Creates a button to add statpoints to the AGIL stat.
  290.                 final JButton dexAddButton = new JButton("+");  //Creates a button to add statpoints to the DEX stat.
  291.                 final JButton intAddButton = new JButton("+");  //Creates a button to add statpoints to the INT stat.
  292.                 final JButton conAddButton = new JButton("+");  //Creates a button to add statpoints to the CON stat.
  293.                 final JButton charAddButton = new JButton("+");  //Creates a button to add statpoints to the CHAR stat.
  294.                 final JButton spAddButton = new JButton("+");  //Creates a button to add statpoints to the SP stat.
  295.                 final JButton hpAddButton = new JButton("+");  //Creates a button to add statpoints to the HP stat.
  296.                
  297.                 final JButton strMinusButton = new JButton("-"); //Creates a button to take away statpoints from the STR stat.
  298.                 final JButton agilMinusButton = new JButton("-"); //Creates a button to take away statpoints from the AGIL stat.
  299.                 final JButton dexMinusButton = new JButton("-"); //Creates a button to take away statpoints from the DEX stat.
  300.                 final JButton intMinusButton = new JButton("-"); //Creates a button to take away statpoints from the INT stat.
  301.                 final JButton conMinusButton = new JButton("-"); //Creates a button to take away statpoints from the CON stat.
  302.                 final JButton charMinusButton = new JButton("-"); //Creates a button to take away statpoints from the CHAR stat.
  303.                 final JButton spMinusButton = new JButton("-"); //Creates a button to take away statpoints from the SP stat.
  304.                 final JButton hpMinusButton = new JButton("-"); //Creates a button to take away statpoints from the HP stat.
  305.                
  306.                 final JButton cancelButton = new JButton(""); //Creates a cancel button to go back to the main menu from the character creation screen.
  307.                 final JButton continueButton = new JButton(""); //Creates a continue button to continue past the character creation screen.
  308.                
  309.                 gamePanel.add(strAttributeLabel1); //Adds the strAttributeLabel1 JLabel to the JPanel.
  310.                 gamePanel.add(agilAttributeLabel1); //Adds the agilAttributeLabel1 JLabel to the JPanel.
  311.                 gamePanel.add(dexAttributeLabel1); //Adds the dexAttributeLabel1 JLabel to the JPanel.
  312.                 gamePanel.add(intAttributeLabel1); //Adds the intAttributeLabel1 JLabel to the JPanel.
  313.                 gamePanel.add(conAttributeLabel1); //Adds the conAttributeLabel1 JLabel to the JPanel.
  314.                 gamePanel.add(charAttributeLabel1); //Adds the charAttributeLabel1 JLabel to the JPanel.
  315.                 gamePanel.add(spAttributeLabel1); //Adds the spAttributeLabel1 JLabel to the JPanel.
  316.                 gamePanel.add(hpAttributeLabel1); //Adds the spAttributeLabel1 JLabel to the JPanel.
  317.                
  318.                 gamePanel.add(strAddButton); //Adds the STR add button to the JPanel.
  319.                 gamePanel.add(agilAddButton); //Adds the AGIL add button to the JPanel.
  320.                 gamePanel.add(dexAddButton); //Adds the DEX add button to the JPanel.
  321.                 gamePanel.add(intAddButton); //Adds the INT add button to the JPanel.
  322.                 gamePanel.add(conAddButton); //Adds the CON add button to the JPanel.
  323.                 gamePanel.add(charAddButton); //Adds the CHAR add button to the JPanel.
  324.                 gamePanel.add(spAddButton); //Adds the SP add button to the JPanel.
  325.                 gamePanel.add(hpAddButton); //Adds the HP add button to the JPanel.
  326.                
  327.                 gamePanel.add(strMinusButton); //Adds the STR minus button to the JPanel.
  328.                 gamePanel.add(agilMinusButton); //Adds the AGIL minus button to the JPanel.
  329.                 gamePanel.add(dexMinusButton); //Adds the DEX minus button to the JPanel.
  330.                 gamePanel.add(intMinusButton); //Adds the INT minus button to the JPanel.
  331.                 gamePanel.add(conMinusButton); //Adds the CON minus button to the JPanel.
  332.                 gamePanel.add(charMinusButton); //Adds the CHAR minus button to the JPanel.
  333.                 gamePanel.add(spMinusButton); //Adds the SP minus button to the JPanel.
  334.                 gamePanel.add(hpMinusButton); //Adds the HP minus button to the JPanel.
  335.                
  336.                 gamePanel.add(cancelButton); //Adds the cancel button to the JPanel.
  337.                 gamePanel.add(continueButton); //Adds the continue button to the JPanel.
  338.                
  339.                 Insets insets = gamePanel.getInsets(); //Gets the amount of space that the gameWindow's boarders take up so that you can use it to better position your JButtons and stuff.
  340.                
  341.                 strAttributeLabel1.setBounds(10 + insets.left, 10 + insets.top, 30, 20); //X coords, Y Coords. Width, Height.
  342.                 agilAttributeLabel1.setBounds(10 + insets.left, 35 + insets.top, 30, 20); //X coords, Y Coords. Width, Height.
  343.                 dexAttributeLabel1.setBounds(10 + insets.left, 60 + insets.top, 30, 20); //X coords, Y Coords. Width, Height.
  344.                 intAttributeLabel1.setBounds(10 + insets.left, 85 + insets.top, 30, 20); //X coords, Y Coords. Width, Height.
  345.                 conAttributeLabel1.setBounds(10 + insets.left, 110 + insets.top, 30, 20); //X coords, Y Coords. Width, Height.
  346.                 charAttributeLabel1.setBounds(10 + insets.left, 135 + insets.top, 40, 20); //X coords, Y Coords. Width, Height.
  347.                 spAttributeLabel1.setBounds(10 + insets.left, 160 + insets.top, 30, 20); //X coords, Y Coords. Width, Height.
  348.                 hpAttributeLabel1.setBounds(10 + insets.left, 185 + insets.top, 30, 20); //X coords, Y Coords. Width, Height.
  349.                
  350.                 strAddButton.setBounds(60 + insets.left, 10 + insets.top, 20, 20); //X coords, Y Coords. Width, Height.
  351.                 agilAddButton.setBounds(60 + insets.left, 35 + insets.top, 20, 20); //X coords, Y Coords. Width, Height.
  352.                 dexAddButton.setBounds(60 + insets.left, 60 + insets.top, 20, 20); //X coords, Y Coords. Width, Height.
  353.                 intAddButton.setBounds(60 + insets.left, 85 + insets.top, 20, 20); //X coords, Y Coords. Width, Height.
  354.                 conAddButton.setBounds(60 + insets.left, 110 + insets.top, 20, 20); //X coords, Y Coords. Width, Height.
  355.                 charAddButton.setBounds(60 + insets.left, 135 + insets.top, 20, 20); //X coords, Y Coords. Width, Height.
  356.                 spAddButton.setBounds(60 + insets.left, 160 + insets.top, 20, 20); //X coords, Y Coords. Width, Height.
  357.                 hpAddButton.setBounds(60 + insets.left, 185 + insets.top, 20, 20); //X coords, Y Coords. Width, Height.
  358.                
  359.                 strMinusButton.setBounds(85 + insets.left, 10 + insets.top, 20, 20); //X coords, Y Coords. Width, Height.
  360.                 agilMinusButton.setBounds(85 + insets.left, 35 + insets.top, 20, 20); //X coords, Y Coords. Width, Height.
  361.                 dexMinusButton.setBounds(85 + insets.left, 60 + insets.top, 20, 20); //X coords, Y Coords. Width, Height.
  362.                 intMinusButton.setBounds(85 + insets.left, 85 + insets.top, 20, 20); //X coords, Y Coords. Width, Height.
  363.                 conMinusButton.setBounds(85 + insets.left, 110 + insets.top, 20, 20); //X coords, Y Coords. Width, Height.
  364.                 charMinusButton.setBounds(85 + insets.left, 135 + insets.top, 20, 20); //X coords, Y Coords. Width, Height.
  365.                 spMinusButton.setBounds(85 + insets.left, 160 + insets.top, 20, 20); //X coords, Y Coords. Width, Height.
  366.                 hpMinusButton.setBounds(85 + insets.left, 185 + insets.top, 20, 20); //X coords, Y Coords. Width, Height.
  367.                
  368.                 cancelButton.setBounds(360 + insets.left, 410 + insets.top, 120, 40); //X coords, Y Coords. Width, Height.
  369.                 continueButton.setBounds(500 + insets.left, 410 + insets.top, 120, 40); //X coords, Y Coords. Width, Height.
  370.                
  371.                 strAddButton.setBorder(null); //Disables the thin black box around the button
  372.                 agilAddButton.setBorder(null); //Disables the thin black box around the button
  373.                 dexAddButton.setBorder(null); //Disables the thin black box around the button
  374.                 intAddButton.setBorder(null); //Disables the thin black box around the button
  375.                 conAddButton.setBorder(null); //Disables the thin black box around the button
  376.                 charAddButton.setBorder(null); //Disables the thin black box around the button
  377.                 spAddButton.setBorder(null); //Disables the thin black box around the button
  378.                 hpAddButton.setBorder(null); //Disables the thin black box around the button
  379.                
  380.                 strMinusButton.setBorder(null); //Disables the thin black box around the button
  381.                 agilMinusButton.setBorder(null); //Disables the thin black box around the button
  382.                 dexMinusButton.setBorder(null); //Disables the thin black box around the button
  383.                 intMinusButton.setBorder(null); //Disables the thin black box around the button
  384.                 conMinusButton.setBorder(null); //Disables the thin black box around the button
  385.                 charMinusButton.setBorder(null); //Disables the thin black box around the button
  386.                 spMinusButton.setBorder(null); //Disables the thin black box around the button
  387.                 hpMinusButton.setBorder(null); //Disables the thin black box around the button
  388.                
  389.                 cancelButton.setBorder(null); //Disables the thin black box around the button
  390.                 continueButton.setBorder(null); //Disables the thin black box around the button
  391.                
  392.                 strAddButton.setFocusPainted(false); //Makes it so that when you select the button there wont be a little box around the words to signify that the button is currently selected.
  393.                 agilAddButton.setFocusPainted(false); //Makes it so that when you select the button there wont be a little box around the words to signify that the button is currently selected.
  394.                 dexAddButton.setFocusPainted(false); //Makes it so that when you select the button there wont be a little box around the words to signify that the button is currently selected.
  395.                 intAddButton.setFocusPainted(false); //Makes it so that when you select the button there wont be a little box around the words to signify that the button is currently selected.
  396.                 conAddButton.setFocusPainted(false); //Makes it so that when you select the button there wont be a little box around the words to signify that the button is currently selected.
  397.                 charAddButton.setFocusPainted(false); //Makes it so that when you select the button there wont be a little box around the words to signify that the button is currently selected.
  398.                 spAddButton.setFocusPainted(false); //Makes it so that when you select the button there wont be a little box around the words to signify that the button is currently selected.
  399.                 hpAddButton.setFocusPainted(false); //Makes it so that when you select the button there wont be a little box around the words to signify that the button is currently selected.
  400.                
  401.                 strMinusButton.setFocusPainted(false); //Makes it so that when you select the button there wont be a little box around the words to signify that the button is currently selected.
  402.                 agilMinusButton.setFocusPainted(false); //Makes it so that when you select the button there wont be a little box around the words to signify that the button is currently selected.
  403.                 dexMinusButton.setFocusPainted(false); //Makes it so that when you select the button there wont be a little box around the words to signify that the button is currently selected.
  404.                 intMinusButton.setFocusPainted(false); //Makes it so that when you select the button there wont be a little box around the words to signify that the button is currently selected.
  405.                 conMinusButton.setFocusPainted(false); //Makes it so that when you select the button there wont be a little box around the words to signify that the button is currently selected.
  406.                 charMinusButton.setFocusPainted(false); //Makes it so that when you select the button there wont be a little box around the words to signify that the button is currently selected.
  407.                 spMinusButton.setFocusPainted(false); //Makes it so that when you select the button there wont be a little box around the words to signify that the button is currently selected.
  408.                 hpMinusButton.setFocusPainted(false); //Makes it so that when you select the button there wont be a little box around the words to signify that the button is currently selected.
  409.                
  410.                 cancelButton.setFocusPainted(false); //Makes it so that when you select the button there wont be a little box around the words to signify that the button is currently selected.
  411.                 continueButton.setFocusPainted(false); //Makes it so that when you select the button there wont be a little box around the words to signify that the button is currently selected.
  412.                
  413.                 strAddButton.setContentAreaFilled(false); //Gets rid of the grey fill when you select the button.
  414.                 agilAddButton.setContentAreaFilled(false); //Gets rid of the grey fill when you select the button.
  415.                 dexAddButton.setContentAreaFilled(false); //Gets rid of the grey fill when you select the button.
  416.                 intAddButton.setContentAreaFilled(false); //Gets rid of the grey fill when you select the button.
  417.                 conAddButton.setContentAreaFilled(false); //Gets rid of the grey fill when you select the button.
  418.                 charAddButton.setContentAreaFilled(false); //Gets rid of the grey fill when you select the button.
  419.                 spAddButton.setContentAreaFilled(false); //Gets rid of the grey fill when you select the button.
  420.                 hpAddButton.setContentAreaFilled(false); //Gets rid of the grey fill when you select the button.
  421.                
  422.                 strMinusButton.setContentAreaFilled(false); //Gets rid of the grey fill when you select the button.
  423.                 agilMinusButton.setContentAreaFilled(false); //Gets rid of the grey fill when you select the button.
  424.                 dexMinusButton.setContentAreaFilled(false); //Gets rid of the grey fill when you select the button.
  425.                 intMinusButton.setContentAreaFilled(false); //Gets rid of the grey fill when you select the button.
  426.                 conMinusButton.setContentAreaFilled(false); //Gets rid of the grey fill when you select the button.
  427.                 charMinusButton.setContentAreaFilled(false); //Gets rid of the grey fill when you select the button.
  428.                 spMinusButton.setContentAreaFilled(false); //Gets rid of the grey fill when you select the button.
  429.                 hpMinusButton.setContentAreaFilled(false); //Gets rid of the grey fill when you select the button.
  430.                
  431.                 strAttributeLabel1.setFont(GlobalVariables.abaddonFont); //Sets the strAttributeLabel1 to use the custom ABADDON font.
  432.                 agilAttributeLabel1.setFont(GlobalVariables.abaddonFont); //Sets the agilAttributeLabel1 to use the custom ABADDON font.
  433.                 dexAttributeLabel1.setFont(GlobalVariables.abaddonFont); //Sets the dexAttributeLabel1 to use the custom ABADDON font.
  434.                 intAttributeLabel1.setFont(GlobalVariables.abaddonFont); //Sets the intAttributeLabel1 to use the custom ABADDON font.
  435.                 conAttributeLabel1.setFont(GlobalVariables.abaddonFont); //Sets the conAttributeLabel1 to use the custom ABADDON font.
  436.                 charAttributeLabel1.setFont(GlobalVariables.abaddonFont); //Sets the charAttributeLabel1 to use the custom ABADDON font.
  437.                 spAttributeLabel1.setFont(GlobalVariables.abaddonFont); //Sets the spAttributeLabel1 to use the custom ABADDON font.
  438.                 hpAttributeLabel1.setFont(GlobalVariables.abaddonFont); //Sets the hpAttributeLabel1 to use the custom ABADDON font.
  439.                
  440.                 cancelButton.setContentAreaFilled(false); //Gets rid of the grey fill when you select the button.
  441.                 continueButton.setContentAreaFilled(false); //Gets rid of the grey fill when you select the button.
  442.                
  443.                 Icon cancelButtonIcon = new ImageIcon("button_cancelButton_normal.png"); //Creates a new ImageIcon object that will be used as the cancelButton.
  444.                 Icon continueButtonIcon = new ImageIcon("button_continueButton_normal.png"); //Creates a new ImageIcon object that will be used as the continueButton.
  445.                
  446.                 cancelButton.setIcon(cancelButtonIcon); //Covers the cancelButton icon with the button_cancelButton_normal.png image.
  447.                 continueButton.setIcon(continueButtonIcon); //Covers the continueButton icon with the button_continueButton_normal.png image.
  448.                
  449.                 Icon cancelButtonIconRollover = new ImageIcon("button_cancelButton_rollover.png"); //Creates a new ImageIcon object that will be used as the rollover version of the cancelButton.
  450.                 Icon continueButtonIconRollover = new ImageIcon("button_continueButton_rollover.png"); //Creates a new ImageIcon object that will be used as the rollover version of the continueButton.
  451.                
  452.                 cancelButton.setRolloverIcon(cancelButtonIconRollover); //Tells the cancelButton to, when the mouse is over it, change to the rollover version of the cancelButton.
  453.                 continueButton.setRolloverIcon(continueButtonIconRollover); //Tells the continueButton to, when the mouse is over it, change to the rollover version of the continueButton.
  454.                
  455.                 Icon cancelButtonIconPressed = new ImageIcon("button_cancelButton_press.png"); //Creates a new ImageIcon object that will be used as the pressed version of the cancelButton.
  456.                 Icon continueButtonIconPressed = new ImageIcon("button_continueButton_press.png"); //Creates a new ImageIcon object that will be used as the pressed version of the continueButton.
  457.                
  458.                 cancelButton.setPressedIcon(cancelButtonIconPressed); //Tells the cancelButton to, when the mouse is over it, change to the rollover version of the cancelButton.
  459.                 continueButton.setPressedIcon(continueButtonIconPressed); //Tells the continueButton to, when the mouse is over it, change to the rollover version of the continueButton.
  460.                
  461.                 cancelButton.addActionListener(new ActionListener() {  //Action listener for the closeButton
  462.                         public void actionPerformed(ActionEvent e)
  463.                         {
  464.                                 System.out.println("You've pressed the Cancel Button on the Character Creation screen.");
  465.                                 gamePanel.remove(cancelButton); //Removes the cancelButton
  466.                                 gamePanel.remove(continueButton); //Removes the continueButton
  467.                                 gamePanel.remove(strAddButton); //Removes the strAddButton
  468.                                 gamePanel.remove(agilAddButton); //Removes the agilAddButton
  469.                                 gamePanel.remove(dexAddButton); //Removes the dexAddButton
  470.                                 gamePanel.remove(intAddButton); //Removes the intAddButton
  471.                                 gamePanel.remove(conAddButton); //Removes the conAddButton
  472.                                 gamePanel.remove(charAddButton); //Removes the charAddButton
  473.                                 gamePanel.remove(spAddButton); //Removes the spAddButton
  474.                                 gamePanel.remove(hpAddButton); //Removes the hpAddButton
  475.                                 gamePanel.remove(strMinusButton); //Removes the strMinusButton
  476.                                 gamePanel.remove(agilMinusButton); //Removes the agilMinusButton
  477.                                 gamePanel.remove(dexMinusButton); //Removes the dexMinusButton
  478.                                 gamePanel.remove(intMinusButton); //Removes the intMinusButton
  479.                                 gamePanel.remove(conMinusButton); //Removes the conMinusButton
  480.                                 gamePanel.remove(charMinusButton); //Removes the charMinusButton
  481.                                 gamePanel.remove(spMinusButton); //Removes the spMinusButton
  482.                                 gamePanel.remove(hpMinusButton); //Removes the hpMinusButton
  483.                                 gamePanel.remove(strAttributeLabel1); //Removes the strAttributeLabel1
  484.                                 gamePanel.remove(agilAttributeLabel1); //Removes the agilAttributeLabel1
  485.                                 gamePanel.remove(dexAttributeLabel1); //Removes the dexAttributeLabel1
  486.                                 gamePanel.remove(intAttributeLabel1); //Removes the intAttributeLabel1
  487.                                 gamePanel.remove(conAttributeLabel1); //Removes the conAttributeLabel1
  488.                                 gamePanel.remove(charAttributeLabel1); //Removes the charAttributeLabel1
  489.                                 gamePanel.remove(spAttributeLabel1); //Removes the spAttributeLabel1
  490.                                 gamePanel.remove(hpAttributeLabel1); //Removes the hpAttributeLabel1
  491.                                 gamePanel.repaint(); //Re-loads the JPanel, also known as gamePanel, so that the deleted buttons disappear.
  492.                                 CreateMainMenu gameWindow = new CreateMainMenu(gamePanel);
  493.                         }});
  494.                        
  495.                         strAddButton.addActionListener(new ActionListener() {  //Action listener for the strAddButton
  496.                         public void actionPerformed(ActionEvent e)
  497.                         {
  498.                                 if (tempPointsToSpend > 0)
  499.                                 {
  500.                                         tempPointsToSpend--;
  501.                                         tempStr++;
  502.                                 }
  503.                                
  504.                                 System.out.println("You've pressed the strAddButton, Str is now: "+tempStr+"");
  505.                                 System.out.println("You've pressed the strAddButton, you now have "+tempPointsToSpend+" points to spend.");
  506.                         }});
  507.         }
  508. }
  509.  
  510. public class Game extends JFrame
  511. {      
  512.         public static void main(String args[]) //This is the main menu of the game, the method has been called 'main' so it will be the first thing to run when the program is loaded.
  513.         {
  514.                
  515.                 InputStream fontInputStream = Game.class.getResourceAsStream("ABADDON.ttf");
  516.                 if (fontInputStream != null)
  517.                 {
  518.                         try
  519.                         {
  520.                                 GlobalVariables.abaddonFont = Font.createFont(Font.TRUETYPE_FONT, fontInputStream);
  521.                                 GlobalVariables.abaddonFont = GlobalVariables.abaddonFont.deriveFont(16f); //Change the 18 to whatever size you want the font to be.
  522.                                 fontInputStream.close(); //Closes the input stream now that I'm done with it.
  523.                         }
  524.                         catch (Exception e)
  525.                         {
  526.                                 System.out.println("error" + e);
  527.                         }
  528.                        
  529.                 }
  530.                
  531.                 CreateGameWindowFirst gameWindow = new CreateGameWindowFirst(); //Calls the CreateGameWindow method of the CreateGameWindow class so that the window and that will be set up
  532.         }
  533. }
clone this paste RAW Paste Data