Getting Started
Starter Template and an Example Program for javaDraw
Now that we have javaDraw installed, we can write a base program:
import javadraw.*;
public class Program extends Window {
public static void main(String[] args) {
Window.open();
}
public void start() {
// Code goes here!
}
}
Note that animation is as simple as adding a while loop to the start method!
boolean running = true;
boolean fps = 30;
while (running) {
screen.update();
screen.sleep(1 / fps);
}
Now we can go ahead and add some shapes:
import javadraw.*;
public class ExampleProgram extends Window {
public static void main(String[] args) {
Window.open();
}
public void start() {
Rectangle rect = new Rectangle(screen, 50, 50, 50, 50);
Triangle triangle = new Triangle(screen, 150, 150, 50, 50);
Oval circle = new Oval(screen, 250, 250, 50, 50);
Polygon hexagon = new Polygon(screen, 6, 350, 350, 50, 50);
}
}
And it should produce the following program output:

Last modified 2yr ago