Advertisement
Crenox

Final Exam: Name That Tune!

May 23rd, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.32 KB | None | 0 0
  1. -----------------------------------------------------------------------------------------------------------------------------------
  2. // Name That Tune!
  3. // Description: This class is the GUI part of the program.
  4. // Sammy Samkough
  5.  
  6. import java.awt.*;
  7. import java.awt.event.*;
  8. import javax.swing.*;
  9.  
  10. public class NameThatTuneGUI extends JFrame
  11. {
  12. // size of screen
  13. public static final int WIDTH = 400;
  14. public static final int HEIGHT = 500;
  15.  
  16. // title
  17. public static final String text = "MALLIKATRON NAME THAT TUNE!";
  18. private JLabel title;
  19.  
  20. /* Buttons Include: 1) Start 2) About
  21. Start - starts the game
  22. About - includes the game layout, how it works, and the people behind the project
  23. */
  24. private JButton startB, aboutB, exitB;
  25.  
  26. // layout
  27. private FlowLayout layout = new FlowLayout(FlowLayout.LEFT, 50, 50);
  28.  
  29. public NameThatTuneGUI()
  30. {
  31. // this is for the space between the buttons as well
  32. this.setLayout(new FlowLayout(FlowLayout.LEFT, 50, 50));
  33.  
  34. // buttons
  35. startB = new JButton("START");
  36. startB.setPreferredSize(new Dimension(300, 50));
  37.  
  38. aboutB = new JButton("ABOUT");
  39. aboutB.setPreferredSize(new Dimension(300, 50));
  40.  
  41. exitB = new JButton("EXIT");
  42. exitB.setPreferredSize(new Dimension(300, 50));
  43. if(exitB.getModel().isPressed())
  44. {
  45. int confirm = JOptionPane.showOptionDialog(null, "Are You Sure to Close Application?", "Exit Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
  46.  
  47. if (confirm == 0)
  48. {
  49. System.exit(0);
  50. }
  51. }
  52.  
  53. // labels
  54. title = new JLabel(text);
  55. title.setFont(title.getFont().deriveFont(24.0f));
  56.  
  57. // additions
  58. add(title);
  59. add(startB);
  60. add(aboutB);
  61. add(exitB);
  62.  
  63. // listeners
  64. event e1 = new event();
  65. startB.addActionListener(e1);
  66.  
  67. event2 e2 = new event2();
  68. aboutB.addActionListener(e2);
  69.  
  70. event3 e3 = new event3();
  71. exitB.addActionListener(e3);
  72.  
  73. addWindowListener(exitListener);
  74. }
  75.  
  76. WindowListener exitListener = new WindowAdapter()
  77. {
  78. @Override
  79. public void windowClosing(WindowEvent e)
  80. {
  81. int confirm = JOptionPane.showOptionDialog(null, "Are you sure you want to close application?", "Exit Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
  82.  
  83. if (confirm == 0)
  84. {
  85. System.exit(0);
  86. }
  87. }
  88. };
  89.  
  90. public class event implements ActionListener
  91. {
  92. public void actionPerformed(ActionEvent e)
  93. {
  94. NameThatTuneGuiStart gui = new NameThatTuneGuiStart();
  95.  
  96. gui.setTitle("Name That Tune!");
  97. gui.setSize(gui.WIDTH, gui.HEIGHT);
  98. gui.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
  99. gui.setLocationRelativeTo(null);
  100. gui.setVisible(true);
  101. gui.getContentPane().setBackground(new Color(255, 178, 108));
  102.  
  103. dispose();
  104. }
  105. }
  106.  
  107. public class event2 implements ActionListener
  108. {
  109. public void actionPerformed(ActionEvent e)
  110. {
  111. NameThatTuneGuiAbout gui = new NameThatTuneGuiAbout();
  112.  
  113. gui.setTitle("About");
  114. gui.setSize(gui.WIDTH, gui.HEIGHT);
  115. gui.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
  116. gui.setLocationRelativeTo(null);
  117. gui.setVisible(true);
  118. gui.setContentPane(new JLabel(new ImageIcon("res/about.png")));
  119. }
  120. }
  121.  
  122. public class event3 implements ActionListener
  123. {
  124. public void actionPerformed(ActionEvent e)
  125. {
  126. int confirm = JOptionPane.showOptionDialog(null, "Are you sure you want to close application?", "Exit Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
  127.  
  128. if (confirm == 0)
  129. {
  130. dispose();
  131. System.exit(0);
  132. }
  133. else
  134. {
  135. // continue
  136. }
  137. }
  138. }
  139.  
  140. public static void main (String args[])
  141. {
  142. NameThatTuneGUI frame = new NameThatTuneGUI();
  143.  
  144. frame.setTitle("Main Menu");
  145. frame.setSize(WIDTH, HEIGHT);
  146. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  147. frame.setLocationRelativeTo(null);
  148. frame.setVisible(true);
  149. frame.getContentPane().setBackground(new Color(255, 178, 108));
  150. }
  151. }
  152. -----------------------------------------------------------------------------------------------------------------------------------
  153. // Name That Tune!
  154. // Description: This class is the GUI part of the program.
  155. // Sammy Samkough
  156.  
  157. import java.awt.*;
  158. import java.awt.event.*;
  159. import javax.swing.*;
  160.  
  161. public class NameThatTuneGuiStart extends JFrame
  162. {
  163. // size of screen
  164. public static final int WIDTH = 900;
  165. public static final int HEIGHT = 900;
  166.  
  167. public NameThatTuneGuiStart()
  168. {
  169. setLayout(new FlowLayout());
  170. setSize(WIDTH, HEIGHT);
  171. getContentPane().setBackground(new Color(255, 178, 108));
  172.  
  173. addWindowListener(exitListener);
  174. }
  175.  
  176. WindowListener exitListener = new WindowAdapter()
  177. {
  178. @Override
  179. public void windowClosing(WindowEvent e)
  180. {
  181. NameThatTuneGUI frame = new NameThatTuneGUI();
  182.  
  183. frame.setTitle("Main Menu");
  184. frame.setSize(frame.WIDTH, frame.HEIGHT);
  185. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  186. frame.setLocationRelativeTo(null);
  187. frame.setVisible(true);
  188. frame.getContentPane().setBackground(new Color(255, 178, 108));
  189.  
  190. dispose();
  191. }
  192. };
  193.  
  194. public static void main (String args[])
  195. {
  196.  
  197. }
  198. }
  199. -----------------------------------------------------------------------------------------------------------------------------------
  200. // Name That Tune!
  201. // Description: This class is the GUI part of the program.
  202. // Sammy Samkough
  203.  
  204. import java.awt.*;
  205. import java.awt.event.*;
  206. import javax.swing.*;
  207.  
  208. public class NameThatTuneGuiAbout extends JFrame
  209. {
  210. // size of screen
  211. public static final int WIDTH = 600;
  212. public static final int HEIGHT = 600;
  213.  
  214. public NameThatTuneGuiAbout()
  215. {
  216. setLayout(new FlowLayout());
  217.  
  218. // listeners
  219. addWindowListener(exitListener);
  220. }
  221.  
  222. WindowListener exitListener = new WindowAdapter()
  223. {
  224. @Override
  225. public void windowClosing(WindowEvent e)
  226. {
  227. NameThatTuneGUI frame = new NameThatTuneGUI();
  228.  
  229. frame.setTitle("Main Menu");
  230. frame.setSize(frame.WIDTH, frame.HEIGHT);
  231. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  232. frame.setLocationRelativeTo(null);
  233. frame.setVisible(true);
  234. frame.getContentPane().setBackground(new Color(255, 178, 108));
  235.  
  236. dispose();
  237. }
  238. };
  239.  
  240. public static void main (String args[])
  241. {
  242.  
  243. }
  244. }
  245. -----------------------------------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement