Advertisement
Guest User

yurd a hunna

a guest
Jan 18th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. package clickProject;
  2.  
  3. import java.awt.Color;
  4.  
  5. import guiTeacher.GUIApplication;
  6.  
  7. public class Click extends GUIApplication{
  8.  
  9. public Click(int width, int height) {
  10. super(width, height);
  11. setVisible(true);
  12. }
  13.  
  14. @Override
  15. public void initScreen() {
  16. WinScreen screen = new WinScreen(getWidth(), getHeight());
  17. setScreen(screen);
  18. }
  19.  
  20. public static void main(String[] args) {
  21. Click game = new Click(800, 500);
  22. game.setLocationRelativeTo(null);
  23. Thread runner = new Thread(game);
  24. runner.start();
  25. }
  26. }
  27.  
  28.  
  29. package clickProject;
  30.  
  31. import java.awt.Color;
  32. import java.util.List;
  33.  
  34. import guiTeacher.components.Action;
  35. import guiTeacher.components.Button;
  36. import guiTeacher.components.TextLabel;
  37. import guiTeacher.interfaces.Visible;
  38. import guiTeacher.userInterfaces.FullFunctionScreen;
  39.  
  40. public class ClickScreen extends FullFunctionScreen {
  41.  
  42. private Button button;
  43. private TextLabel text;
  44. private TextLabel time;
  45. private boolean ready;
  46. private int score;
  47. private boolean over;
  48.  
  49.  
  50. public ClickScreen(int width, int height) {
  51. super(width, height);
  52. Thread app = new Thread();
  53. ready = false;
  54. score = 0;
  55. over = false;
  56. app.start();
  57. // TODO Auto-generated constructor stub
  58. }
  59.  
  60. @Override
  61. public void initAllObjects(List<Visible> viewObjects) {
  62. // TODO Auto-generated method stub
  63.  
  64. button = new Button(220, 50, 50, 50, "Ready",Color.red, null);
  65. button.setAction(new Action() {
  66.  
  67. @Override
  68. public void act() {
  69. // TODO Auto-generated method stub
  70. Thread t = new Thread(new Runnable() {
  71.  
  72. @Override
  73. public void run() {
  74. if(ready) {
  75. clickme();
  76. } else {
  77. countr();
  78. button.setEnabled(false);
  79. }
  80.  
  81. }
  82.  
  83. });
  84. t.start();
  85.  
  86.  
  87. }
  88.  
  89. private void clickme() {
  90. Thread t = new Thread(new Runnable() {
  91.  
  92. @Override
  93. public void run() {
  94. // TODO Auto-generated method stub
  95. if(!over) {
  96. score++;
  97. text.setText(Integer.toString(score));
  98. }
  99.  
  100. }
  101.  
  102. });
  103. t.start();
  104.  
  105. }
  106.  
  107. });
  108. viewObjects.add(button);
  109. text = new TextLabel(220, 200, 100, 100, "");
  110. viewObjects.add(text);
  111.  
  112. time = new TextLabel(220,300,100,100,"");
  113.  
  114. viewObjects.add(time);
  115.  
  116.  
  117. }
  118.  
  119. public void run() {
  120.  
  121. }
  122.  
  123. public void countr() {
  124. ready = true;
  125. Thread t = new Thread(new Runnable() {
  126.  
  127. @Override
  128. public void run() {
  129. // TODO Auto-generated method stub
  130. try {
  131. for(int i = 3; i >= 1; i--) {
  132. text.setText(i + "...");
  133. Thread.sleep(1000);
  134. }
  135. text.setText("GO!!");
  136. button.setText("CLICK ME!");
  137.  
  138. button.setEnabled(true);
  139.  
  140. for(int i = 5; i >= 1; i--) {
  141. time.setText(Integer.toString(i) + " seconds left..");
  142. Thread.sleep(1000);
  143. }
  144. time.setText("TIMES UP!");
  145. over = true;
  146. }catch(InterruptedException e) {
  147. e.printStackTrace();
  148. }
  149.  
  150. }
  151.  
  152. });
  153. t.start();
  154. }
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement