Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package tarekeselotto;
- import java.awt.Color;
- import java.awt.FlowLayout;
- import java.awt.Graphics;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JPanel;
- import javax.swing.Timer;
- /**
- *
- * @author isonuZ
- */
- public class Ball extends JPanel {
- private boolean[] numbers = new boolean[42];
- public String value;
- public int radius = 15;
- int delay = 100;
- Timer timer = new Timer(delay, new TimerListenerBall());
- int timerCount = 0;
- boolean spinning = false;
- public Ball() {
- value = "0";
- this.timer.start();
- }
- private void rollWheels() {
- this.spinning = true;
- this.timer.start();
- }
- public int getValue(int[] resultArray, int bounds) {
- rollWheels();
- System.out.print("he");
- //while(this.spinning) {}
- System.out.println("llo");
- numbers[Integer.parseInt(value)+1] = false;
- return Integer.parseInt(value);
- }
- protected void paintComponent(Graphics g) {
- super.paintComponent(g);
- g.setColor(Color.red);
- g.fillOval(5, 5, 2 * radius, 2 * radius);
- g.setColor(Color.white);
- g.fillOval(8, 8,
- 2 * radius - 7,
- 2 * radius - 7);
- g.setColor(Color.black);
- g.drawString(value, radius+1, radius+10);
- }
- class TimerListenerBall implements ActionListener {
- /** Handle ActionEvent */
- public void actionPerformed(ActionEvent e) {
- int number;
- do {
- number = (int) (Math.random()*42);
- } while(!numbers[number]);
- value = number + "";
- timerCount++;
- if(timerCount > 15)
- delay = 150;
- if(timerCount > 20)
- delay = 200;
- if(timerCount > 50)
- delay = 1000;
- if(timerCount > 53)
- spinning = false;
- if(spinning) {
- timer.setDelay(delay);
- repaint();
- } else {
- timer.stop();
- }
- repaint();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement