我仍然在處理那個程序,在那裏我問了一個關於昨天的問題。在java中將文本打印到文本字段
所以我有這樣的一段代碼:
public static void main(String[] args) {
Display display = Display.getDefault();
Shell shlKoffieHalenApp = new Shell();
shlKoffieHalenApp.setMinimumSize(new Point(610, 430));
shlKoffieHalenApp.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
shlKoffieHalenApp.setSize(610, 430);
shlKoffieHalenApp.setText("Koffie Halen App");
shlKoffieHalenApp.setLayout(null);
List list = new List(shlKoffieHalenApp, SWT.BORDER);
list.setFont(SWTResourceManager.getFont("Sans", 13, SWT.BOLD));
list.setItems(new String[] {"Anne", "", "Bas", "", "Daan", "", "Nick", "", "Paul", "", "Peter", "", "Sebastien"});
list.setBackground(SWTResourceManager.getColor(SWT.COLOR_GRAY));
list.setBounds(10, 10, 113, 377);
ButtonAnne = new Button(shlKoffieHalenApp, SWT.CHECK);
ButtonAnne.setBounds(129, 17, 137, 16);
ButtonAnne.setText("Aanwezig/Afwezig");
ButtonBas = new Button(shlKoffieHalenApp, SWT.CHECK);
ButtonBas.setBounds(129, 67, 137, 16);
ButtonBas.setText("Aanwezig/Afwezig");
ButtonDaan = new Button(shlKoffieHalenApp, SWT.CHECK);
ButtonDaan.setBounds(129, 120, 137, 16);
ButtonDaan.setText("Aanwezig/Afwezig");
ButtonNick = new Button(shlKoffieHalenApp, SWT.CHECK);
ButtonNick.setBounds(129, 173, 137, 16);
ButtonNick.setText("Aanwezig/Afwezig");
ButtonPaul = new Button(shlKoffieHalenApp, SWT.CHECK);
ButtonPaul.setBounds(129, 224, 137, 16);
ButtonPaul.setText("Aanwezig/Afwezig");
ButtonPeter = new Button(shlKoffieHalenApp, SWT.CHECK);
ButtonPeter.setBounds(129, 276, 137, 16);
ButtonPeter.setText("Aanwezig/Afwezig");
ButtonSebastien = new Button(shlKoffieHalenApp, SWT.CHECK);
ButtonSebastien.setBounds(129, 329, 137, 16);
ButtonSebastien.setText("Aanwezig/Afwezig");
ButtonKoffie = new Button(shlKoffieHalenApp, SWT.NONE);
ButtonKoffie.setBounds(394, 53, 121, 34);
ButtonKoffie.setText("Klik voor koffie!");
Answer = new Text(shlKoffieHalenApp, SWT.BORDER);
Answer.setEditable(false);
Answer.getText();
Answer.setBounds(355, 106, 200, 30);
shlKoffieHalenApp.open();
shlKoffieHalenApp.layout();
while (!shlKoffieHalenApp.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
Random generate = new Random();
ArrayList<String> names = new ArrayList<String>(); {
if(ButtonAnne.getSelection() == true) {
names.add("Anne");
}
if(ButtonBas.getSelection() == true) {
names.add("Bas");
}
if(ButtonDaan.getSelection() == true) {
names.add("Daan");
}
if(ButtonNick.getSelection() == true) {
names.add("Nick");
}
if(ButtonPaul.getSelection() == true) {
names.add("Paul");
}
if(ButtonPeter.getSelection() == true) {
names.add("Peter");
}
if(ButtonSebastien.getSelection() == true) {
names.add("Sebastien");
}
if(ButtonKoffie.getSelection() == true) {
int randomIndex = generate.nextInt(names.size());
Answer.setText(names.get(randomIndex) + " moet koffie halen!");
}
}
}
}
的回答是,我想打印的隨機名稱多數民衆贊成從ArrayList中選擇了文本框。 我在這裏失蹤了什麼?我試圖創建一種方法,但沒有按計劃實施。
非常感謝!我感謝您的幫助! –