Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -----------------------------------------------------------------------------------------------------------------------------------
- // Name That Tune!
- // Description: This class is the GUI part of the program.
- // Sammy Samkough
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class NameThatTuneGUI extends JFrame
- {
- // size of screen
- public static final int WIDTH = 400;
- public static final int HEIGHT = 500;
- // title
- public static final String text = "MALLIKATRON NAME THAT TUNE!";
- private JLabel title;
- /* Buttons Include: 1) Start 2) About
- Start - starts the game
- About - includes the game layout, how it works, and the people behind the project
- */
- private JButton startB, aboutB, exitB;
- // layout
- private FlowLayout layout = new FlowLayout(FlowLayout.LEFT, 50, 50);
- public NameThatTuneGUI()
- {
- // this is for the space between the buttons as well
- this.setLayout(new FlowLayout(FlowLayout.LEFT, 50, 50));
- // buttons
- startB = new JButton("START");
- startB.setPreferredSize(new Dimension(300, 50));
- aboutB = new JButton("ABOUT");
- aboutB.setPreferredSize(new Dimension(300, 50));
- exitB = new JButton("EXIT");
- exitB.setPreferredSize(new Dimension(300, 50));
- if(exitB.getModel().isPressed())
- {
- int confirm = JOptionPane.showOptionDialog(null, "Are You Sure to Close Application?", "Exit Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
- if (confirm == 0)
- {
- System.exit(0);
- }
- }
- // labels
- title = new JLabel(text);
- title.setFont(title.getFont().deriveFont(24.0f));
- // additions
- add(title);
- add(startB);
- add(aboutB);
- add(exitB);
- // listeners
- event e1 = new event();
- startB.addActionListener(e1);
- event2 e2 = new event2();
- aboutB.addActionListener(e2);
- event3 e3 = new event3();
- exitB.addActionListener(e3);
- addWindowListener(exitListener);
- }
- WindowListener exitListener = new WindowAdapter()
- {
- @Override
- public void windowClosing(WindowEvent e)
- {
- 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);
- if (confirm == 0)
- {
- System.exit(0);
- }
- }
- };
- public class event implements ActionListener
- {
- public void actionPerformed(ActionEvent e)
- {
- NameThatTuneGuiStart gui = new NameThatTuneGuiStart();
- gui.setTitle("Name That Tune!");
- gui.setSize(gui.WIDTH, gui.HEIGHT);
- gui.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
- gui.setLocationRelativeTo(null);
- gui.setVisible(true);
- gui.getContentPane().setBackground(new Color(255, 178, 108));
- dispose();
- }
- }
- public class event2 implements ActionListener
- {
- public void actionPerformed(ActionEvent e)
- {
- NameThatTuneGuiAbout gui = new NameThatTuneGuiAbout();
- gui.setTitle("About");
- gui.setSize(gui.WIDTH, gui.HEIGHT);
- gui.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
- gui.setLocationRelativeTo(null);
- gui.setVisible(true);
- gui.setContentPane(new JLabel(new ImageIcon("res/about.png")));
- }
- }
- public class event3 implements ActionListener
- {
- public void actionPerformed(ActionEvent e)
- {
- 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);
- if (confirm == 0)
- {
- dispose();
- System.exit(0);
- }
- else
- {
- // continue
- }
- }
- }
- public static void main (String args[])
- {
- NameThatTuneGUI frame = new NameThatTuneGUI();
- frame.setTitle("Main Menu");
- frame.setSize(WIDTH, HEIGHT);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setLocationRelativeTo(null);
- frame.setVisible(true);
- frame.getContentPane().setBackground(new Color(255, 178, 108));
- }
- }
- -----------------------------------------------------------------------------------------------------------------------------------
- // Name That Tune!
- // Description: This class is the GUI part of the program.
- // Sammy Samkough
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class NameThatTuneGuiStart extends JFrame
- {
- // size of screen
- public static final int WIDTH = 900;
- public static final int HEIGHT = 900;
- public NameThatTuneGuiStart()
- {
- setLayout(new FlowLayout());
- setSize(WIDTH, HEIGHT);
- getContentPane().setBackground(new Color(255, 178, 108));
- addWindowListener(exitListener);
- }
- WindowListener exitListener = new WindowAdapter()
- {
- @Override
- public void windowClosing(WindowEvent e)
- {
- NameThatTuneGUI frame = new NameThatTuneGUI();
- frame.setTitle("Main Menu");
- frame.setSize(frame.WIDTH, frame.HEIGHT);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setLocationRelativeTo(null);
- frame.setVisible(true);
- frame.getContentPane().setBackground(new Color(255, 178, 108));
- dispose();
- }
- };
- public static void main (String args[])
- {
- }
- }
- -----------------------------------------------------------------------------------------------------------------------------------
- // Name That Tune!
- // Description: This class is the GUI part of the program.
- // Sammy Samkough
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class NameThatTuneGuiAbout extends JFrame
- {
- // size of screen
- public static final int WIDTH = 600;
- public static final int HEIGHT = 600;
- public NameThatTuneGuiAbout()
- {
- setLayout(new FlowLayout());
- // listeners
- addWindowListener(exitListener);
- }
- WindowListener exitListener = new WindowAdapter()
- {
- @Override
- public void windowClosing(WindowEvent e)
- {
- NameThatTuneGUI frame = new NameThatTuneGUI();
- frame.setTitle("Main Menu");
- frame.setSize(frame.WIDTH, frame.HEIGHT);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setLocationRelativeTo(null);
- frame.setVisible(true);
- frame.getContentPane().setBackground(new Color(255, 178, 108));
- dispose();
- }
- };
- public static void main (String args[])
- {
- }
- }
- -----------------------------------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement