- 论坛徽章:
- 0
|
我执行后没有错误提示,运行后按扭事件没有触发,按它没有反应,只是Eclipse代码行旁边有个黄点提示,我能整个代码贴出来给你看下
import org.apache.xalan.trace.SelectionEvent;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.events.VerifyListener;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import com.swtdesigner.SWTResourceManager;
public class MyWork {
private static Text text;
/**
* Launch the application
* @param args
*/
public static void main(String[] args) {
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setSize(500, 375);
shell.setText("实验窗口");
//
shell.open();
text = new Text(shell, SWT.BORDER);
text.setForeground(SWTResourceManager.getColor(255, 0, 0));
text.setBounds(168, 144, 120, 30);
text.addVerifyListener(new VerifyListener(){
public void verifyText(VerifyEvent e) {
// TODO 自动生成方法存根
boolean b=("0123456789".indexOf(e.text)>=0);
e.doit=b;
}
});
final Button button = new Button(shell, SWT.BORDER);
button.setText("确定");
button.setBounds(72, 239, 120, 30);
button.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e){
String str=text.getText();
if(str==null||str.equals(""))
MessageDialog.openWarning(shell,"","请输入一个字符");
else
MessageDialog.openInformation(shell,"","输入值通过检证");
}
});
final Button button_1 = new Button(shell, SWT.BORDER);
button_1.setData("newKey", null);
button_1.setText("退出");
button_1.setBounds(295, 239, 120, 30);
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
} |
|