Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package FTTG;
- import java.awt.*;
- import javax.swing.*;
- import java.awt.event.*;
- import java.util.Random;
- //@Cakemoth [20171705]
- // Class [4]
- // EXMP - [2] :BURGER:
- public class FTTC extends JFrame{
- //Class Declarations
- //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- JLabel label0 = new JLabel();
- JLabel label1 = new JLabel();
- JLabel label2 = new JLabel();
- static JLabel[] choiceLabel = new JLabel[3];
- static ImageIcon burger = new ImageIcon("burger.gif");
- static int burgerLocation;
- static Random myRandom = new Random();
- //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- JFrame FindBurger = new JFrame();
- //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- JButton newButton = new JButton();
- //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- static boolean isHot = false;
- //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- public static void main(String args[])
- {
- new FTTC();
- }
- //- - - - -Hamburger Finder- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- public FTTC()
- {
- setTitle("Trouver l'hamburger");
- setVisible(true);
- setResizable(false);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- addWindowListener(new WindowAdapter()
- {
- public void windowClosing(WindowEvent evt)
- {
- exitForm(evt);
- }
- });
- getContentPane().setLayout(new GridBagLayout());
- //Application Controls
- getContentPane().setLayout(new GridBagLayout());
- GridBagConstraints gridCons;
- gridCons = new GridBagConstraints();
- //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- GridBagConstraints gridConstraints;
- choiceLabel[0] = label0;
- choiceLabel[1] = label1;
- choiceLabel[2] = label2;
- for (int i = 0; i < 3; i++)
- {
- gridConstraints = new GridBagConstraints();
- choiceLabel[i].setPreferredSize(new
- Dimension(burger.getIconWidth(), burger.getIconHeight()));
- choiceLabel[i].setOpaque(true);
- choiceLabel[i].setBackground(Color.RED);
- gridConstraints.gridx = i;
- gridConstraints.gridy = 0;
- gridConstraints.insets = new Insets(10, 10, 10, 10);
- getContentPane().add(choiceLabel[i], gridConstraints);
- choiceLabel[i].addMouseListener(new MouseAdapter()
- {
- public void mouseClicked(MouseEvent e)
- {
- labelMouseClicked(e);
- }
- });
- }
- //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- newButton.setText("Play Again");
- gridConstraints = new GridBagConstraints();
- gridConstraints.gridx = 1;
- gridConstraints.gridy = 1;
- gridConstraints.insets = new Insets(10, 10, 10, 10);
- getContentPane().add(newButton, gridConstraints);
- newButton.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- newButtonActionPerformed(e);
- }
- });
- //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- newButton.doClick();
- //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- pack();
- Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
- setBounds((int) (0.5 *(screenSize.width - getWidth())), (int) (0.5 * (screenSize.height - getHeight())), getWidth(), getHeight());
- }
- //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- private void exitForm(WindowEvent evt)
- {
- System.exit(0);
- }
- private void labelMouseClicked(MouseEvent e)
- {
- Component clickedComponent = e.getComponent();
- int choice;
- for (choice = 0; choice < 3; choice++)
- {
- if (clickedComponent == choiceLabel[choice])
- {
- break;
- }
- }
- choiceLabel[choice].setBackground(Color.WHITE);
- if (choice == burgerLocation)
- {
- choiceLabel[choice].setIcon(burger);
- newButton.setEnabled(true);
- }
- }
- private void newButtonActionPerformed(ActionEvent e)
- {
- // clear boxes and hide burger
- for (int i = 0; i < 3; i++)
- {
- choiceLabel[i].setIcon(null);
- choiceLabel[i].setBackground(Color.RED);
- }
- burgerLocation = myRandom.nextInt(3);
- newButton.setEnabled(false);
- }
- //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement