Skip to content

#08.2 Checkbox

Valkryst edited this page Nov 10, 2017 · 16 revisions

Create a Checkbox

import com.valkryst.VTerminal.Panel;
import com.valkryst.VTerminal.builder.PanelBuilder;
import com.valkryst.VTerminal.builder.component.CheckBoxBuilder;
import com.valkryst.VTerminal.font.Font;
import com.valkryst.VTerminal.font.FontLoader;

import java.io.IOException;
import java.net.URISyntaxException;

public class Driver {
    public static void main(final String[] args) throws IOException, URISyntaxException, InterruptedException {
        final Panel panel = new PanelBuilder().build();


        final CheckBoxBuilder checkBoxBuilder = new CheckBoxBuilder();
        checkBoxBuilder.setPosition(10, 10);
        checkBoxBuilder.setText("Click Me");

        panel.addComponents(checkBoxBuilder.build());


        Thread.sleep(50);

        panel.draw();
    }
}

Code Explanation

final CheckBoxBuilder checkBoxBuilder = new CheckBoxBuilder();

Constructs a new CheckBoxBuilder. You can view the documentation here.

You can reuse the builder, so you won't need to create a new CheckBoxBuilder every time you want to create a new check box.


checkBoxBuilder.setPosition(10, 10);

This tells the builder to place the check box at position (10x, 10y).


checkBoxBuilder.setText("Click Me");

This sets the text on the check box, so this check box will display "Click Me".


panel.addComponents(checkBoxBuilder.build());

This builds the check box and adds it to the panel.

Result

Clone this wiki locally