> For the complete documentation index, see [llms.txt](https://easy-draw.joemazzone.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://easy-draw.joemazzone.net/java/starter-template.md). Agents can also search and read this documentation through its [MCP server](https://easy-draw.joemazzone.net/~gitbook/mcp).

# Starter Template

To start drawing with Easy Draw, all you need is two method calls inside `main`. It is that easy!

```java
// Learn how to use Easy Draw!
// https://easy-draw.joemazzone.net/java/module-reference

public class Main {
    public static void main(String[] args) {
        EasyDraw.loadCanvas();    // Always start your program with this

        // --- Your main program below here ---



        // --- Your main program ends here ---

        EasyDraw.end();           // Always end your program with this
    }
}
```

When you run the program above, Easy Draw opens your drawing in your web browser at <http://localhost:8765/>.

Easy Draw also writes your drawing to an `index.html` file in the folder you run your program from. Open `index.html` any time to see your drawing again.

{% hint style="info" %}
While your program is running, clicks, mouse movement, and key presses in the browser are sent to your event handlers. The badge in the top-right corner of the page says **Live** when the page is connected to your program and **Offline** when it is not.

Close the browser tab (or press Ctrl+C) to stop your program.
{% endhint %}

The Java version uses the same Easy Draw page as the Python version:

![The Easy Draw page in a web browser](https://651142499-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MRAMSGwqRIdQ2ADsTkz%2Fuploads%2F0FH3GcROqAGhldKd0USi%2Feasy-draw-browser.webp?alt=media)

#### Features of the Easy Draw page:

1. **Grid** - Turns a grid on and off, with a line every 50 pixels and numbers along the top and left side of the canvas.
2. **Coordinates** - The bottom-right corner of the page shows the x, y coordinates of your mouse as you move it around the canvas.
3. **Color Picker** - Choose a color and the page shows its hex and RGB values to use in your program.
4. **Save Canvas** - Downloads your drawing as a PNG file.

## A First Drawing

```java
public class Main {
    public static void main(String[] args) {
        EasyDraw.loadCanvas();

        EasyDraw.Rectangle square = new EasyDraw.Rectangle(100, 100, 200, 200);
        square.setColor("red");
        square.eventSetup("<Button-1>", event -> square.rotate(10));

        EasyDraw.end();
    }
}
```

This draws a red square. Click it and it turns 10 degrees.
