Mary_99

kulki

May 7th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.81 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5.  
  6.  
  7. public class Ball extends JFrame implements ActionListener {
  8.  
  9.  
  10.     static final int MAX_BALL = 3;
  11.     static final int SQUERE_WIDTH = 9;
  12.     static final int SQUERE_HIGHT = 9;
  13.     static final int BALL_SIZE = 45;
  14.     static final int PANEL_WIDTH = 405;
  15.     static final int PANEL_HEIGHT = 405 ;
  16.  
  17.     final int FRAME_WIDTH =540;
  18.     final int FRAME_HEIGHT = 455;
  19.  
  20.     public static int points;
  21.  
  22.     final Font font1 = new Font("System", 1, 18);
  23.     final Font font2 = new Font("System", 1, 22);
  24.  
  25.  
  26.     static final Color BACKGROUNG_COLOUR = new Color(225, 141, 198);
  27.  
  28.     static final Color [] SQUERE_COLOUR =
  29.             {
  30.                     new Color(171, 225, 224),
  31.                     new Color(100, 225, 100),
  32.                     new Color(225, 225, 0),
  33.                     new Color(85, 170, 255)
  34.             };
  35.  
  36.     static final Color[] BALL_COLOUR;
  37.     JPanel panel;
  38.     static JLabel lPoints;
  39.     JLabel lText;
  40.     JLabel lLegend1;
  41.     JLabel lLegend2;
  42.     JLabel lLegend3;
  43.     JButton bStart;
  44.     static GameArea gameArea;
  45.  
  46.     static {
  47.         BALL_COLOUR = new Color[]{Color.RED, Color.BLUE, Color.GREEN, Color.CYAN, Color.ORANGE};
  48.     }
  49.  
  50.  
  51.     public Ball()
  52.     {
  53.         super("Ball");
  54.         this.setDefaultCloseOperation(3);
  55.         this.panel = new JPanel();
  56.         gameArea = new GameArea();
  57.         this.lText = new JLabel("POINTS", 0);
  58.         lPoints = new JLabel("0", 0);
  59.         this.lLegend1 = new JLabel("Spaces", 0);
  60.         this.lLegend2 = new JLabel("Selected ", 0);
  61.         this.lLegend3 = new JLabel("Balls");
  62.         this.bStart = new JButton("NEW");
  63.         this.panel.setLayout((LayoutManager)null);
  64.         this.panel.setBackground(BACKGROUNG_COLOUR);
  65.         gameArea.setBounds(10, 10, 405, 405);
  66.         gameArea.setBackground(SQUERE_COLOUR[0]);
  67.         this.lText.setFont(this.font1);
  68.         this.lText.setBounds(425, 40, 100, 30);
  69.         this.lText.setForeground(Color.WHITE);
  70.         lPoints.setFont(this.font2);
  71.         lPoints.setBounds(425, 60, 100, 30);
  72.         lPoints.setForeground(Color.WHITE);
  73.         this.lLegend1.setFont(this.font1);
  74.         this.lLegend1.setBounds(425, 285, 100, 30);
  75.         this.lLegend1.setForeground(SQUERE_COLOUR[1]);
  76.         this.lLegend2.setFont(this.font1);
  77.         this.lLegend2.setBounds(425, 305, 100, 30);
  78.         this.lLegend2.setForeground(SQUERE_COLOUR[2]);
  79.         this.lLegend3.setFont(this.font1);
  80.         this.lLegend3.setBounds(425, 325, 100, 30);
  81.         this.lLegend3.setForeground(SQUERE_COLOUR[3]);
  82.         this.bStart.setBounds(425, 385, 100, 30);
  83.         this.panel.add(gameArea);
  84.         this.panel.add(this.lText);
  85.         this.panel.add(lPoints);
  86.         this.panel.add(this.lLegend1);
  87.         this.panel.add(this.lLegend2);
  88.         this.panel.add(this.lLegend3);
  89.         this.panel.add(this.bStart);
  90.         this.add(this.panel);
  91.         this.bStart.addActionListener(this);
  92.         this.setSize(540, 455);
  93.         this.setLocationRelativeTo((Component)null);
  94.         this.setResizable(false);
  95.         this.setVisible(true);
  96.     }
  97.  
  98.     public static void main (String[] args) {new Ball();}
  99.  
  100.     public void actionPerformed(ActionEvent e) {
  101.         if (points > 0) {
  102.             Object[] opcions = new Object[]{"NEW GAME", "Return"};
  103.             int opcion = JOptionPane.showOptionDialog((Component)null, "Are you sure?", "NEW GAME", 0, 3, (Icon)null, opcions, opcions[0]);
  104.             if (opcion == 0) {
  105.                 gameArea.newGame();
  106.                 gameArea.printSquere();
  107.                 lPoints.setText("0");
  108.             }
  109.         } else {
  110.             gameArea.newGame();
  111.             gameArea.printSquere();
  112.             lPoints.setText("0");
  113.         }
  114.  
  115.     }
  116. }
Add Comment
Please, Sign In to add comment