Advertisement
Guest User

Kraz Full Code

a guest
Jul 18th, 2012
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 17.98 KB | None | 0 0
  1. package kraz;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4. import java.util.Scanner;
  5.  
  6. public class Kraz extends javax.swing.JFrame implements ActionListener{
  7.    
  8.     private Scanner in = new Scanner(System.in);
  9.     private int step = 1, health, progress, nameEdit = 0;
  10.     private static String name = "Nothing", path;
  11.     private javax.swing.JButton EditGame;
  12.     private javax.swing.JButton EditName;
  13.     private javax.swing.JButton EndGame;
  14.     private javax.swing.JTextPane EventField;
  15.     private javax.swing.JButton Exit;
  16.     private javax.swing.JLabel GameLabel;
  17.     private javax.swing.ButtonGroup GameOptions;
  18.     private javax.swing.JProgressBar HealthBar;
  19.     private javax.swing.JLabel HealthLabel;
  20.     private javax.swing.JButton HighScores;
  21.     private javax.swing.JPanel Holder;
  22.     private javax.swing.JLabel InvLabel;
  23.     private javax.swing.ButtonGroup InventoryOptions;
  24.     private javax.swing.JButton Left;
  25.     private javax.swing.JButton Middle;
  26.     private javax.swing.JLabel PathLabel;
  27.     private javax.swing.ButtonGroup PathOptions;
  28.     private javax.swing.JButton PickUp;
  29.     private javax.swing.JProgressBar ProgressBar;
  30.     private javax.swing.JLabel ProgressLabel;
  31.     private javax.swing.JButton RestartGame;
  32.     private javax.swing.JButton Right;
  33.     private javax.swing.JButton SetDown;
  34.     private javax.swing.JLabel SettingLabel;
  35.     private javax.swing.ButtonGroup Settings;
  36.     private javax.swing.JButton Use;
  37.     private javax.swing.JPanel jPanel1, jPanel2;
  38.     private javax.swing.JScrollPane jScrollPane1;
  39.     private javax.swing.JButton Sumbit;
  40.     private javax.swing.JLabel NameLabel;
  41.     private javax.swing.JTextField NameField;
  42.    
  43.     public Kraz() {
  44.         initComponents();
  45.         setVisible(true);
  46.         game();
  47.     }
  48.     public Kraz(String check) {
  49.         if (check.equals("editName"))
  50.         {
  51.             editName();
  52.             setVisible(true);
  53.         }
  54.     }
  55.     public void game() {
  56.         if (step == 1)
  57.         {
  58.             HealthBar.setValue(100);
  59.         }
  60.         else if (step == 2)
  61.         {
  62.             EventField.setText("Test");
  63.             ProgressBar.setValue(1);
  64.         }
  65.         else if (step == 3)
  66.         {
  67.             EventField.setText("You want to go " + path + " eh? Well before we do so, I suggest you pick up this knife.");
  68.             ProgressBar.setValue(2);
  69.         }
  70.     }
  71.     private void editName() {
  72.         NameLabel = new javax.swing.JLabel();
  73.         NameField = new javax.swing.JTextField();
  74.         Sumbit = new javax.swing.JButton();
  75.         Sumbit.addActionListener(this);
  76.  
  77.         setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
  78.         setAlwaysOnTop(true);
  79.         setType(java.awt.Window.Type.POPUP);
  80.  
  81.         NameLabel.setText("Name:");
  82.         NameField.setText(name);
  83.         Sumbit.setText("Sumbit");
  84.  
  85.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  86.         getContentPane().setLayout(layout);
  87.         layout.setHorizontalGroup(
  88.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  89.             .addGroup(layout.createSequentialGroup()
  90.                 .addContainerGap()
  91.                 .addComponent(NameLabel)
  92.                 .addGap(18, 18, 18)
  93.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  94.                     .addComponent(Sumbit)
  95.                     .addComponent(NameField, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE))
  96.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  97.         );
  98.         layout.setVerticalGroup(
  99.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  100.             .addGroup(layout.createSequentialGroup()
  101.                 .addContainerGap()
  102.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  103.                     .addComponent(NameLabel)
  104.                     .addComponent(NameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  105.                 .addGap(18, 18, 18)
  106.                 .addComponent(Sumbit)
  107.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  108.         );
  109.  
  110.         pack();
  111.     }
  112.    
  113.     public void actionPerformed(ActionEvent e)
  114.     {
  115.         if (e.getSource() == Left)
  116.         {
  117.             if (step == 2)
  118.             {
  119.                 path = "left";
  120.                 ++step;
  121.                 game();
  122.             }
  123.         }
  124.         else if (e.getSource() == Right)
  125.         {
  126.             if (step == 2)
  127.             {
  128.                 path = "right";
  129.                 ++step;
  130.                 game();
  131.             }
  132.         }
  133.         else if (e.getSource() == Middle)
  134.         {
  135.             if (step == 2)
  136.             {
  137.                 path = "middle";
  138.                 ++step;
  139.                 game();
  140.             }
  141.         }
  142.         else if (e.getSource() == PickUp)
  143.         {
  144.            
  145.         }
  146.         else if (e.getSource() == SetDown)
  147.         {
  148.            
  149.         }
  150.         else if (e.getSource() == Use)
  151.         {
  152.            
  153.         }
  154.         else if (e.getSource() == HighScores)
  155.         {
  156.            
  157.         }
  158.         else if (e.getSource() == EditName)
  159.         {
  160.             new Kraz("editName");
  161.         }
  162.         else if (e.getSource() == EditGame)
  163.         {
  164.            
  165.         }
  166.         else if (e.getSource() == RestartGame)
  167.         {
  168.            
  169.         }
  170.         else if (e.getSource() == EndGame)
  171.         {
  172.            
  173.         }
  174.         else if (e.getSource() == Exit)
  175.         {
  176.            
  177.         }
  178.         else if (e.getSource() == Sumbit)
  179.         {
  180.             name = NameField.getText();
  181.             NameField.setText("" + name);
  182.            
  183.             if (step == 1)
  184.             {
  185.                 ++step;
  186.                 game();
  187.             }
  188.         }
  189.     }
  190.     private void initComponents() {
  191.  
  192.         PathOptions = new javax.swing.ButtonGroup();
  193.         InventoryOptions = new javax.swing.ButtonGroup();
  194.         Settings = new javax.swing.ButtonGroup();
  195.         GameOptions = new javax.swing.ButtonGroup();
  196.         Holder = new javax.swing.JPanel();
  197.         jScrollPane1 = new javax.swing.JScrollPane();
  198.         EventField = new javax.swing.JTextPane();
  199.         PathLabel = new javax.swing.JLabel();
  200.         Left = new javax.swing.JButton();
  201.         Left.addActionListener(this);
  202.         Right = new javax.swing.JButton();
  203.         Right.addActionListener(this);
  204.         Middle = new javax.swing.JButton();
  205.         Middle.addActionListener(this);
  206.         InvLabel = new javax.swing.JLabel();
  207.         PickUp = new javax.swing.JButton();
  208.         PickUp.addActionListener(this);
  209.         SetDown = new javax.swing.JButton();
  210.         SetDown.addActionListener(this);
  211.         Use = new javax.swing.JButton();
  212.         Use.addActionListener(this);
  213.         SettingLabel = new javax.swing.JLabel();
  214.         HighScores = new javax.swing.JButton();
  215.         HighScores.addActionListener(this);
  216.         EditName = new javax.swing.JButton();
  217.         EditName.addActionListener(this);
  218.         EditGame = new javax.swing.JButton();
  219.         EditGame.addActionListener(this);
  220.         ProgressLabel = new javax.swing.JLabel();
  221.         ProgressBar = new javax.swing.JProgressBar(0,20);
  222.         HealthBar = new javax.swing.JProgressBar(0,100);
  223.         HealthLabel = new javax.swing.JLabel();
  224.         RestartGame = new javax.swing.JButton();
  225.         RestartGame.addActionListener(this);
  226.         EndGame = new javax.swing.JButton();
  227.         EndGame.addActionListener(this);
  228.         Exit = new javax.swing.JButton();
  229.         Exit.addActionListener(this);
  230.         GameLabel = new javax.swing.JLabel();
  231.         jPanel1 = new javax.swing.JPanel();
  232.  
  233.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  234.         setAlwaysOnTop(true);
  235.         setType(java.awt.Window.Type.NORMAL);
  236.  
  237.         jScrollPane1.setViewportView(EventField);
  238.  
  239.         EventField.setText("Hellow and welcome to Kraz, an interactive text adventure game! I am Jared,\n the coder of the game and I will be here to guide you "
  240.                 + "through the story. \nThe first step, it's quite simple, all you have to do is go down there and hit the \nbutton that says \"Edit Name\" and put "
  241.                 + "your name in!");
  242.         EventField.setBackground(new java.awt.Color(0, 0, 0));
  243.         EventField.setEditable(false);
  244.         EventField.setForeground(new java.awt.Color(255,255,255));
  245.                
  246.         PathLabel.setText("Path Options:");
  247.  
  248.         Left.setText("Go Left");
  249.         PathOptions.add(Left);
  250.  
  251.         Right.setText("Go Right");
  252.         PathOptions.add(Right);
  253.  
  254.         Middle.setText("Go Middle");
  255.         PathOptions.add(Middle);
  256.  
  257.         InvLabel.setText("Inventory Options:");
  258.  
  259.         PickUp.setText("Pick Up");
  260.         InventoryOptions.add(PickUp);
  261.  
  262.         SetDown.setText("Set Down");
  263.         InventoryOptions.add(SetDown);
  264.  
  265.         Use.setText("Use");
  266.         InventoryOptions.add(Use);
  267.  
  268.         SettingLabel.setText("Settings:");
  269.  
  270.         HighScores.setText("High Scores");
  271.         Settings.add(HighScores);
  272.  
  273.         EditName.setText("Edit Name");
  274.         Settings.add(EditName);
  275.  
  276.         EditGame.setText("Edit Game");
  277.         Settings.add(EditGame);
  278.  
  279.         ProgressLabel.setText("Progress:");
  280.  
  281.         HealthLabel.setText("Health:");
  282.  
  283.         RestartGame.setText("Restart Game");
  284.         GameOptions.add(RestartGame);
  285.  
  286.         EndGame.setText("End Game");
  287.         GameOptions.add(EndGame);
  288.  
  289.         Exit.setText("Exit");
  290.         GameOptions.add(Exit);
  291.  
  292.         GameLabel.setText("Game Options:");
  293.  
  294.         javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  295.         jPanel1.setLayout(jPanel1Layout);
  296.         jPanel1Layout.setHorizontalGroup(
  297.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  298.             .addGap(0, 100, Short.MAX_VALUE)
  299.         );
  300.         jPanel1Layout.setVerticalGroup(
  301.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  302.             .addGap(0, 100, Short.MAX_VALUE)
  303.         );
  304.  
  305.         javax.swing.GroupLayout HolderLayout = new javax.swing.GroupLayout(Holder);
  306.         Holder.setLayout(HolderLayout);
  307.         HolderLayout.setHorizontalGroup(
  308.             HolderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  309.             .addGroup(HolderLayout.createSequentialGroup()
  310.                 .addContainerGap()
  311.                 .addGroup(HolderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  312.                     .addGroup(HolderLayout.createSequentialGroup()
  313.                         .addGroup(HolderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  314.                             .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING)
  315.                             .addGroup(HolderLayout.createSequentialGroup()
  316.                                 .addGroup(HolderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  317.                                     .addGroup(HolderLayout.createSequentialGroup()
  318.                                         .addComponent(InvLabel)
  319.                                         .addGap(18, 18, 18)
  320.                                         .addComponent(PickUp)
  321.                                         .addGap(18, 18, 18)
  322.                                         .addComponent(SetDown)
  323.                                         .addGap(18, 18, 18)
  324.                                         .addComponent(Use))
  325.                                     .addGroup(HolderLayout.createSequentialGroup()
  326.                                         .addComponent(SettingLabel)
  327.                                         .addGap(18, 18, 18)
  328.                                         .addComponent(HighScores)
  329.                                         .addGap(18, 18, 18)
  330.                                         .addComponent(EditName)
  331.                                         .addGap(18, 18, 18)
  332.                                         .addComponent(EditGame))
  333.                                     .addGroup(HolderLayout.createSequentialGroup()
  334.                                         .addComponent(PathLabel)
  335.                                         .addGap(18, 18, 18)
  336.                                         .addGroup(HolderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  337.                                             .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  338.                                             .addGroup(HolderLayout.createSequentialGroup()
  339.                                                 .addComponent(Left)
  340.                                                 .addGap(18, 18, 18)
  341.                                                 .addComponent(Right)
  342.                                                 .addGap(18, 18, 18)
  343.                                                 .addComponent(Middle)))))
  344.                                 .addGap(0, 17, Short.MAX_VALUE))
  345.                             .addGroup(HolderLayout.createSequentialGroup()
  346.                                 .addComponent(ProgressLabel)
  347.                                 .addGap(18, 18, 18)
  348.                                 .addComponent(ProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
  349.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  350.                                 .addComponent(HealthLabel)
  351.                                 .addGap(18, 18, 18)
  352.                                 .addComponent(HealthBar, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)))
  353.                         .addContainerGap())
  354.                     .addGroup(HolderLayout.createSequentialGroup()
  355.                         .addComponent(GameLabel)
  356.                         .addGap(18, 18, 18)
  357.                         .addComponent(RestartGame)
  358.                         .addGap(18, 18, 18)
  359.                         .addComponent(EndGame)
  360.                         .addGap(18, 18, 18)
  361.                         .addComponent(Exit)
  362.                         .addGap(0, 0, Short.MAX_VALUE))))
  363.         );
  364.         HolderLayout.setVerticalGroup(
  365.             HolderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  366.             .addGroup(HolderLayout.createSequentialGroup()
  367.                 .addContainerGap()
  368.                 .addGroup(HolderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  369.                     .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
  370.                     .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  371.                 .addGap(18, 18, 18)
  372.                 .addGroup(HolderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  373.                     .addGroup(HolderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  374.                         .addComponent(Right)
  375.                         .addComponent(Middle)
  376.                         .addComponent(Left))
  377.                     .addComponent(PathLabel))
  378.                 .addGap(18, 18, 18)
  379.                 .addGroup(HolderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  380.                     .addComponent(InvLabel)
  381.                     .addComponent(PickUp)
  382.                     .addComponent(SetDown)
  383.                     .addComponent(Use))
  384.                 .addGap(18, 18, 18)
  385.                 .addGroup(HolderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  386.                     .addComponent(SettingLabel)
  387.                     .addComponent(HighScores)
  388.                     .addComponent(EditName)
  389.                     .addComponent(EditGame))
  390.                 .addGap(18, 18, 18)
  391.                 .addGroup(HolderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  392.                     .addComponent(ProgressLabel)
  393.                     .addComponent(ProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  394.                     .addComponent(HealthBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  395.                     .addComponent(HealthLabel))
  396.                 .addGap(18, 18, 18)
  397.                 .addGroup(HolderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  398.                     .addComponent(GameLabel)
  399.                     .addComponent(RestartGame)
  400.                     .addComponent(EndGame)
  401.                     .addComponent(Exit))
  402.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  403.         );
  404.  
  405.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  406.         getContentPane().setLayout(layout);
  407.         layout.setHorizontalGroup(
  408.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  409.             .addComponent(Holder, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  410.         );
  411.         layout.setVerticalGroup(
  412.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  413.             .addComponent(Holder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  414.         );
  415.  
  416.         pack();
  417.     }
  418.  
  419.     public static void main(String args[]) {
  420.         java.awt.EventQueue.invokeLater(new Runnable() {
  421.  
  422.             @Override
  423.             public void run() {
  424.                 new Kraz();
  425.             }
  426.         });
  427.     }
  428. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement