Skip to content

#08.2 Checkbox

Valkryst edited this page Feb 9, 2018 · 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 {
        final Font font = FontLoader.loadFontFromJar("Fonts/DejaVu Sans Mono/18pt/bitmap.png", "Fonts/DejaVu Sans Mono/18pt/data.fnt", 1);

        final PanelBuilder panelBuilder = new PanelBuilder();
        panelBuilder.setFont(font);

        final Panel panel = panelBuilder.build();


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

        panel.addComponents(checkBoxBuilder.build());



        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