1

到目前为止我有

Terminal terminal = new DefaultTerminalFactory().createTerminal();
TerminalScreen screen = new TerminalScreen(terminal);
MultiWindowTextGUI mwtg = new MultiWindowTextGUI​(screen);

CheckBoxList checkBoxList = new CheckBoxList<String>();
checkBoxList.addItem("Check one");
checkBoxList.addItem("Check two");

我想不通的是如何checkBoxList直接添加到mwtg

非常感谢您的帮助

4

1 回答 1

1

好的,所以在盲目地通过 API 胡乱猜测了几个小时之后,我做到了这一点,它有效,但可能很笨重或有异味,所以请随时改进我自己的答案。

private MultiWindowTextGUI mwtg;
private BasicWindow bw;
private CheckBoxList<String> checkBoxList;
private List<String> ckeckedItems;
Terminal terminal = new DefaultTerminalFactory().createTerminal();
TerminalScreen screen = new TerminalScreen(terminal);
MultiWindowTextGUI mwtg = new MultiWindowTextGUI​(screen);
this.checkBoxList = new CheckBoxList<String>();
this.checkBoxList.addItem("item1");
this.checkBoxList.addItem("item2");
this.checkBoxList.addItem("item3");
this.checkBoxList.addListener((sel, prev) ->
    { this.ckeckedItems = this.checkBoxList.getCheckedItems​(); }
);
Panel panel = new Panel();
panel.setLayoutManager(new GridLayout(4));
panel.addComponent(this.checkBoxList);
Button button = new Button("Done", () -> this.bw.close());
button.addTo​(panel);
this.bw = new BasicWindow("Choices");
this.bw.setComponent(panel);
this.mwtg.addWindowAndWait(this.bw);

我希望这可能对某人有用...

于 2020-07-20T01:56:57.333 回答