Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.35 KB | None | 0 0
  1. package gamelibrary;
  2.  
  3. import javax.swing.UIManager;
  4. import javax.swing.UnsupportedLookAndFeelException;
  5. import javax.swing.JOptionPane;
  6. import javax.swing.SwingUtilities;
  7.  
  8. /**
  9. *
  10. * @author Evan
  11. */
  12. public class GUIDriver extends javax.swing.JFrame
  13. {
  14. private String[] gameDescriptions;
  15.  
  16. /**
  17. * Creates new form GUIDriver
  18. */
  19. public GUIDriver()
  20. {
  21. initComponents();
  22.  
  23. try
  24. {
  25. UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
  26. }
  27. catch(UnsupportedLookAndFeelException e)
  28. {}
  29. catch(ClassNotFoundException e)
  30. {}
  31. catch(InstantiationException e)
  32. {}
  33. catch(IllegalAccessException e)
  34. {}
  35. setLocationRelativeTo(null);
  36.  
  37. populateGameDescriptions();
  38. jTextArea1.setText(gameDescriptions[0]);
  39. }
  40.  
  41. /**
  42. * This method is called from within the constructor to initialize the form.
  43. * WARNING: Do NOT modify this code. The content of this method is always
  44. * regenerated by the Form Editor.
  45. */
  46. @SuppressWarnings("unchecked")
  47. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  48. private void initComponents() {
  49.  
  50. lblTitle = new javax.swing.JLabel();
  51. btnExit = new javax.swing.JButton();
  52. btnLaunchGame = new javax.swing.JButton();
  53. jScrollPane1 = new javax.swing.JScrollPane();
  54. jTextArea1 = new javax.swing.JTextArea();
  55. cmbSelectGame = new javax.swing.JComboBox<>();
  56. lblSelectGame = new javax.swing.JLabel();
  57. btnControls = new javax.swing.JButton();
  58.  
  59. setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
  60. setTitle("SCCC Game Library");
  61.  
  62. lblTitle.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
  63. lblTitle.setText("1LT(P) Foley Bored in SCCC Game Library");
  64.  
  65. btnExit.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
  66. btnExit.setText("Exit");
  67. btnExit.setMaximumSize(new java.awt.Dimension(101, 23));
  68. btnExit.setMinimumSize(new java.awt.Dimension(101, 23));
  69. btnExit.setPreferredSize(new java.awt.Dimension(101, 23));
  70. btnExit.addActionListener(new java.awt.event.ActionListener() {
  71. public void actionPerformed(java.awt.event.ActionEvent evt) {
  72. btnExitActionPerformed(evt);
  73. }
  74. });
  75.  
  76. btnLaunchGame.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
  77. btnLaunchGame.setText("Launch Game");
  78. btnLaunchGame.setMaximumSize(new java.awt.Dimension(101, 23));
  79. btnLaunchGame.setMinimumSize(new java.awt.Dimension(101, 23));
  80. btnLaunchGame.setPreferredSize(new java.awt.Dimension(101, 23));
  81. btnLaunchGame.addActionListener(new java.awt.event.ActionListener() {
  82. public void actionPerformed(java.awt.event.ActionEvent evt) {
  83. btnLaunchGameActionPerformed(evt);
  84. }
  85. });
  86.  
  87. jTextArea1.setEditable(false);
  88. jTextArea1.setColumns(20);
  89. jTextArea1.setFont(new java.awt.Font("Arial", 0, 13)); // NOI18N
  90. jTextArea1.setLineWrap(true);
  91. jTextArea1.setRows(5);
  92. jTextArea1.setWrapStyleWord(true);
  93. jScrollPane1.setViewportView(jTextArea1);
  94.  
  95. cmbSelectGame.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Foley Ball", "Rock Dodger", "Space Banditos", "Moon RANGER!" }));
  96. cmbSelectGame.addActionListener(new java.awt.event.ActionListener() {
  97. public void actionPerformed(java.awt.event.ActionEvent evt) {
  98. cmbSelectGameActionPerformed(evt);
  99. }
  100. });
  101.  
  102. lblSelectGame.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
  103. lblSelectGame.setText("Select Game: ");
  104.  
  105. btnControls.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
  106. btnControls.setText("View Controls");
  107. btnControls.addActionListener(new java.awt.event.ActionListener() {
  108. public void actionPerformed(java.awt.event.ActionEvent evt) {
  109. btnControlsActionPerformed(evt);
  110. }
  111. });
  112.  
  113. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  114. getContentPane().setLayout(layout);
  115. layout.setHorizontalGroup(
  116. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  117. .addGroup(layout.createSequentialGroup()
  118. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  119. .addGroup(layout.createSequentialGroup()
  120. .addContainerGap()
  121. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
  122. .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING)
  123. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  124. .addGroup(layout.createSequentialGroup()
  125. .addGap(58, 58, 58)
  126. .addComponent(lblSelectGame)
  127. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  128. .addComponent(cmbSelectGame, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  129. .addGroup(layout.createSequentialGroup()
  130. .addComponent(btnControls)
  131. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  132. .addComponent(btnLaunchGame, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  133. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  134. .addComponent(btnExit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
  135. .addGroup(layout.createSequentialGroup()
  136. .addGap(23, 23, 23)
  137. .addComponent(lblTitle)))
  138. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  139. );
  140. layout.setVerticalGroup(
  141. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  142. .addGroup(layout.createSequentialGroup()
  143. .addContainerGap()
  144. .addComponent(lblTitle)
  145. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  146. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
  147. .addComponent(lblSelectGame)
  148. .addComponent(cmbSelectGame, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  149. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  150. .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  151. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  152. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  153. .addComponent(btnLaunchGame, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  154. .addComponent(btnExit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  155. .addComponent(btnControls))
  156. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  157. );
  158.  
  159. pack();
  160. }// </editor-fold>
  161.  
  162. private void cmbSelectGameActionPerformed(java.awt.event.ActionEvent evt) {
  163. // TODO add your handling code here:
  164. jTextArea1.setText(gameDescriptions[cmbSelectGame.getSelectedIndex()]);;
  165. }
  166.  
  167. private void btnExitActionPerformed(java.awt.event.ActionEvent evt) {
  168. // TODO add your handling code here:
  169. System.exit(0);
  170. }
  171.  
  172. private void btnLaunchGameActionPerformed(java.awt.event.ActionEvent evt) {
  173. // TODO add your handling code here:
  174. int game = cmbSelectGame.getSelectedIndex();
  175. switch(game)
  176. {
  177. case 0:
  178. String name1 = JOptionPane.showInputDialog(this, "Enter Player 1's name or \'quit\' to cancel");
  179. if(name1.equalsIgnoreCase("QUIT"))
  180. {
  181. break;
  182. }
  183. String name2 = JOptionPane.showInputDialog(this, "Enter Player 2's name or \'quit\' to cancel");
  184. if(name2.equalsIgnoreCase("QUIT"))
  185. {
  186. break;
  187. }
  188. SwingUtilities.invokeLater(new Runnable()
  189. {
  190. public void run()
  191. {
  192. new Ball(name1, name2).setVisible(true);
  193. }
  194. });
  195. break;
  196. case 1:
  197. JOptionPane.showConfirmDialog(this, "Playing Rock Dodger");
  198. break;
  199. case 2:
  200. JOptionPane.showMessageDialog(this, "Space Banditos is not yet finished. Stay tuned");
  201. break;
  202. case 3:
  203. JOptionPane.showMessageDialog(this, "Moon RANGER! is not yet finished. Stay tuned");
  204. break;
  205. default:
  206. break;
  207. }
  208. }
  209.  
  210. private void btnControlsActionPerformed(java.awt.event.ActionEvent evt) {
  211. // TODO add your handling code here:
  212. int game = cmbSelectGame.getSelectedIndex();
  213. switch(game)
  214. {
  215. case 0:
  216. JOptionPane.showMessageDialog(this, "Player 1 uses \'W\' and \'X\' to move up and down" +
  217. "\nPlayer 2 uses \'NUMPAD9\' and \'NUMPAD3\' to move up and down");
  218. break;
  219. case 1:
  220. JOptionPane.showMessageDialog(this, "Player 1 uses \'W\' and \'S\' to move up and down," +
  221. "\nand \'A\' and \'D\' to move left and right");
  222. break;
  223. case 2:
  224. JOptionPane.showMessageDialog(this, "Players use \'W\' and \'S\' to move up and down," +
  225. "\n\'A\' and \'D\' to move left and right," +
  226. "\nand \'SPACE\' to fire their laser cannon");
  227. break;
  228. case 3:
  229. JOptionPane.showMessageDialog(this, "Player 1 uses \'A\' and \'D\' to move left and right," +
  230. "\n\'ENTER\' to jump, and \'SPACE\' to fire their laser rifle");
  231. break;
  232. default:
  233. break;
  234. }
  235. }
  236.  
  237. private void populateGameDescriptions()
  238. {
  239. gameDescriptions = new String[]{"Rebound Ball is a Pong clone that lets two people play against each other on the same machine",
  240. "Rock Dodger puts the player in control of a spaceship in an asteroid field. Survive for as long as you can",
  241. "Space Banditos puts 2 gringos head-to-head in vicious space combat across a local network",
  242. "Moon RANGER! puts you in control of a Soldier with nothing to lose. Survive for as long as possible"};
  243. }
  244.  
  245. /**
  246. * @param args the command line arguments
  247. */
  248. public static void main(String args[]) {
  249. /* Set the Nimbus look and feel */
  250. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  251. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  252. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  253. */
  254. //try {
  255. // for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  256. // if ("Nimbus".equals(info.getName())) {
  257. // javax.swing.UIManager.setLookAndFeel(info.getClassName());
  258. // break;
  259. // }
  260. // }
  261. //} catch (ClassNotFoundException ex) {
  262. // java.util.logging.Logger.getLogger(GUIDriver.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  263. //} catch (InstantiationException ex) {
  264. // java.util.logging.Logger.getLogger(GUIDriver.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  265. //} catch (IllegalAccessException ex) {
  266. // java.util.logging.Logger.getLogger(GUIDriver.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  267. //} catch (javax.swing.UnsupportedLookAndFeelException ex) {
  268. // java.util.logging.Logger.getLogger(GUIDriver.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  269. //}
  270. //</editor-fold>
  271.  
  272. /* Create and display the form */
  273. SwingUtilities.invokeLater(new Runnable()
  274. {
  275. public void run()
  276. {
  277. new GUIDriver().setVisible(true);
  278. }
  279. });
  280. }
  281.  
  282. // Variables declaration - do not modify
  283. private javax.swing.JButton btnControls;
  284. private javax.swing.JButton btnExit;
  285. private javax.swing.JButton btnLaunchGame;
  286. private javax.swing.JComboBox<String> cmbSelectGame;
  287. private javax.swing.JScrollPane jScrollPane1;
  288. private javax.swing.JTextArea jTextArea1;
  289. private javax.swing.JLabel lblSelectGame;
  290. private javax.swing.JLabel lblTitle;
  291. // End of variables declaration
  292. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement