#08.2 Checkbox - Valkryst/VTerminal GitHub Wiki

import com.valkryst.VTerminal.Screen;
import com.valkryst.VTerminal.builder.CheckBoxBuilder;

import java.io.IOException;

public class Driver {
    public static void main(final String[] args) throws IOException {
        final Screen screen = new Screen();
        screen.addCanvasToFrame();

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

        screen.addComponent(checkBoxBuilder.build());
        screen.draw();
    }
}

Code Explanation

final CheckBoxBuilder checkBoxBuilder = new CheckBoxBuilder();

Constructs a new CheckBoxBuilder.

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".


screen.addComponent(checkBoxBuilder.build());

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


screen.draw();

This redraws the screen, to show the newly added check box.

Result