免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 3292 | 回复: 16
打印 上一主题 下一主题

[求助]Eclipse的SWT问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-07-12 14:30 |只看该作者 |倒序浏览
我是初学Eclipse,现在碰到一个问题:用SWT建了一个文件框和按扭,功能是文本框只能输入数字,如果文本框有内容则提示通过,否则提示输入,现在文本框内容没问题,但是按扭事件不能执行,按扭代码如下:
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,"","输入值通过检证" );
                          }
                });
错误提示是:从不以本地方式使用类型new SelectionAdapter(){}中的方法widgetSelected(SelectionEvent)
我是安照《Eclipse从入门到精通》这本书的例子做的,谁知道告诉我一下,感激不尽~~!!

论坛徽章:
0
2 [报告]
发表于 2006-07-12 14:53 |只看该作者
1. text 要是类变量或者是final变量
2.错误信息是什么? 从不以本地方式使用类型new SelectionAdapter(){}中的方法widgetSelected(SelectionEvent)
怎么看不懂?

论坛徽章:
0
3 [报告]
发表于 2006-07-12 15:11 |只看该作者
我执行后没有错误提示,运行后按扭事件没有触发,按它没有反应,只是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();
                }
        }

}

论坛徽章:
0
4 [报告]
发表于 2006-07-12 15:19 |只看该作者
public void widgetSelected(SelectionEvent e){
                                String str=text.getText();
                                if(str==null||str.equals(""))
                                        MessageDialog.openWarning(shell,"","请输入一个字符");
                                else
                                        MessageDialog.openInformation(shell,"","输入值通过检证");

设置个断点debug一下,应该是这里某处抛异常了

论坛徽章:
0
5 [报告]
发表于 2006-07-12 15:29 |只看该作者
能祥细讲讲它的操作好吗,我是个新手,刚学习没多久,很多不知道的,万分感谢~~~!

论坛徽章:
0
6 [报告]
发表于 2006-07-12 15:36 |只看该作者
啊,那个,设个断点,运行,查看变量值,基本的debug流程,自己多摸索一下

论坛徽章:
0
7 [报告]
发表于 2006-07-12 15:38 |只看该作者
我用是eclipse工具的,但是我执行一点错误提示都没有,怎么捕捉异常呀?

论坛徽章:
0
8 [报告]
发表于 2006-07-12 15:45 |只看该作者
1.使用debug模式运行你的程序。
2.查看控制台是否有异常抛出,没有捕捉的异常最终都是会从main抛出的

论坛徽章:
0
9 [报告]
发表于 2006-07-12 15:53 |只看该作者
唉,烦恼。。。 我用调试模试还是什么都没有。。 你现有有时间吗,我想用QQ远控让你看下我的Eclipse内容,实在不好意思~

论坛徽章:
0
10 [报告]
发表于 2006-07-12 15:57 |只看该作者
原帖由 shifangyan 于 2006-7-12 16:53 发表
唉,烦恼。。。 我用调试模试还是什么都没有。。 你现有有时间吗,我想用QQ远控让你看下我的Eclipse内容,实在不好意思~


调试模式运行后给一行代码加个断点,就是双击左边空白处,然后用鼠标一划某个变量就可以看它的值了。工作中,不能上QQ,慢慢来,还不太熟悉eclipse的缘故
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP