Skip to content

Creating a simple page

MrLetsplay edited this page Sep 19, 2021 · 2 revisions

Creating the page

Pages can be created creating a class that extends WebinterfacePage, e.g.:

package com.example.webinterface;

import me.mrletsplay.webinterfaceapi.webinterface.page.WebinterfacePage;

public class ExamplePage extends WebinterfacePage {

    public ExamplePage() {
        super("/example/page" /* Path */, "Example Page" /* Name */);
    }

}

The page currently does not contain any content though, making it rather useless. To add content, we first need to create a WebinterfacePageSection to hold it:

// Inside the constructor

WebinterfacePageSection s = new WebinterfacePageSection();

// We can add a title to our section
s.addTitle("Section");

// Let's add some elements to it
// Most elements have a builder, making it easier to add objects without having a bunch of temporary variables
s.addElement(WebinterfaceText.builder()
    .text("Hello World!")
    .centered());

// Don't forget to add the section to the page
addSection(s);

Finally, we need to actually register the page in the Webinterface. We can do so in our main method:

public static void main(String[] args) {
    Webinterface.registerPage(new ExamplePage());
    Webinterface.start(); // Start the webinterface. By default it will use port 8880
}

Layout

TODO

Dynamic Content

TODO

Clone this wiki locally