Ucigame - Gallery - PushMe

Home | Getting Started | Reference | Introduction to Java | Gallery

Your browser cannot show Java applets. PushMe demonstrates buttons, alternate font choices, and putting text in sprites. Look at images/PlayButton.png to see the relationship between the image file (which contains the three button states) and what appears on the screen.

PushMe.java
import ucigame.*;

public class PushMe extends Ucigame
{
    Sprite button1;
    Sprite counter1;

    int count = 0;

    public void setup()
    {
        window.size(250, 250);
        window.title("Push Me");
        framerate(20);
        window.showFPS();

        canvas.background(50, 150, 150);

        counter1 = makeSprite(getImage("images/counter.png", 0));
        counter1.position(40, 5);
        if (isAvailableFont("Mangal"))
            counter1.font("Mangal", BOLD, 16);
        else if (isAvailableFont("Bradley Hand"))
            counter1.font("Bradley Hand", BOLD, 16);
        else
            counter1.font("Arial", BOLD, 16);

        button1 = makeButton("Play",
                             getImage("images/PlayButton.png", 0, 255, 0),
                             158, 30);

        button1.position(canvas.width()/2 - button1.width()/2,
                         canvas.height()/2 - button1.height()/2);
    }

    public void draw()
    {
        canvas.clear();

        counter1.draw();
        counter1.putText(count, 11, 13);
        button1.draw();
    }

    // called whenever the button is pressed.
    public void onClickPlay()
    {
        count++;
    }
}