Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. import java.awt.*;
  2. public class Main {
  3. public static void main(String[] args) {
  4.  
  5. BarberGui b = new BarberGui();
  6.  
  7. Human human1 = new Human(b, 0);
  8. Human human2 = new Human(b, 1);
  9. Human human3 = new Human(b, 2);
  10. Human human4 = new Human(b, 3);
  11. Human human5 = new Human(b, 4);
  12. human1.start();
  13. human2.start();
  14. human3.start();
  15. human4.start();
  16. human5.start();
  17. }
  18. }
  19.  
  20. class Human extends Thread {
  21. Button mButton;
  22. BarberGui mBarberGui;
  23. Integer mHumanID;
  24. public Human(BarberGui b, int i) {
  25. mHumanID = i;
  26. mBarberGui = b;
  27. mButton = new Button();
  28. mButton.setBounds(b.pos[mHumanID][0].x, b.pos[mHumanID][0].y, 20, 20);
  29. mButton.setFont(new Font("TimesRoman", 0, 10));
  30. mButton.setBackground(Color.blue);
  31. mButton.setForeground(Color.white);
  32. mButton.setLabel(new Integer(mHumanID).toString());
  33. mButton.setVisible(true);
  34. b.add(mButton);
  35. }
  36. public void Go(int i) {
  37. mButton.setLocation(mBarberGui.pos[mHumanID][i].x, mBarberGui.pos[mHumanID][i].y);
  38. }
  39. public void run() {
  40. int counter = 0;
  41. while(true) {
  42. try {
  43. Thread.sleep((int)(Math.random() * 5000));
  44. }catch(InterruptedException e) {
  45. System.err.println(e.toString());
  46. }
  47. if(counter == 4) counter = 0;
  48. Go(counter++);
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement