Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. import javax.swing.JFrame;
  2. import java.awt.*;
  3.  
  4. public class UsageThread {
  5. public UsageThread() {}
  6.  
  7. public static void main(String[] args) {
  8.  
  9. JFrame frame = new JFrame("Slot Machine");
  10.  
  11. ball game1 = new ball(250, "1");
  12. ball game2 = new ball(50, "2");
  13. ball game3 = new ball(50, "3");
  14.  
  15. frame.setSize(500, 500);
  16. frame.setLocation(50, 50);
  17. frame.add(game1);
  18. frame.add(game2);
  19. frame.add(game3);
  20. frame.setVisible(true);
  21. frame.setDefaultCloseOperation(3);
  22. game1.start();
  23. game2.start();
  24. game3.start();
  25. game1.stop();
  26. game2.stop();
  27. game3.stop();
  28.  
  29. }
  30. }
  31.  
  32. ------------------------------------------
  33.  
  34. import java.awt.Color;
  35. import java.awt.Graphics2D;
  36. import java.io.PrintStream;
  37.  
  38. public class ball extends javax.swing.JPanel implements Runnable
  39. {
  40. public int x;
  41. public int y = 0;
  42. public String b;
  43. Thread t;
  44.  
  45. public ball(int a, String c) { x = a;
  46.  
  47. b = c;
  48. System.out.println("Creating " + c);
  49. }
  50.  
  51. public void paint(java.awt.Graphics g) {
  52. super.paint(g);
  53.  
  54. Graphics2D g2d = (Graphics2D)g;
  55. Graphics2D g3d = (Graphics2D)g;
  56. Graphics2D g4d = (Graphics2D)g;
  57.  
  58.  
  59.  
  60. int n1 = (int)(Math.random()*3);
  61. int n2 = (int)(Math.random()*3);
  62. int n3 = (int)(Math.random()*3);
  63.  
  64. switch(n1){
  65. case 0:
  66. g2d.setColor(Color.blue);
  67. g2d.fillOval(10, 10, 30, 30);
  68. break;
  69. case 1:
  70. g2d.setColor(Color.green);
  71. g2d.fillOval(10, 10, 30, 30);
  72. break;
  73. case 2:
  74. g2d.setColor(Color.red);
  75. g2d.fillOval(10, 10, 30, 30);
  76. break;
  77. }
  78. switch(n2){
  79. case 0:
  80. g3d.setColor(Color.blue);
  81. g3d.fillOval(50, 10, 30, 30);
  82. break;
  83. case 1:
  84. g3d.setColor(Color.green);
  85. g3d.fillOval(50, 10, 30, 30);
  86. break;
  87. case 2:
  88. g3d.setColor(Color.red);
  89. g3d.fillOval(50, 10, 30, 30);
  90. break;
  91. }
  92. switch(n3){
  93. case 0:
  94. g4d.setColor(Color.blue);
  95. g4d.fillOval(90, 10, 30, 30);
  96.  
  97. case 1:
  98. g4d.setColor(Color.green);
  99. g4d.fillOval(90, 10, 30, 30);
  100.  
  101. case 2:
  102. g4d.setColor(Color.red);
  103. g4d.fillOval(90, 10, 30, 30);
  104. }
  105.  
  106.  
  107.  
  108. }
  109.  
  110.  
  111.  
  112.  
  113. public void run()
  114. {
  115.  
  116. y += 1;
  117.  
  118. if (y < 450) {
  119. y += 30;
  120. repaint();
  121. } else {
  122. y = 30;
  123. repaint();
  124. }
  125. System.out.println(x);
  126. repaint();
  127.  
  128.  
  129. }
  130.  
  131. public void start() {
  132. if (t == null) {
  133. t = new Thread(this);
  134. t.start();
  135. }
  136. }
  137. public void stop() {
  138. if (t == null) {
  139. t = new Thread(this);
  140. t.stop();
  141. }
  142. }
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement