SHARE
TWEET

Ball correct

Mary_99 May 6th, 2019 60 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.     public static int points;
  25.  
  26.     final Font font1 = new Font("System", 1, 11);
  27.     final Font font2 = new Font("System", 1, 22);
  28.  
  29.  
  30.     static final Color BACKGROUNG_COLOUR = new Color(225, 141, 198);
  31.  
  32.     static final Color [] SQUERE_COLOUR =
  33.             {
  34.                     new Color(171, 225, 224),
  35.                     new Color(100, 225, 100),
  36.                     new Color(225, 225, 0),
  37.                     new Color(85, 170, 255)
  38.             };
  39.  
  40.     static final Color[] BALL_COLOUR;
  41.     JPanel panel;
  42.     static JLabel lPoints;
  43.     JLabel lText;
  44.     JLabel lLegend1;
  45.     JLabel lLegend2;
  46.     JLabel lLegend3;
  47.     JButton bStart;
  48.     static GameArea gameArea;
  49.  
  50.     static {
  51.         BALL_COLOUR = new Color[]{Color.RED, Color.BLUE, Color.GREEN, Color.CYAN, Color.ORANGE};
  52.     }
  53.  
  54.  
  55.     public Ball()
  56.     {
  57.         super("Ball");
  58.         this.setDefaultCloseOperation(3);
  59.         this.panel = new JPanel();
  60.         gameArea = new GameArea();
  61.         this.lText = new JLabel("POINTS", 0);
  62.         lPoints = new JLabel("0", 0);
  63.         this.lLegend1 = new JLabel("Free Spaces", 0);
  64.         this.lLegend2 = new JLabel("Selected Spaces", 0);
  65.         this.lLegend3 = new JLabel("New Ball");
  66.         this.bStart = new JButton("New Game");
  67.         this.panel.setLayout((LayoutManager)null);
  68.         this.panel.setBackground(BACKGROUNG_COLOUR);
  69.         gameArea.setBounds(10, 10, 405, 405);
  70.         gameArea.setBackground(SQUERE_COLOUR[0]);
  71.         this.lText.setFont(this.font1);
  72.         this.lText.setBounds(425, 40, 100, 30);
  73.         this.lText.setForeground(Color.WHITE);
  74.         lPoints.setFont(this.font2);
  75.         lPoints.setBounds(425, 60, 100, 30);
  76.         lPoints.setForeground(Color.WHITE);
  77.         this.lLegend1.setFont(this.font1);
  78.         this.lLegend1.setBounds(425, 285, 100, 30);
  79.         this.lLegend1.setForeground(SQUERE_COLOUR[1]);
  80.         this.lLegend2.setFont(this.font1);
  81.         this.lLegend2.setBounds(425, 305, 100, 30);
  82.         this.lLegend2.setForeground(SQUERE_COLOUR[2]);
  83.         this.lLegend3.setFont(this.font1);
  84.         this.lLegend3.setBounds(425, 325, 100, 30);
  85.         this.lLegend3.setForeground(SQUERE_COLOUR[3]);
  86.         this.bStart.setBounds(425, 385, 100, 30);
  87.         this.panel.add(gameArea);
  88.         this.panel.add(this.lText);
  89.         this.panel.add(lPoints);
  90.         this.panel.add(this.lLegend1);
  91.         this.panel.add(this.lLegend2);
  92.         this.panel.add(this.lLegend3);
  93.         this.panel.add(this.bStart);
  94.         this.add(this.panel);
  95.         this.bStart.addActionListener(this);
  96.         this.setSize(540, 455);
  97.         this.setLocationRelativeTo((Component)null);
  98.         this.setResizable(false);
  99.         this.setVisible(true);
  100.     }
  101.  
  102.     public static void main (String[] args) {new Ball();}
  103.  
  104.     public void actionPerformed(ActionEvent e) {
  105.         if (points > 0) {
  106.             Object[] opcje = new Object[]{"NEW GAME", "Return"};
  107.             int opcja = JOptionPane.showOptionDialog((Component)null, "Napewno chcesz przerwać istniejącą rozgrywke?", "Rozpoczęcie od początku", 0, 3, (Icon)null, opcje, opcje[0]);
  108.             if (opcja == 0) {
  109.                 gameArea.newGame();
  110.                 gameArea.printSquere();
  111.                 lPoints.setText("0");
  112.             }
  113.         } else {
  114.             gameArea.newGame();
  115.             gameArea.printSquere();
  116.             lPoints.setText("0");
  117.         }
  118.  
  119.     }
  120. }
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