Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Dimension;
- import java.awt.Font;
- import java.awt.GridLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.ItemEvent;
- import java.awt.event.ItemListener;
- import java.awt.event.KeyEvent;
- import javax.swing.*;
- public class FinalProject extends JFrame {
- private JMenuBar menuBar; //right below the title bar
- private JMenu selectionMenu;
- private JMenu gameMenu;
- private JMenu foodMenu;
- private JMenu bookMenu;
- private JMenuItem exitItem;
- private JCheckBoxMenuItem gameStoreOption;
- private JCheckBoxMenuItem foodStoreOption;
- private JCheckBoxMenuItem bookStoreOption;
- //labels
- private JLabel label;
- private JLabel gamesLabel;
- private JLabel foodsLabel;
- private JLabel booksLabel;
- //games
- private JRadioButtonMenuItem mortalKombat11;
- private JRadioButtonMenuItem smashBrosUltimate;
- private JRadioButtonMenuItem rocketLeague;
- private ButtonGroup gameGroup;
- //foods
- private JRadioButtonMenuItem hamburger;
- private JRadioButtonMenuItem hotdog;
- private JRadioButtonMenuItem salad;
- private ButtonGroup foodGroup;
- //books
- private JRadioButtonMenuItem harryPotter;
- private JRadioButtonMenuItem hungerGames;
- private JRadioButtonMenuItem textbook;
- private ButtonGroup booksGroup;
- //costs
- private double mk11Cost = 60;
- private double smashUltimateCost = 60;
- private double rocketLeagueCost = 20;
- private double hamburgerCost = 5;
- private double hotdogCost = 4;
- private double saladCost = 6;
- private double harryPotterCost = 60;
- private double hungerGamesCost = 30;
- private double textbookCost = 500;
- public FinalProject() {
- 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!");
- label.setFont(new Font("Courier New", Font.PLAIN, 20));
- setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);
- gamesLabel = new JLabel("");
- gamesLabel.setFont(new Font("Courier New", Font.PLAIN, 25));
- foodsLabel = new JLabel("");
- foodsLabel.setFont(new Font("Courier New", Font.PLAIN, 25));
- booksLabel = new JLabel("");
- booksLabel.setFont(new Font("Courier New", Font.PLAIN, 25));
- label.setSize(1920,1080);
- setLayout(new GridLayout(10, 5));
- add(label);
- add(gamesLabel);
- add(foodsLabel);
- add(booksLabel);
- buildMenuBar();
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setLocationRelativeTo(null);
- setVisible(true);
- }
- private void buildMenuBar() {
- menuBar = new JMenuBar();
- buildFileMenu();
- menuBar.add(selectionMenu);
- exitItem = new JMenuItem("Exit");
- exitItem.setFont(new Font("Garamond", Font.PLAIN, 30));
- exitItem.setMnemonic(KeyEvent.VK_X);
- exitItem.addActionListener(new ExitButtonListener());
- menuBar.add(exitItem);
- setJMenuBar(menuBar);
- }
- //Selection Menu
- private void buildFileMenu() {
- selectionMenu = new JMenu("Select Here");
- selectionMenu.setFont(new Font("Garamond", Font.PLAIN, 30));
- selectionMenu.setMnemonic(KeyEvent.VK_S);
- buildGamesMenu();
- selectionMenu.add(gameMenu);
- gameStoreOption = new JCheckBoxMenuItem("Game Store");
- gameStoreOption.setFont(new Font("Times New Roman", Font.BOLD, 24));
- foodStoreOption = new JCheckBoxMenuItem("Restaurant");
- foodStoreOption.setFont(new Font("Times New Roman", Font.BOLD, 24));
- bookStoreOption = new JCheckBoxMenuItem("Book Store");
- bookStoreOption.setFont(new Font("Times New Roman", Font.BOLD, 24));
- gameStoreOption.addItemListener(new CheckBoxListener());
- foodStoreOption.addItemListener(new CheckBoxListener());
- bookStoreOption.addItemListener(new CheckBoxListener());
- buildFoodsMenu();
- selectionMenu.add(foodMenu);
- buildBooksMenu();
- selectionMenu.add(bookMenu);
- selectionMenu.add(gameStoreOption);
- selectionMenu.add(foodStoreOption);
- selectionMenu.add(bookStoreOption);
- }
- //Games Menu
- private void buildGamesMenu() {
- gameMenu = new JMenu("Game Store Options");
- gameMenu.setFont(new Font("Serif", Font.PLAIN, 30));
- gameGroup = new ButtonGroup();
- mortalKombat11 = new JRadioButtonMenuItem("Mortal Kombat 11");
- mortalKombat11.setFont(new Font("Helvetica", Font.PLAIN, 24));
- smashBrosUltimate = new JRadioButtonMenuItem("Super Smash Bros. Ultimate");
- smashBrosUltimate.setFont(new Font("Helvetica", Font.PLAIN, 24));
- rocketLeague = new JRadioButtonMenuItem("Rocket League");
- rocketLeague.setFont(new Font("Helvetica", Font.PLAIN, 24));
- gameGroup.add(mortalKombat11);
- gameGroup.add(smashBrosUltimate);
- gameGroup.add(rocketLeague);
- gameMenu.add(mortalKombat11);
- gameMenu.add(smashBrosUltimate);
- gameMenu.add(rocketLeague);
- mortalKombat11.addActionListener(new RadioButtonListener());
- smashBrosUltimate.addActionListener(new RadioButtonListener());
- rocketLeague.addActionListener(new RadioButtonListener());
- gameMenu.setVisible(false);
- }
- //Foods Menu
- private void buildFoodsMenu() {
- foodMenu = new JMenu("Restaurant Options");
- foodMenu.setFont(new Font("Serif", Font.PLAIN, 30));
- hamburger = new JRadioButtonMenuItem("Hamburger");
- hamburger.setFont(new Font("Helvetica", Font.PLAIN, 24));
- hotdog = new JRadioButtonMenuItem("Hot Dog");
- hotdog.setFont(new Font("Helvetica", Font.PLAIN, 24));
- salad = new JRadioButtonMenuItem("Salad");
- salad.setFont(new Font("Helvetica", Font.PLAIN, 24));
- foodGroup = new ButtonGroup();
- foodGroup.add(hamburger);
- foodGroup.add(hotdog);
- foodGroup.add(salad);
- foodMenu.add(hamburger);
- foodMenu.add(hotdog);
- foodMenu.add(salad);
- hamburger.addActionListener(new RadioButtonListener());
- hotdog.addActionListener(new RadioButtonListener());
- salad.addActionListener(new RadioButtonListener());
- foodMenu.setVisible(false);
- }
- //books menu
- private void buildBooksMenu() {
- bookMenu = new JMenu("Book Store Options");
- bookMenu.setFont(new Font("Serif", Font.PLAIN, 30));
- booksGroup = new ButtonGroup();
- harryPotter = new JRadioButtonMenuItem("Harry Potter Series");
- harryPotter.setFont(new Font("Helvetica", Font.PLAIN, 24));
- hungerGames = new JRadioButtonMenuItem("The Hunger Games Series");
- hungerGames.setFont(new Font("Helvetica", Font.PLAIN, 24));
- textbook = new JRadioButtonMenuItem("Any Textbook");
- textbook.setFont(new Font("Helvetica", Font.PLAIN, 24));
- booksGroup.add(harryPotter);
- booksGroup.add(hungerGames);
- booksGroup.add(textbook);
- bookMenu.add(harryPotter);
- bookMenu.add(hungerGames);
- bookMenu.add(textbook);
- harryPotter.addActionListener(new RadioButtonListener());
- hungerGames.addActionListener(new RadioButtonListener());
- textbook.addActionListener(new RadioButtonListener());
- bookMenu.setVisible(false);
- }
- private class ExitButtonListener implements ActionListener {
- @Override
- public void actionPerformed(ActionEvent e) {
- System.exit(0);
- }
- }
- private class RadioButtonListener implements ActionListener {
- @Override
- public void actionPerformed(ActionEvent e) {
- if (e.getSource() == mortalKombat11) {
- gamesLabel.setText(gamesLabel.getText() + "\n\n Mortal Kombat 11: $" + mk11Cost );
- }
- else if (e.getSource() == smashBrosUltimate) {
- gamesLabel.setText(gamesLabel.getText() + "\n\n Super Smash Brothers Ultimate: $" + smashUltimateCost );
- }
- else if (e.getSource() == rocketLeague) {
- gamesLabel.setText(gamesLabel.getText() + "\n\n Rocket League: $" + rocketLeagueCost);
- }
- if (e.getSource() == hamburger) {
- foodsLabel.setText(foodsLabel.getText() + "\n\n Hamburger: $" + hamburgerCost);
- }
- else if (e.getSource() == hotdog) {
- foodsLabel.setText(foodsLabel.getText() + "\n\n Hot Dog: $" + hotdogCost);
- }
- else if (e.getSource() == salad) {
- foodsLabel.setText(foodsLabel.getText() + "\n\n Salad: $" + saladCost);
- }
- if (e.getSource() == harryPotter) {
- booksLabel.setText(booksLabel.getText() + "\n\n Harry Potter Series: $" + harryPotterCost);
- }
- else if (e.getSource() == hungerGames) {
- booksLabel.setText(booksLabel.getText() + "\n\n Hunger Games Series: $" + hungerGamesCost);
- }
- else if (e.getSource() == textbook) {
- booksLabel.setText(booksLabel.getText() + "\n\n Any Textbook: $" + textbookCost);
- }
- }
- }
- private class CheckBoxListener implements ItemListener {
- @Override
- public void itemStateChanged(ItemEvent e) {
- if (gameStoreOption.isSelected()) {
- gameStoreOption.setSelected(true);
- gameMenu.setVisible(true);
- foodMenu.setVisible(false);
- bookMenu.setVisible(false);
- foodStoreOption.setSelected(false);
- bookStoreOption.setSelected(false);
- }
- else if (foodStoreOption.isSelected()) {
- foodStoreOption.setSelected(true);
- foodMenu.setVisible(true);
- gameMenu.setVisible(false);
- bookMenu.setVisible(false);
- bookStoreOption.setSelected(false);
- gameStoreOption.setSelected(false);
- }
- else if (bookStoreOption.isSelected()) {
- bookStoreOption.setSelected(true);
- foodMenu.setVisible(false);
- gameMenu.setVisible(false);
- bookMenu.setVisible(true);
- foodStoreOption.setSelected(false);
- gameStoreOption.setSelected(false);
- }
- else if (foodStoreOption.isSelected() && gameStoreOption.isSelected() && bookStoreOption.isSelected()) {
- gameMenu.setVisible(false);
- foodMenu.setVisible(false);
- bookMenu.setVisible(false);
- foodStoreOption.setSelected(false);
- bookStoreOption.setSelected(false);
- gameStoreOption.setSelected(false);
- }
- else {
- foodMenu.setVisible(false);
- gameMenu.setVisible(false);
- bookMenu.setVisible(false);
- foodStoreOption.setSelected(false);
- bookStoreOption.setSelected(false);
- gameStoreOption.setSelected(false);
- }
- }
- }
- public static void main(String[] args) {
- new FinalProject();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement