Quick Start

One page summary of how to start a JWM project.

Install Dependencies

Download jwm jar using build tool or manually from maven repository:

groupIdartifactIdversion
jwmio.github.humbleUIjwm
typesio.github.humbleUItypes

E.g. for Maven it’ll look like this:

<dependency>
    <groupId>io.github.humbleui</groupId>
    <artifactId>jwm</artifactId>
    <version>0.3.1</version>
</dependency>

mvn command:

mvn dependency:get -Dartifact=io.github.humbleui:jwm:0.3.1 -Ddest=./
mvn dependency:get -Dartifact=io.github.humbleui:types:0.1.2 -Ddest=./

coursier command:

cs fetch io.github.humbleui:jwm:0.3.1
cs fetch io.github.humbleui:types:0.1.2

Download example script

wget https://raw.githubusercontent.com/HumbleUI/JWM/main/docs/GettingStarted.java

Run Example

On Windows and Linux:

java -cp jwm-0.3.1.jar:types-0.1.1.jar GettingStarted.java

On macOS, add -XstartOnFirstThread flag to java:

java -XstartOnFirstThread -cp jwm-0.3.1.jar:types-0.1.1.jar GettingStarted.java

note

types-0.1.1.jar here are from https://github.com/HumbleUI/Types. They will be included as a transitive dependency if you are using Maven or Gradle.

Step by Step

Initialize

Init JWM library:

App.init();

Creating a window

Create a window:

Window window = App.makeWindow();
window.setTitle("Hello, world!");

Set up a listener:

class EventHandler implements Consumer<Event> {
    public final Window window;

    public EventHandler(Window window) {
        this.window = window;
    }
}

Write the accept function:

@Override
public void accept(Event e) {
    System.out.println(e);

    if (e instanceof EventWindowCloseRequest) {
        window.close();
        App.terminate();
    }
}

Assign handler to the window:

window.setEventListener(new EventHandler(window));

Display the window:

window.setVisible(true);

start an event loop

Start the event loop (will block the thread):

App.start();

See it all together in GettingStarted.java.