Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- //@SuppressWornings("serial")
- public class Ball extends JFrame implements ActionListener {
- static final int MAX_BALL = 3;
- static final int SQUERE_WIDTH = 9;
- static final int SQUERE_HIGHT = 9;
- static final int BALL_SIZE = 45;
- static final int PANEL_WIDTH = 405;
- static final int PANEL_HEIGHT = 405 ;
- final int FRAME_WIDTH =540;
- final int FRAME_HEIGHT = 455;
- final Font font1 = new Font("System", 1, 11);
- final Font font2 = new Font("System", 1, 22);
- static final Color BACKGROUNG_COLOUR = new Color(225, 141, 198);
- static final Color [] SQUERE_COLOUR =
- {
- new Color(171, 225, 224),
- new Color(100, 225, 100),
- new Color(225, 225, 0),
- new Color(85, 170, 255)
- };
- static final Color[] BALL_COLOUR;
- JPanel panel;
- static JLabel lPoints;
- JLabel lText;
- JLabel lLegend1;
- JLabel lLegend2;
- JLabel lLegend3;
- JButton bStart;
- static GameArea gameArea;
- static {
- BALL_COLOUR = new Color[]{Color.RED, Color.BLUE, Color.GREEN, Color.CYAN, Color.ORANGE};
- }
- public Ball()
- {
- super("Ball");
- this.setDefaultCloseOperation(3);
- this.panel = new JPanel();
- gameArea = new GameArea();
- this.lText = new JLabel("POINTS", 0);
- lPoints = new JLabel("0", 0);
- this.lLegend1 = new JLabel("Free Spaces", 0);
- this.lLegend2 = new JLabel("Selected Spaces", 0);
- this.lLegend3 = new JLabel("New Ball");
- this.bStart = new JButton("New Game");
- this.panel.setLayout((LayoutManager)null);
- this.panel.setBackground(BACKGROUNG_COLOUR);
- gameArea.setBounds(10, 10, 405, 405);
- gameArea.setBackground(SQUERE_COLOUR[0]);
- this.lText.setFont(this.font1);
- this.lText.setBounds(425, 40, 100, 30);
- this.lText.setForeground(Color.WHITE);
- lPoints.setFont(this.font2);
- lPoints.setBounds(425, 60, 100, 30);
- lPoints.setForeground(Color.WHITE);
- this.lLegend1.setFont(this.font1);
- this.lLegend1.setBounds(425, 285, 100, 30);
- this.lLegend1.setForeground(SQUERE_COLOUR[1]);
- this.lLegend2.setFont(this.font1);
- this.lLegend2.setBounds(425, 305, 100, 30);
- this.lLegend2.setForeground(SQUERE_COLOUR[2]);
- this.lLegend3.setFont(this.font1);
- this.lLegend3.setBounds(425, 325, 100, 30);
- this.lLegend3.setForeground(SQUERE_COLOUR[3]);
- this.bStart.setBounds(425, 385, 100, 30);
- this.panel.add(gameArea);
- this.panel.add(this.lText);
- this.panel.add(lPoints);
- this.panel.add(this.lLegend1);
- this.panel.add(this.lLegend2);
- this.panel.add(this.lLegend3);
- this.panel.add(this.bStart);
- this.add(this.panel);
- this.bStart.addActionListener(this);
- this.setSize(540, 455);
- this.setLocationRelativeTo((Component)null);
- this.setResizable(false);
- this.setVisible(true);
- }
- public static void main (String[] args) {new Ball();}
- public void actionPerformed(ActionEvent e) {
- if (points > 0) {
- Object[] opcje = new Object[]{"NEW GAME", "Return"};
- int opcja = JOptionPane.showOptionDialog((Component)null, "Napewno chcesz przerwać istniejącą rozgrywke?", "Rozpoczęcie od początku", 0, 3, (Icon)null, opcje, opcje[0]);
- if (opcja == 0) {
- gameArea.newGame();
- gameArea.printSquere();
- lPoints.setText("0");
- }
- } else {
- gameArea.newGame();
- gameArea.printSquere();
- lPoints.setText("0");
- }
- }
- }
Add Comment
Please, Sign In to add comment