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。这太快了。 –