Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JFrame;
- import java.awt.*;
- public class UsageThread {
- public UsageThread() {}
- public static void main(String[] args) {
- JFrame frame = new JFrame("Slot Machine");
- ball game1 = new ball(250, "1");
- ball game2 = new ball(50, "2");
- ball game3 = new ball(50, "3");
- frame.setSize(500, 500);
- frame.setLocation(50, 50);
- frame.add(game1);
- frame.add(game2);
- frame.add(game3);
- frame.setVisible(true);
- frame.setDefaultCloseOperation(3);
- game1.start();
- game2.start();
- game3.start();
- game1.stop();
- game2.stop();
- game3.stop();
- }
- }
- ------------------------------------------
- import java.awt.Color;
- import java.awt.Graphics2D;
- import java.io.PrintStream;
- public class ball extends javax.swing.JPanel implements Runnable
- {
- public int x;
- public int y = 0;
- public String b;
- Thread t;
- public ball(int a, String c) { x = a;
- b = c;
- System.out.println("Creating " + c);
- }
- public void paint(java.awt.Graphics g) {
- super.paint(g);
- Graphics2D g2d = (Graphics2D)g;
- Graphics2D g3d = (Graphics2D)g;
- Graphics2D g4d = (Graphics2D)g;
- int n1 = (int)(Math.random()*3);
- int n2 = (int)(Math.random()*3);
- int n3 = (int)(Math.random()*3);
- switch(n1){
- case 0:
- g2d.setColor(Color.blue);
- g2d.fillOval(10, 10, 30, 30);
- break;
- case 1:
- g2d.setColor(Color.green);
- g2d.fillOval(10, 10, 30, 30);
- break;
- case 2:
- g2d.setColor(Color.red);
- g2d.fillOval(10, 10, 30, 30);
- break;
- }
- switch(n2){
- case 0:
- g3d.setColor(Color.blue);
- g3d.fillOval(50, 10, 30, 30);
- break;
- case 1:
- g3d.setColor(Color.green);
- g3d.fillOval(50, 10, 30, 30);
- break;
- case 2:
- g3d.setColor(Color.red);
- g3d.fillOval(50, 10, 30, 30);
- break;
- }
- switch(n3){
- case 0:
- g4d.setColor(Color.blue);
- g4d.fillOval(90, 10, 30, 30);
- case 1:
- g4d.setColor(Color.green);
- g4d.fillOval(90, 10, 30, 30);
- case 2:
- g4d.setColor(Color.red);
- g4d.fillOval(90, 10, 30, 30);
- }
- }
- public void run()
- {
- y += 1;
- if (y < 450) {
- y += 30;
- repaint();
- } else {
- y = 30;
- repaint();
- }
- System.out.println(x);
- repaint();
- }
- public void start() {
- if (t == null) {
- t = new Thread(this);
- t.start();
- }
- }
- public void stop() {
- if (t == null) {
- t = new Thread(this);
- t.stop();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement