当前页面: 开发资料首页 → Eclipse 专题 → SWT为什么不能运行啊?
SWT为什么不能运行啊?
摘要: SWT为什么不能运行啊?
编译的时候一直提示:
---------------------------------------------------------------------------
java.lang.Error: 无法解析的编译问题:
类型 Control 中的方法 addMouseListener(MouseListener)对于参数(new MouseAdapter(){})不适用
at test.main(test.java:28)
Exception in thread "main"
------------------------------------------------------------------------------
以及:
Fatal exception occurred .program will exit.
-------------------------------------------------------------------------------
Eclipse是3.2的,SWT是5.1的
swt-win32-3232.dll这个文件我也导入了,还有什么地方要做啊??
不是提示你了嘛,
Control类的addMouseListener(MouserListener l)的参数应该是MouserListener类型
而你给传递参数的类型是MouseAdapter类型,类型不匹配。
程序如下:///////////
--------------------------------------------------------------------
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
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 test {
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();
text = new Text(shell, SWT.BORDER);
text.setText("1234,2234");
text.addMouseListener(new MouseAdapter(){
public void mouseDoubleClick(MouseEvent e){
MessageDialog.openInformation(null,"","TEST!!");}
});
text.setBounds(85, 125, 167, 67);
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
}
你的MouseAdapter类没有导入,需要import
在import org.eclipse.swt.events.MouseAdapter;之后。。终于可以正常运行了。。。
谢谢楼上的朋友^^