Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package kraz;
- import java.awt.event.*;
- import javax.swing.*;
- import java.util.Scanner;
- public class Kraz extends javax.swing.JFrame implements ActionListener{
- private Scanner in = new Scanner(System.in);
- private int step = 1, health, progress, nameEdit = 0;
- private static String name = "Nothing", path;
- private javax.swing.JButton EditGame;
- private javax.swing.JButton EditName;
- private javax.swing.JButton EndGame;
- private javax.swing.JTextPane EventField;
- private javax.swing.JButton Exit;
- private javax.swing.JLabel GameLabel;
- private javax.swing.ButtonGroup GameOptions;
- private javax.swing.JProgressBar HealthBar;
- private javax.swing.JLabel HealthLabel;
- private javax.swing.JButton HighScores;
- private javax.swing.JPanel Holder;
- private javax.swing.JLabel InvLabel;
- private javax.swing.ButtonGroup InventoryOptions;
- private javax.swing.JButton Left;
- private javax.swing.JButton Middle;
- private javax.swing.JLabel PathLabel;
- private javax.swing.ButtonGroup PathOptions;
- private javax.swing.JButton PickUp;
- private javax.swing.JProgressBar ProgressBar;
- private javax.swing.JLabel ProgressLabel;
- private javax.swing.JButton RestartGame;
- private javax.swing.JButton Right;
- private javax.swing.JButton SetDown;
- private javax.swing.JLabel SettingLabel;
- private javax.swing.ButtonGroup Settings;
- private javax.swing.JButton Use;
- private javax.swing.JPanel jPanel1, jPanel2;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JButton Sumbit;
- private javax.swing.JLabel NameLabel;
- private javax.swing.JTextField NameField;
- public Kraz() {
- initComponents();
- setVisible(true);
- game();
- }
- public Kraz(String check) {
- if (check.equals("editName"))
- {
- editName();
- setVisible(true);
- }
- }
- public void game() {
- if (step == 1)
- {
- HealthBar.setValue(100);
- }
- else if (step == 2)
- {
- EventField.setText("Test");
- ProgressBar.setValue(1);
- }
- else if (step == 3)
- {
- EventField.setText("You want to go " + path + " eh? Well before we do so, I suggest you pick up this knife.");
- ProgressBar.setValue(2);
- }
- }
- private void editName() {
- NameLabel = new javax.swing.JLabel();
- NameField = new javax.swing.JTextField();
- Sumbit = new javax.swing.JButton();
- Sumbit.addActionListener(this);
- setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- setAlwaysOnTop(true);
- setType(java.awt.Window.Type.POPUP);
- NameLabel.setText("Name:");
- NameField.setText(name);
- Sumbit.setText("Sumbit");
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(NameLabel)
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(Sumbit)
- .addComponent(NameField, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(NameLabel)
- .addComponent(NameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addComponent(Sumbit)
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- pack();
- }
- public void actionPerformed(ActionEvent e)
- {
- if (e.getSource() == Left)
- {
- if (step == 2)
- {
- path = "left";
- ++step;
- game();
- }
- }
- else if (e.getSource() == Right)
- {
- if (step == 2)
- {
- path = "right";
- ++step;
- game();
- }
- }
- else if (e.getSource() == Middle)
- {
- if (step == 2)
- {
- path = "middle";
- ++step;
- game();
- }
- }
- else if (e.getSource() == PickUp)
- {
- }
- else if (e.getSource() == SetDown)
- {
- }
- else if (e.getSource() == Use)
- {
- }
- else if (e.getSource() == HighScores)
- {
- }
- else if (e.getSource() == EditName)
- {
- new Kraz("editName");
- }
- else if (e.getSource() == EditGame)
- {
- }
- else if (e.getSource() == RestartGame)
- {
- }
- else if (e.getSource() == EndGame)
- {
- }
- else if (e.getSource() == Exit)
- {
- }
- else if (e.getSource() == Sumbit)
- {
- name = NameField.getText();
- NameField.setText("" + name);
- if (step == 1)
- {
- ++step;
- game();
- }
- }
- }
- private void initComponents() {
- PathOptions = new javax.swing.ButtonGroup();
- InventoryOptions = new javax.swing.ButtonGroup();
- Settings = new javax.swing.ButtonGroup();
- GameOptions = new javax.swing.ButtonGroup();
- Holder = new javax.swing.JPanel();
- jScrollPane1 = new javax.swing.JScrollPane();
- EventField = new javax.swing.JTextPane();
- PathLabel = new javax.swing.JLabel();
- Left = new javax.swing.JButton();
- Left.addActionListener(this);
- Right = new javax.swing.JButton();
- Right.addActionListener(this);
- Middle = new javax.swing.JButton();
- Middle.addActionListener(this);
- InvLabel = new javax.swing.JLabel();
- PickUp = new javax.swing.JButton();
- PickUp.addActionListener(this);
- SetDown = new javax.swing.JButton();
- SetDown.addActionListener(this);
- Use = new javax.swing.JButton();
- Use.addActionListener(this);
- SettingLabel = new javax.swing.JLabel();
- HighScores = new javax.swing.JButton();
- HighScores.addActionListener(this);
- EditName = new javax.swing.JButton();
- EditName.addActionListener(this);
- EditGame = new javax.swing.JButton();
- EditGame.addActionListener(this);
- ProgressLabel = new javax.swing.JLabel();
- ProgressBar = new javax.swing.JProgressBar(0,20);
- HealthBar = new javax.swing.JProgressBar(0,100);
- HealthLabel = new javax.swing.JLabel();
- RestartGame = new javax.swing.JButton();
- RestartGame.addActionListener(this);
- EndGame = new javax.swing.JButton();
- EndGame.addActionListener(this);
- Exit = new javax.swing.JButton();
- Exit.addActionListener(this);
- GameLabel = new javax.swing.JLabel();
- jPanel1 = new javax.swing.JPanel();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- setAlwaysOnTop(true);
- setType(java.awt.Window.Type.NORMAL);
- jScrollPane1.setViewportView(EventField);
- 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 "
- + "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 "
- + "your name in!");
- EventField.setBackground(new java.awt.Color(0, 0, 0));
- EventField.setEditable(false);
- EventField.setForeground(new java.awt.Color(255,255,255));
- PathLabel.setText("Path Options:");
- Left.setText("Go Left");
- PathOptions.add(Left);
- Right.setText("Go Right");
- PathOptions.add(Right);
- Middle.setText("Go Middle");
- PathOptions.add(Middle);
- InvLabel.setText("Inventory Options:");
- PickUp.setText("Pick Up");
- InventoryOptions.add(PickUp);
- SetDown.setText("Set Down");
- InventoryOptions.add(SetDown);
- Use.setText("Use");
- InventoryOptions.add(Use);
- SettingLabel.setText("Settings:");
- HighScores.setText("High Scores");
- Settings.add(HighScores);
- EditName.setText("Edit Name");
- Settings.add(EditName);
- EditGame.setText("Edit Game");
- Settings.add(EditGame);
- ProgressLabel.setText("Progress:");
- HealthLabel.setText("Health:");
- RestartGame.setText("Restart Game");
- GameOptions.add(RestartGame);
- EndGame.setText("End Game");
- GameOptions.add(EndGame);
- Exit.setText("Exit");
- GameOptions.add(Exit);
- GameLabel.setText("Game Options:");
- javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
- jPanel1.setLayout(jPanel1Layout);
- jPanel1Layout.setHorizontalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGap(0, 100, Short.MAX_VALUE)
- );
- jPanel1Layout.setVerticalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGap(0, 100, Short.MAX_VALUE)
- );
- javax.swing.GroupLayout HolderLayout = new javax.swing.GroupLayout(Holder);
- Holder.setLayout(HolderLayout);
- HolderLayout.setHorizontalGroup(
- HolderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(HolderLayout.createSequentialGroup()
- .addContainerGap()
- .addGroup(HolderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(HolderLayout.createSequentialGroup()
- .addGroup(HolderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING)
- .addGroup(HolderLayout.createSequentialGroup()
- .addGroup(HolderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(HolderLayout.createSequentialGroup()
- .addComponent(InvLabel)
- .addGap(18, 18, 18)
- .addComponent(PickUp)
- .addGap(18, 18, 18)
- .addComponent(SetDown)
- .addGap(18, 18, 18)
- .addComponent(Use))
- .addGroup(HolderLayout.createSequentialGroup()
- .addComponent(SettingLabel)
- .addGap(18, 18, 18)
- .addComponent(HighScores)
- .addGap(18, 18, 18)
- .addComponent(EditName)
- .addGap(18, 18, 18)
- .addComponent(EditGame))
- .addGroup(HolderLayout.createSequentialGroup()
- .addComponent(PathLabel)
- .addGap(18, 18, 18)
- .addGroup(HolderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGroup(HolderLayout.createSequentialGroup()
- .addComponent(Left)
- .addGap(18, 18, 18)
- .addComponent(Right)
- .addGap(18, 18, 18)
- .addComponent(Middle)))))
- .addGap(0, 17, Short.MAX_VALUE))
- .addGroup(HolderLayout.createSequentialGroup()
- .addComponent(ProgressLabel)
- .addGap(18, 18, 18)
- .addComponent(ProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(HealthLabel)
- .addGap(18, 18, 18)
- .addComponent(HealthBar, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addContainerGap())
- .addGroup(HolderLayout.createSequentialGroup()
- .addComponent(GameLabel)
- .addGap(18, 18, 18)
- .addComponent(RestartGame)
- .addGap(18, 18, 18)
- .addComponent(EndGame)
- .addGap(18, 18, 18)
- .addComponent(Exit)
- .addGap(0, 0, Short.MAX_VALUE))))
- );
- HolderLayout.setVerticalGroup(
- HolderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(HolderLayout.createSequentialGroup()
- .addContainerGap()
- .addGroup(HolderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addGroup(HolderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(HolderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(Right)
- .addComponent(Middle)
- .addComponent(Left))
- .addComponent(PathLabel))
- .addGap(18, 18, 18)
- .addGroup(HolderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(InvLabel)
- .addComponent(PickUp)
- .addComponent(SetDown)
- .addComponent(Use))
- .addGap(18, 18, 18)
- .addGroup(HolderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(SettingLabel)
- .addComponent(HighScores)
- .addComponent(EditName)
- .addComponent(EditGame))
- .addGap(18, 18, 18)
- .addGroup(HolderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(ProgressLabel)
- .addComponent(ProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(HealthBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(HealthLabel))
- .addGap(18, 18, 18)
- .addGroup(HolderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(GameLabel)
- .addComponent(RestartGame)
- .addComponent(EndGame)
- .addComponent(Exit))
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(Holder, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(Holder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- );
- pack();
- }
- public static void main(String args[]) {
- java.awt.EventQueue.invokeLater(new Runnable() {
- @Override
- public void run() {
- new Kraz();
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement