1
你好,這是我的第一篇文章,我正在盡我所能學習編程! 我想在Eclipse中用SWT製作一個程序。 這是一個基本程序,應該從用戶接收輸入,並根據(if
語句)在用戶輸入的哪一天顯示某個輸出。如何處理輸入?
問題:我第一次嘗試將if
語句放在文本字段下,但我注意到我需要某種按鈕來使這個運行,否則它不起作用!
哪裏是使輸入的錯誤:Dilluns
不輸出:MATESSS!
?
public void open() {
Display display = Display.getDefault();
createContents();
elsllibres.open();
elsllibres.layout();
while (!elsllibres.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
protected void createContents() {
elsllibres = new Shell();
elsllibres.setSize(450, 300);
elsllibres.setText("OSKARITOOO Industries");
Label lblQuinsLlibresCal = new Label(elsllibres, SWT.NONE);
lblQuinsLlibresCal.setBounds(10, 10, 360, 15);
lblQuinsLlibresCal.setText("QUINS LLIBRES CAL PORTAR AVUI?");
Label lblIndicaElDia = new Label(elsllibres, SWT.NONE);
lblIndicaElDia.setBounds(10, 31, 96, 15);
lblIndicaElDia.setText("INDICA EL DIA:");
text_1 = new Text(elsllibres, SWT.BORDER);
text_1.setText("EX: Dilluns, Dimarts...");
text_1.setBounds(10, 52, 123, 21);
Label info = new Label(elsllibres, SWT.NONE);
info.setBounds(10, 79, 174, 15);
info.setText("Cal portar els llibres de...");
resultat = new Label(elsllibres, SWT.NONE);
resultat.setBounds(10, 100, 207, 15);
Button ok = new Button(elsllibres, SWT.NONE);
ok.addTouchListener(new TouchListener() {
public void touch(TouchEvent arg0) {
String quediaes;
quediaes = text_1.toString();
if(quediaes.equals("Dilluns")){
resultat.setText("MATESSSS!");
}
}
});
ok.setBounds(142, 48, 75, 25);
ok.setText("OK");
text_1.addMouseTrackListener(new MouseTrackAdapter() {
@Override
public void mouseEnter(org.eclipse.swt.events.MouseEvent e) {
text_1.setText("");
}
});
}
這不是Swing。它的SWT。 – camickr
upsitubsy!我很困惑對不起 – oscar6662
在這種情況下,我很抱歉,我批准了一個編輯替換SWT標記與擺動。相反,標題和文本應該已經改爲閱讀SWT。這太快了。 –