Skip to content

Instantly share code, notes, and snippets.

@anroots
Created May 11, 2012 01:40
Show Gist options
  • Save anroots/2656972 to your computer and use it in GitHub Desktop.
Save anroots/2656972 to your computer and use it in GitHub Desktop.
An Applet that gives advice on which beverage to drink.
import java.applet.Applet;
import java.awt.*;
/**
* An Applet that gives advice on which beverage to drink.
* @author Ando Roots & Carolys K.
*/
public class Beverage extends Applet {
/**
* The main method, sets the conditions for printing output.
*/
public void paint(Graphics g) {
// Get applet's dimensions
int w = getWidth();
int h = getHeight();
// Make the background black
g.setColor(Color.black);
g.fillRect(0, 0, w, h);
// Set font
g.setFont(new Font("Helvetica", Font.BOLD, 18));
// Whatever will it be? Whatever will it be? Will it be coffee? Will it be tea?
if (Math.random() < 0.5) {
g.setColor(Color.green);
g.drawString("Have a nice cup of coffee :).", 50,50);
} else {
g.setColor(Color.orange);
g.drawString("Drink tea, it's good for you :).", 50,50);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment