Advertisement
Guest User

Colin Jeffer - Final Project Code so far

a guest
Apr 26th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.02 KB | None | 0 0
  1.  
  2.  
  3. import java.awt.Dimension;
  4. import java.awt.Font;
  5. import java.awt.GridLayout;
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.ActionListener;
  8. import java.awt.event.ItemEvent;
  9. import java.awt.event.ItemListener;
  10. import java.awt.event.KeyEvent;
  11.  
  12. import javax.swing.*;
  13.  
  14.  
  15.  
  16.  
  17. public class FinalProject extends JFrame {
  18.  
  19.  
  20. private JMenuBar menuBar; //right below the title bar
  21. private JMenu selectionMenu;
  22.  
  23. private JMenu gameMenu;
  24. private JMenu foodMenu;
  25. private JMenu bookMenu;
  26.  
  27. private JMenuItem exitItem;
  28.  
  29. private JCheckBoxMenuItem gameStoreOption;
  30. private JCheckBoxMenuItem foodStoreOption;
  31. private JCheckBoxMenuItem bookStoreOption;
  32.  
  33. //labels
  34. private JLabel label;
  35. private JLabel gamesLabel;
  36. private JLabel foodsLabel;
  37. private JLabel booksLabel;
  38.  
  39.  
  40. //games
  41. private JRadioButtonMenuItem mortalKombat11;
  42. private JRadioButtonMenuItem smashBrosUltimate;
  43. private JRadioButtonMenuItem rocketLeague;
  44. private ButtonGroup gameGroup;
  45.  
  46.  
  47. //foods
  48. private JRadioButtonMenuItem hamburger;
  49. private JRadioButtonMenuItem hotdog;
  50. private JRadioButtonMenuItem salad;
  51. private ButtonGroup foodGroup;
  52.  
  53. //books
  54. private JRadioButtonMenuItem harryPotter;
  55. private JRadioButtonMenuItem hungerGames;
  56. private JRadioButtonMenuItem textbook;
  57. private ButtonGroup booksGroup;
  58.  
  59. //costs
  60. private double mk11Cost = 60;
  61. private double smashUltimateCost = 60;
  62. private double rocketLeagueCost = 20;
  63.  
  64. private double hamburgerCost = 5;
  65. private double hotdogCost = 4;
  66. private double saladCost = 6;
  67.  
  68. private double harryPotterCost = 60;
  69. private double hungerGamesCost = 30;
  70. private double textbookCost = 500;
  71.  
  72.  
  73.  
  74.  
  75. public FinalProject() {
  76.  
  77. label = new JLabel("Welcome to the Open Beta of the Create-a-Store 9000! Please choose which items you'd like to add to your stock!");
  78. label.setFont(new Font("Courier New", Font.PLAIN, 20));
  79. setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);
  80.  
  81. gamesLabel = new JLabel("");
  82. gamesLabel.setFont(new Font("Courier New", Font.PLAIN, 25));
  83.  
  84. foodsLabel = new JLabel("");
  85. foodsLabel.setFont(new Font("Courier New", Font.PLAIN, 25));
  86.  
  87. booksLabel = new JLabel("");
  88. booksLabel.setFont(new Font("Courier New", Font.PLAIN, 25));
  89.  
  90. label.setSize(1920,1080);
  91.  
  92. setLayout(new GridLayout(10, 5));
  93.  
  94. add(label);
  95. add(gamesLabel);
  96. add(foodsLabel);
  97. add(booksLabel);
  98.  
  99.  
  100. buildMenuBar();
  101.  
  102.  
  103. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  104. setLocationRelativeTo(null);
  105. setVisible(true);
  106.  
  107. }
  108.  
  109. private void buildMenuBar() {
  110.  
  111. menuBar = new JMenuBar();
  112. buildFileMenu();
  113. menuBar.add(selectionMenu);
  114. exitItem = new JMenuItem("Exit");
  115. exitItem.setFont(new Font("Garamond", Font.PLAIN, 30));
  116. exitItem.setMnemonic(KeyEvent.VK_X);
  117. exitItem.addActionListener(new ExitButtonListener());
  118. menuBar.add(exitItem);
  119. setJMenuBar(menuBar);
  120.  
  121. }
  122.  
  123. //Selection Menu
  124. private void buildFileMenu() {
  125.  
  126. selectionMenu = new JMenu("Select Here");
  127. selectionMenu.setFont(new Font("Garamond", Font.PLAIN, 30));
  128. selectionMenu.setMnemonic(KeyEvent.VK_S);
  129.  
  130. buildGamesMenu();
  131. selectionMenu.add(gameMenu);
  132.  
  133. gameStoreOption = new JCheckBoxMenuItem("Game Store");
  134. gameStoreOption.setFont(new Font("Times New Roman", Font.BOLD, 24));
  135.  
  136. foodStoreOption = new JCheckBoxMenuItem("Restaurant");
  137. foodStoreOption.setFont(new Font("Times New Roman", Font.BOLD, 24));
  138.  
  139. bookStoreOption = new JCheckBoxMenuItem("Book Store");
  140. bookStoreOption.setFont(new Font("Times New Roman", Font.BOLD, 24));
  141.  
  142. gameStoreOption.addItemListener(new CheckBoxListener());
  143. foodStoreOption.addItemListener(new CheckBoxListener());
  144. bookStoreOption.addItemListener(new CheckBoxListener());
  145.  
  146. buildFoodsMenu();
  147. selectionMenu.add(foodMenu);
  148.  
  149. buildBooksMenu();
  150. selectionMenu.add(bookMenu);
  151.  
  152. selectionMenu.add(gameStoreOption);
  153. selectionMenu.add(foodStoreOption);
  154. selectionMenu.add(bookStoreOption);
  155. }
  156.  
  157. //Games Menu
  158. private void buildGamesMenu() {
  159.  
  160. gameMenu = new JMenu("Game Store Options");
  161. gameMenu.setFont(new Font("Serif", Font.PLAIN, 30));
  162.  
  163. gameGroup = new ButtonGroup();
  164. mortalKombat11 = new JRadioButtonMenuItem("Mortal Kombat 11");
  165. mortalKombat11.setFont(new Font("Helvetica", Font.PLAIN, 24));
  166.  
  167. smashBrosUltimate = new JRadioButtonMenuItem("Super Smash Bros. Ultimate");
  168. smashBrosUltimate.setFont(new Font("Helvetica", Font.PLAIN, 24));
  169.  
  170. rocketLeague = new JRadioButtonMenuItem("Rocket League");
  171. rocketLeague.setFont(new Font("Helvetica", Font.PLAIN, 24));
  172.  
  173.  
  174.  
  175. gameGroup.add(mortalKombat11);
  176. gameGroup.add(smashBrosUltimate);
  177. gameGroup.add(rocketLeague);
  178.  
  179. gameMenu.add(mortalKombat11);
  180. gameMenu.add(smashBrosUltimate);
  181. gameMenu.add(rocketLeague);
  182.  
  183. mortalKombat11.addActionListener(new RadioButtonListener());
  184. smashBrosUltimate.addActionListener(new RadioButtonListener());
  185. rocketLeague.addActionListener(new RadioButtonListener());
  186.  
  187. gameMenu.setVisible(false);
  188.  
  189. }
  190.  
  191. //Foods Menu
  192. private void buildFoodsMenu() {
  193.  
  194. foodMenu = new JMenu("Restaurant Options");
  195. foodMenu.setFont(new Font("Serif", Font.PLAIN, 30));
  196.  
  197. hamburger = new JRadioButtonMenuItem("Hamburger");
  198. hamburger.setFont(new Font("Helvetica", Font.PLAIN, 24));
  199.  
  200. hotdog = new JRadioButtonMenuItem("Hot Dog");
  201. hotdog.setFont(new Font("Helvetica", Font.PLAIN, 24));
  202.  
  203. salad = new JRadioButtonMenuItem("Salad");
  204. salad.setFont(new Font("Helvetica", Font.PLAIN, 24));
  205.  
  206. foodGroup = new ButtonGroup();
  207. foodGroup.add(hamburger);
  208. foodGroup.add(hotdog);
  209. foodGroup.add(salad);
  210.  
  211. foodMenu.add(hamburger);
  212. foodMenu.add(hotdog);
  213. foodMenu.add(salad);
  214.  
  215. hamburger.addActionListener(new RadioButtonListener());
  216. hotdog.addActionListener(new RadioButtonListener());
  217. salad.addActionListener(new RadioButtonListener());
  218.  
  219. foodMenu.setVisible(false);
  220.  
  221. }
  222.  
  223. //books menu
  224. private void buildBooksMenu() {
  225.  
  226. bookMenu = new JMenu("Book Store Options");
  227. bookMenu.setFont(new Font("Serif", Font.PLAIN, 30));
  228.  
  229. booksGroup = new ButtonGroup();
  230. harryPotter = new JRadioButtonMenuItem("Harry Potter Series");
  231. harryPotter.setFont(new Font("Helvetica", Font.PLAIN, 24));
  232.  
  233. hungerGames = new JRadioButtonMenuItem("The Hunger Games Series");
  234. hungerGames.setFont(new Font("Helvetica", Font.PLAIN, 24));
  235.  
  236. textbook = new JRadioButtonMenuItem("Any Textbook");
  237. textbook.setFont(new Font("Helvetica", Font.PLAIN, 24));
  238.  
  239.  
  240.  
  241. booksGroup.add(harryPotter);
  242. booksGroup.add(hungerGames);
  243. booksGroup.add(textbook);
  244.  
  245. bookMenu.add(harryPotter);
  246. bookMenu.add(hungerGames);
  247. bookMenu.add(textbook);
  248.  
  249. harryPotter.addActionListener(new RadioButtonListener());
  250. hungerGames.addActionListener(new RadioButtonListener());
  251. textbook.addActionListener(new RadioButtonListener());
  252.  
  253. bookMenu.setVisible(false);
  254.  
  255. }
  256.  
  257. private class ExitButtonListener implements ActionListener {
  258. @Override
  259. public void actionPerformed(ActionEvent e) {
  260. System.exit(0);
  261. }
  262. }
  263.  
  264.  
  265. private class RadioButtonListener implements ActionListener {
  266.  
  267. @Override
  268. public void actionPerformed(ActionEvent e) {
  269.  
  270. if (e.getSource() == mortalKombat11) {
  271. gamesLabel.setText(gamesLabel.getText() + "\n\n Mortal Kombat 11: $" + mk11Cost );
  272. }
  273. else if (e.getSource() == smashBrosUltimate) {
  274. gamesLabel.setText(gamesLabel.getText() + "\n\n Super Smash Brothers Ultimate: $" + smashUltimateCost );
  275. }
  276. else if (e.getSource() == rocketLeague) {
  277. gamesLabel.setText(gamesLabel.getText() + "\n\n Rocket League: $" + rocketLeagueCost);
  278. }
  279.  
  280. if (e.getSource() == hamburger) {
  281. foodsLabel.setText(foodsLabel.getText() + "\n\n Hamburger: $" + hamburgerCost);
  282. }
  283. else if (e.getSource() == hotdog) {
  284. foodsLabel.setText(foodsLabel.getText() + "\n\n Hot Dog: $" + hotdogCost);
  285. }
  286. else if (e.getSource() == salad) {
  287. foodsLabel.setText(foodsLabel.getText() + "\n\n Salad: $" + saladCost);
  288. }
  289.  
  290. if (e.getSource() == harryPotter) {
  291. booksLabel.setText(booksLabel.getText() + "\n\n Harry Potter Series: $" + harryPotterCost);
  292. }
  293. else if (e.getSource() == hungerGames) {
  294. booksLabel.setText(booksLabel.getText() + "\n\n Hunger Games Series: $" + hungerGamesCost);
  295. }
  296. else if (e.getSource() == textbook) {
  297. booksLabel.setText(booksLabel.getText() + "\n\n Any Textbook: $" + textbookCost);
  298. }
  299.  
  300.  
  301. }
  302.  
  303. }
  304.  
  305.  
  306. private class CheckBoxListener implements ItemListener {
  307.  
  308. @Override
  309. public void itemStateChanged(ItemEvent e) {
  310.  
  311. if (gameStoreOption.isSelected()) {
  312. gameStoreOption.setSelected(true);
  313. gameMenu.setVisible(true);
  314. foodMenu.setVisible(false);
  315. bookMenu.setVisible(false);
  316. foodStoreOption.setSelected(false);
  317. bookStoreOption.setSelected(false);
  318.  
  319. }
  320. else if (foodStoreOption.isSelected()) {
  321. foodStoreOption.setSelected(true);
  322. foodMenu.setVisible(true);
  323. gameMenu.setVisible(false);
  324. bookMenu.setVisible(false);
  325. bookStoreOption.setSelected(false);
  326. gameStoreOption.setSelected(false);
  327. }
  328. else if (bookStoreOption.isSelected()) {
  329. bookStoreOption.setSelected(true);
  330. foodMenu.setVisible(false);
  331. gameMenu.setVisible(false);
  332. bookMenu.setVisible(true);
  333. foodStoreOption.setSelected(false);
  334. gameStoreOption.setSelected(false);
  335. }
  336. else if (foodStoreOption.isSelected() && gameStoreOption.isSelected() && bookStoreOption.isSelected()) {
  337. gameMenu.setVisible(false);
  338. foodMenu.setVisible(false);
  339. bookMenu.setVisible(false);
  340. foodStoreOption.setSelected(false);
  341. bookStoreOption.setSelected(false);
  342. gameStoreOption.setSelected(false);
  343. }
  344. else {
  345. foodMenu.setVisible(false);
  346. gameMenu.setVisible(false);
  347. bookMenu.setVisible(false);
  348. foodStoreOption.setSelected(false);
  349. bookStoreOption.setSelected(false);
  350. gameStoreOption.setSelected(false);
  351. }
  352.  
  353.  
  354. }
  355.  
  356. }
  357.  
  358.  
  359. public static void main(String[] args) {
  360. new FinalProject();
  361. }
  362. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement