SHARE
TWEET

Ball

Mary_99 May 6th, 2019 11 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5.  
  6.  
  7. //@SuppressWornings("serial")
  8.  
  9. public class Ball extends JFrame implements ActionListener {
  10.  
  11.  
  12.  
  13.  
  14.     static final int MAX_BALL = 3;
  15.     static final int SQUERE_WIDTH = 9;
  16.     static final int SQUERE_HIGHT = 9;
  17.     static final int BALL_SIZE = 45;
  18.     static final int PANEL_WIDTH = 405;
  19.     static final int PANEL_HEIGHT = 405 ;
  20.  
  21.     final int FRAME_WIDTH =540;
  22.     final int FRAME_HEIGHT = 455;
  23.  
  24.     final Font font1 = new Font("System", 1, 11);
  25.     final Font font2 = new Font("System", 1, 22);
  26.  
  27.  
  28.    static final Color BACKGROUNG_COLOUR = new Color(225, 141, 198);
  29.  
  30.    static final Color [] SQUERE_COLOUR =
  31.            {
  32.                    new Color(171, 225, 224),
  33.                    new Color(100, 225, 100),
  34.                    new Color(225, 225, 0),
  35.                    new Color(85, 170, 255)
  36.            };
  37.  
  38.    static final Color[] BALL_COLOUR;
  39.     JPanel panel;
  40.     static JLabel lPoints;
  41.     JLabel lText;
  42.     JLabel lLegend1;
  43.     JLabel lLegend2;
  44.     JLabel lLegend3;
  45.     JButton bStart;
  46.     static GameArea gameArea;
  47.  
  48.     static {
  49.         BALL_COLOUR = new Color[]{Color.RED, Color.BLUE, Color.GREEN, Color.CYAN, Color.ORANGE};
  50.     }
  51.  
  52.  
  53.     public Ball()
  54.     {
  55.         super("Ball");
  56.         this.setDefaultCloseOperation(3);
  57.         this.panel = new JPanel();
  58.         gameArea = new GameArea();
  59.         this.lText = new JLabel("POINTS", 0);
  60.         lPoints = new JLabel("0", 0);
  61.         this.lLegend1 = new JLabel("Free Spaces", 0);
  62.         this.lLegend2 = new JLabel("Selected Spaces", 0);
  63.         this.lLegend3 = new JLabel("New Ball");
  64.         this.bStart = new JButton("New Game");
  65.         this.panel.setLayout((LayoutManager)null);
  66.         this.panel.setBackground(BACKGROUNG_COLOUR);
  67.         gameArea.setBounds(10, 10, 405, 405);
  68.         gameArea.setBackground(SQUERE_COLOUR[0]);
  69.         this.lText.setFont(this.font1);
  70.         this.lText.setBounds(425, 40, 100, 30);
  71.         this.lText.setForeground(Color.WHITE);
  72.         lPoints.setFont(this.font2);
  73.         lPoints.setBounds(425, 60, 100, 30);
  74.         lPoints.setForeground(Color.WHITE);
  75.         this.lLegend1.setFont(this.font1);
  76.         this.lLegend1.setBounds(425, 285, 100, 30);
  77.         this.lLegend1.setForeground(SQUERE_COLOUR[1]);
  78.         this.lLegend2.setFont(this.font1);
  79.         this.lLegend2.setBounds(425, 305, 100, 30);
  80.         this.lLegend2.setForeground(SQUERE_COLOUR[2]);
  81.         this.lLegend3.setFont(this.font1);
  82.         this.lLegend3.setBounds(425, 325, 100, 30);
  83.         this.lLegend3.setForeground(SQUERE_COLOUR[3]);
  84.         this.bStart.setBounds(425, 385, 100, 30);
  85.         this.panel.add(gameArea);
  86.         this.panel.add(this.lText);
  87.         this.panel.add(lPoints);
  88.         this.panel.add(this.lLegend1);
  89.         this.panel.add(this.lLegend2);
  90.         this.panel.add(this.lLegend3);
  91.         this.panel.add(this.bStart);
  92.         this.add(this.panel);
  93.         this.bStart.addActionListener(this);
  94.         this.setSize(540, 455);
  95.         this.setLocationRelativeTo((Component)null);
  96.         this.setResizable(false);
  97.         this.setVisible(true);
  98.     }
  99.  
  100.     public static void main (String[] args) {new Ball();}
  101.  
  102.     public void actionPerformed(ActionEvent e) {
  103.         if (points > 0) {
  104.             Object[] opcje = new Object[]{"NEW GAME", "Return"};
  105.             int opcja = JOptionPane.showOptionDialog((Component)null, "Napewno chcesz przerwać istniejącą rozgrywke?", "Rozpoczęcie od początku", 0, 3, (Icon)null, opcje, opcje[0]);
  106.             if (opcja == 0) {
  107.                 gameArea.newGame();
  108.                 gameArea.printSquere();
  109.                 lPoints.setText("0");
  110.             }
  111.         } else {
  112.             gameArea.newGame();
  113.             gameArea.printSquere();
  114.             lPoints.setText("0");
  115.         }
  116.  
  117.     }
  118. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top