Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package clickProject;
- import java.awt.Color;
- import guiTeacher.GUIApplication;
- public class Click extends GUIApplication{
- public Click(int width, int height) {
- super(width, height);
- setVisible(true);
- }
- @Override
- public void initScreen() {
- WinScreen screen = new WinScreen(getWidth(), getHeight());
- setScreen(screen);
- }
- public static void main(String[] args) {
- Click game = new Click(800, 500);
- game.setLocationRelativeTo(null);
- Thread runner = new Thread(game);
- runner.start();
- }
- }
- package clickProject;
- import java.awt.Color;
- import java.util.List;
- import guiTeacher.components.Action;
- import guiTeacher.components.Button;
- import guiTeacher.components.TextLabel;
- import guiTeacher.interfaces.Visible;
- import guiTeacher.userInterfaces.FullFunctionScreen;
- public class ClickScreen extends FullFunctionScreen {
- private Button button;
- private TextLabel text;
- private TextLabel time;
- private boolean ready;
- private int score;
- private boolean over;
- public ClickScreen(int width, int height) {
- super(width, height);
- Thread app = new Thread();
- ready = false;
- score = 0;
- over = false;
- app.start();
- // TODO Auto-generated constructor stub
- }
- @Override
- public void initAllObjects(List<Visible> viewObjects) {
- // TODO Auto-generated method stub
- button = new Button(220, 50, 50, 50, "Ready",Color.red, null);
- button.setAction(new Action() {
- @Override
- public void act() {
- // TODO Auto-generated method stub
- Thread t = new Thread(new Runnable() {
- @Override
- public void run() {
- if(ready) {
- clickme();
- } else {
- countr();
- button.setEnabled(false);
- }
- }
- });
- t.start();
- }
- private void clickme() {
- Thread t = new Thread(new Runnable() {
- @Override
- public void run() {
- // TODO Auto-generated method stub
- if(!over) {
- score++;
- text.setText(Integer.toString(score));
- }
- }
- });
- t.start();
- }
- });
- viewObjects.add(button);
- text = new TextLabel(220, 200, 100, 100, "");
- viewObjects.add(text);
- time = new TextLabel(220,300,100,100,"");
- viewObjects.add(time);
- }
- public void run() {
- }
- public void countr() {
- ready = true;
- Thread t = new Thread(new Runnable() {
- @Override
- public void run() {
- // TODO Auto-generated method stub
- try {
- for(int i = 3; i >= 1; i--) {
- text.setText(i + "...");
- Thread.sleep(1000);
- }
- text.setText("GO!!");
- button.setText("CLICK ME!");
- button.setEnabled(true);
- for(int i = 5; i >= 1; i--) {
- time.setText(Integer.toString(i) + " seconds left..");
- Thread.sleep(1000);
- }
- time.setText("TIMES UP!");
- over = true;
- }catch(InterruptedException e) {
- e.printStackTrace();
- }
- }
- });
- t.start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement