Skip to content

#08.2 Checkbox

Valkryst edited this page Aug 21, 2017 · 16 revisions

Create a Button

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 Font font = FontLoader.loadFontFromJar("Fonts/DejaVu Sans Mono/20pt/bitmap.png",
                "Fonts/DejaVu Sans Mono/20pt/data.fnt",
                1);

        final PanelBuilder builder = new PanelBuilder();
        builder.setFont(font);
        final Panel panel = builder.build();


        final CheckBoxBuilder checkBoxBuilder = new CheckBoxBuilder();
        checkBoxBuilder.setRadio(panel.getRadio());
        checkBoxBuilder.setColumnIndex(10);
        checkBoxBuilder.setRowIndex(10);
        checkBoxBuilder.setText("Click Me");

        panel.addComponent(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.setRadio(panel.getRadio());

This is a required setter for every component. A component sends a message to the radio saying "Redraw me!" whenever it needs to be redrawn, so the radio should always be set to the radio of the panel on which the button is placed.


checkBoxBuilder.setColumnIndex(10);
checkBoxBuilder.setRowIndex(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.addComponent(checkBoxBuilder.build());

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

Result

Clone this wiki locally