回 帖 发 新 帖 刷新版面

主题:SWTResourceManager问题,求助

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
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;


public class ButtonTest {
    private static Text text;
    public static void main(String[] args) {
        final Display display = Display.getDefault();
        final Shell shell = new Shell();
        shell.setSize(500, 375);
        shell.setText("SWT Application");
        shell.open();

        final Button okButton = new Button(shell, SWT.NONE);
        okButton.setImage([color=FF0000]SWTResourceManager[/color].getImage(ButtonTest.class, "275.jpg"));
        okButton.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                String str = text.getText();
                if (str == null || str.equals("")) {
                    MessageDialog.openInformation(shell, "", "please enter a number");
                } else {
                    MessageDialog.openInformation(shell, "", "your enter the number is true");
                }
            }
        });
        okButton.setText("OK.");
        okButton.setBounds(81, 183, 244, 54);

        text = new Text(shell, SWT.BORDER);
        text.setTextLimit(10);  //最都只能输入10个字符
        text.setBounds(70, 85, 228, 46);
        text.addVerifyListener(new VerifyListener(){//检查监听器,每输入一个字符都回触发
            public void verifyText(VerifyEvent e) {
                //检查输入字符(e.text)是否在0123456789这个字符串中,不在indexOf会返回-1
                boolean b = "0123456789".indexOf(e.text) >= 0 ;
                e.doit = b;  //doit属性如果为true,则字符允许输入,反之不允许
            }
        });

        shell.layout();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
    }
}


eclipse编辑的时候,红色部分报错,不能处理它,怎么回事哦?求助~ 这个是不是一个类?要导入什么包呢?

回复列表 (共1个回复)

沙发

baidu google搜遍了找不到,晕,还是自己解决了,做事还是要靠自己比较好,嗯嗯...
原来还真是包没有导入,菜了...嘿嘿...

SWTResourceManager类 未能被识别出
错误原因:相关包未导入
解决方法:
[Package Explorer]观察窗口中,右键打开这个项目的属性(Properties);
在跳出的对话框中,左侧,选择Java Build Path项;
右侧,选择Libraries选项卡,点击Add External JARs...按钮,添加外部包;
找到安装swt-designer插件(plugins)的文件夹,其下有一个com.swtdesigner_6.4.0的文件夹(我安装的是swt-designer6.4.0 version的,所以叫这个),打开它;
其下有个designer.jar大包文件,就是它!
导入之,OK,关键问题解决了;
然后回到Editor观察窗口,找到出错的地方,点击左边出错的灯泡,import相关包;
OK,问题解决。

我来回复

您尚未登录,请登录后再回复。点此登录或注册