Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. package myStuff;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. import guiTeacher.components.Action;
  7. import guiTeacher.components.Button;
  8. import guiTeacher.components.TextArea;
  9. import guiTeacher.interfaces.Visible;
  10. import guiTeacher.userInterfaces.ClickableScreen;
  11.  
  12. public class Game extends ClickableScreen implements Runnable {
  13.  
  14. private static final long serialVersionUID = -8829654677685378367L;
  15. private TextArea txt;
  16. private Button button1;
  17. private int count;
  18. private int time;
  19. private TextArea finalTxt;
  20.  
  21. public Game(int width, int height) {
  22. super(width, height);
  23. count = 0;
  24. time = 10;
  25. Thread app = new Thread(this);
  26. app.start();
  27. }
  28.  
  29. public Game(int width, int height, ArrayList<Visible> initWithObjects) {
  30. super(width, height);
  31. }
  32.  
  33. @Override
  34. public void run() {
  35. for(int i = time; i > 0; i--) {
  36. time--;
  37. try {
  38. Thread.sleep(1000);
  39. } catch (InterruptedException e) {
  40. e.printStackTrace();
  41. }
  42. txt.setText("Times Clicked: " + count + " Time Left: " + time);
  43. }
  44. button1.setEnabled(false);
  45. finalTxt.setText("Final Score: " + count );
  46. }
  47.  
  48. @Override
  49. public void initAllObjects(List<Visible> viewObjects) {
  50. txt = new TextArea(250,100,250,200, "Times Clicked: " + count + " Time Left: " + time);
  51. button1 = new Button(100,100,100,100, "Click", new Action() {
  52.  
  53. @Override
  54. public void act() {
  55. count++;
  56. txt.setText("Times Clicked: " + count + " Time Left: " + time);
  57. }
  58.  
  59. });
  60. finalTxt = new TextArea(250,400,100,100, "");
  61. viewObjects.add(button1);
  62. viewObjects.add(txt);
  63. viewObjects.add(finalTxt);
  64. }
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement