Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. package b;
  2.  
  3. import java.util.List;
  4.  
  5. import guiTeacher.components.*;
  6. import guiTeacher.interfaces.Visible;
  7. import guiTeacher.userInterfaces.FullFunctionScreen;
  8.  
  9. public class Screen extends FullFunctionScreen
  10. {
  11. private TextLabel countdown;
  12. private TextLabel scoreLabel;
  13. private Button button;
  14. private int score;
  15. private int clicks;
  16. private boolean clicked1;
  17. private boolean clicked2;
  18.  
  19. public Screen(int width, int height)
  20. {
  21. super(width, height);
  22. }
  23.  
  24. @Override
  25. public void initAllObjects(List<Visible> viewObjects)
  26. {
  27. String s = "Score: "+score;
  28. clicks = 0;
  29.  
  30.  
  31. scoreLabel = new TextLabel(30,50,200,200, s);
  32. viewObjects.add(scoreLabel);
  33.  
  34. countdown = new TextLabel(30,80,200,200,"");
  35. viewObjects.add(countdown);
  36.  
  37. button = new Button(30,150,200,200, "Ready",new Action() {
  38.  
  39. @Override
  40. public void act() {
  41.  
  42. if (!clicked1)
  43. {
  44. new Thread()
  45. {
  46. public void run()
  47. {
  48. try
  49. {
  50. countdown.setText("3");
  51. Thread.sleep(1000);
  52. countdown.update();
  53. countdown.setText("2");
  54. Thread.sleep(1000);
  55. countdown.update();
  56. countdown.setText("1");
  57. Thread.sleep(1000);
  58. countdown.update();
  59. countdown.setText("Go!");
  60. countdown.update();
  61. button.setText("Click me!");
  62. button.update();
  63.  
  64.  
  65. }
  66. catch (InterruptedException e)
  67. {
  68. e.printStackTrace();
  69. }
  70. }
  71. } .start();
  72. clicked1 = true;
  73. }
  74. else
  75. {
  76. if (!clicked2)
  77. {
  78. new Thread()
  79. {
  80. public void run()
  81. {
  82. try
  83. {
  84. countdown.setText("5");
  85. Thread.sleep(1000);
  86. countdown.update();
  87. countdown.setText("4");
  88. Thread.sleep(1000);
  89. countdown.update();
  90. countdown.setText("3");
  91. Thread.sleep(1000);
  92. countdown.update();
  93. countdown.setText("2");
  94. countdown.update();
  95. Thread.sleep(1000);
  96. countdown.setText("1");
  97. Thread.sleep(1000);
  98. countdown.update();
  99. countdown.setText("0");
  100. countdown.update();
  101. button.setText("Done");
  102. button.update();
  103.  
  104. }
  105. catch (InterruptedException e)
  106. {
  107. e.printStackTrace();
  108. }
  109. }
  110. } .start();
  111. clicked2 = true;
  112. }
  113. else
  114. {
  115. if (!countdown.getText().equals("0"))
  116. {
  117. clicks++;
  118. scoreLabel.setText(clicks+"");
  119. }
  120. }
  121. }
  122. }
  123. });
  124. viewObjects.add(button);
  125. }
  126.  
  127. }
  128. import guiTeacher.GUIApplication;
  129.  
  130. public class MainGUI extends GUIApplication {
  131.  
  132. public static Screen a;
  133. public MainGUI(int width, int height) {
  134. super(width, height);
  135. setVisible(true);
  136. }
  137.  
  138. @Override
  139. public void initScreen() {
  140. a = new Screen(getWidth(), getHeight());
  141. setScreen(a);
  142. }
  143.  
  144. public static void main(String[] args) {
  145. MainGUI gui = new MainGUI(500,500);
  146. Thread b = new Thread(gui);
  147. b.start();
  148. }
  149.  
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement