Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package gamelibrary;
- import javax.swing.UIManager;
- import javax.swing.UnsupportedLookAndFeelException;
- import javax.swing.JOptionPane;
- import javax.swing.SwingUtilities;
- /**
- *
- * @author Evan
- */
- public class GUIDriver extends javax.swing.JFrame
- {
- private String[] gameDescriptions;
- /**
- * Creates new form GUIDriver
- */
- public GUIDriver()
- {
- initComponents();
- try
- {
- UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
- }
- catch(UnsupportedLookAndFeelException e)
- {}
- catch(ClassNotFoundException e)
- {}
- catch(InstantiationException e)
- {}
- catch(IllegalAccessException e)
- {}
- setLocationRelativeTo(null);
- populateGameDescriptions();
- jTextArea1.setText(gameDescriptions[0]);
- }
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- lblTitle = new javax.swing.JLabel();
- btnExit = new javax.swing.JButton();
- btnLaunchGame = new javax.swing.JButton();
- jScrollPane1 = new javax.swing.JScrollPane();
- jTextArea1 = new javax.swing.JTextArea();
- cmbSelectGame = new javax.swing.JComboBox<>();
- lblSelectGame = new javax.swing.JLabel();
- btnControls = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- setTitle("SCCC Game Library");
- lblTitle.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
- lblTitle.setText("1LT(P) Foley Bored in SCCC Game Library");
- btnExit.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
- btnExit.setText("Exit");
- btnExit.setMaximumSize(new java.awt.Dimension(101, 23));
- btnExit.setMinimumSize(new java.awt.Dimension(101, 23));
- btnExit.setPreferredSize(new java.awt.Dimension(101, 23));
- btnExit.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btnExitActionPerformed(evt);
- }
- });
- btnLaunchGame.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
- btnLaunchGame.setText("Launch Game");
- btnLaunchGame.setMaximumSize(new java.awt.Dimension(101, 23));
- btnLaunchGame.setMinimumSize(new java.awt.Dimension(101, 23));
- btnLaunchGame.setPreferredSize(new java.awt.Dimension(101, 23));
- btnLaunchGame.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btnLaunchGameActionPerformed(evt);
- }
- });
- jTextArea1.setEditable(false);
- jTextArea1.setColumns(20);
- jTextArea1.setFont(new java.awt.Font("Arial", 0, 13)); // NOI18N
- jTextArea1.setLineWrap(true);
- jTextArea1.setRows(5);
- jTextArea1.setWrapStyleWord(true);
- jScrollPane1.setViewportView(jTextArea1);
- cmbSelectGame.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Foley Ball", "Rock Dodger", "Space Banditos", "Moon RANGER!" }));
- cmbSelectGame.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- cmbSelectGameActionPerformed(evt);
- }
- });
- lblSelectGame.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
- lblSelectGame.setText("Select Game: ");
- btnControls.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
- btnControls.setText("View Controls");
- btnControls.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btnControlsActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(58, 58, 58)
- .addComponent(lblSelectGame)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(cmbSelectGame, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(layout.createSequentialGroup()
- .addComponent(btnControls)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(btnLaunchGame, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(btnExit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
- .addGroup(layout.createSequentialGroup()
- .addGap(23, 23, 23)
- .addComponent(lblTitle)))
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(lblTitle)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
- .addComponent(lblSelectGame)
- .addComponent(cmbSelectGame, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(btnLaunchGame, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(btnExit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(btnControls))
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- private void cmbSelectGameActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- jTextArea1.setText(gameDescriptions[cmbSelectGame.getSelectedIndex()]);;
- }
- private void btnExitActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- System.exit(0);
- }
- private void btnLaunchGameActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- int game = cmbSelectGame.getSelectedIndex();
- switch(game)
- {
- case 0:
- String name1 = JOptionPane.showInputDialog(this, "Enter Player 1's name or \'quit\' to cancel");
- if(name1.equalsIgnoreCase("QUIT"))
- {
- break;
- }
- String name2 = JOptionPane.showInputDialog(this, "Enter Player 2's name or \'quit\' to cancel");
- if(name2.equalsIgnoreCase("QUIT"))
- {
- break;
- }
- SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
- new Ball(name1, name2).setVisible(true);
- }
- });
- break;
- case 1:
- JOptionPane.showConfirmDialog(this, "Playing Rock Dodger");
- break;
- case 2:
- JOptionPane.showMessageDialog(this, "Space Banditos is not yet finished. Stay tuned");
- break;
- case 3:
- JOptionPane.showMessageDialog(this, "Moon RANGER! is not yet finished. Stay tuned");
- break;
- default:
- break;
- }
- }
- private void btnControlsActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- int game = cmbSelectGame.getSelectedIndex();
- switch(game)
- {
- case 0:
- JOptionPane.showMessageDialog(this, "Player 1 uses \'W\' and \'X\' to move up and down" +
- "\nPlayer 2 uses \'NUMPAD9\' and \'NUMPAD3\' to move up and down");
- break;
- case 1:
- JOptionPane.showMessageDialog(this, "Player 1 uses \'W\' and \'S\' to move up and down," +
- "\nand \'A\' and \'D\' to move left and right");
- break;
- case 2:
- JOptionPane.showMessageDialog(this, "Players use \'W\' and \'S\' to move up and down," +
- "\n\'A\' and \'D\' to move left and right," +
- "\nand \'SPACE\' to fire their laser cannon");
- break;
- case 3:
- JOptionPane.showMessageDialog(this, "Player 1 uses \'A\' and \'D\' to move left and right," +
- "\n\'ENTER\' to jump, and \'SPACE\' to fire their laser rifle");
- break;
- default:
- break;
- }
- }
- private void populateGameDescriptions()
- {
- gameDescriptions = new String[]{"Rebound Ball is a Pong clone that lets two people play against each other on the same machine",
- "Rock Dodger puts the player in control of a spaceship in an asteroid field. Survive for as long as you can",
- "Space Banditos puts 2 gringos head-to-head in vicious space combat across a local network",
- "Moon RANGER! puts you in control of a Soldier with nothing to lose. Survive for as long as possible"};
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- //try {
- // for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- // if ("Nimbus".equals(info.getName())) {
- // javax.swing.UIManager.setLookAndFeel(info.getClassName());
- // break;
- // }
- // }
- //} catch (ClassNotFoundException ex) {
- // java.util.logging.Logger.getLogger(GUIDriver.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- //} catch (InstantiationException ex) {
- // java.util.logging.Logger.getLogger(GUIDriver.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- //} catch (IllegalAccessException ex) {
- // java.util.logging.Logger.getLogger(GUIDriver.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- //} catch (javax.swing.UnsupportedLookAndFeelException ex) {
- // java.util.logging.Logger.getLogger(GUIDriver.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- //}
- //</editor-fold>
- /* Create and display the form */
- SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
- new GUIDriver().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton btnControls;
- private javax.swing.JButton btnExit;
- private javax.swing.JButton btnLaunchGame;
- private javax.swing.JComboBox<String> cmbSelectGame;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JTextArea jTextArea1;
- private javax.swing.JLabel lblSelectGame;
- private javax.swing.JLabel lblTitle;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement