求教啊,着是为什么啊

joyceanxu 2011-07-26 04:53:33
import org.eclipse.swt.events.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Text;

class helloworld {

public static void main(String[] args) {
// TODO Auto-generated method stub
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setSize(327, 253);
shell.setText("linux");
Text text = new Text(shell, SWT.BORDER);
Button button = new Button(shell, SWT.BUTTON1);
button.setBounds(100, 100, 70, 70);
text.addMouseListener(new MouseAdapter(){
public void mouseDoubleClick(MouseEvent E){
MessageDialog.openInformation(null,"","window");
}
});
text.setText("helloworld");
text.setBackground(null);
text.setBounds(200, 166, 100, 100);
shell.layout();
shell.open();
while(!shell.isDisposed()){
if(!display.readAndDispatch())
display.sleep();
}

}
}

报错:MouseAdapter cannot be resolved to a type
...全文
45 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
huntor 2011-07-26
  • 打赏
  • 举报
回复
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class World {

public static void main(String[] args) {
// TODO Auto-generated method stub
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setSize(327, 253);
shell.setText("linux");
Text text = new Text(shell, SWT.BORDER);
Button button = new Button(shell, SWT.BUTTON1);
button.setBounds(100, 100, 70, 70);
text.addMouseListener(new MouseAdapter(){
public void mouseDoubleClick(MouseEvent E){
MessageBox mbox = new MessageBox(shell);
mbox.setMessage("window");
mbox.open();
}
});
text.setText("helloworld");
text.setBackground(null);
text.setBounds(200, 166, 100, 100);
shell.layout();
shell.open();
while(!shell.isDisposed()){
if(!display.readAndDispatch())
display.sleep();
}

}
}

swt-3.7-gtk-linux-x86 + 6u26 通过。
来到我身边 2011-07-26
  • 打赏
  • 举报
回复
在代码中你用到了监听器MouseListener,所以必须导入其所在的包,
很有可能是由于类MouseAdapter所在的包没有导入,尝试一下吧!
zn85600301 2011-07-26
  • 打赏
  • 举报
回复
MouseAdapter 是不是没导入需要支持的jar包
joyceanxu 2011-07-26
  • 打赏
  • 举报
回复
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method addMouseListener(MouseListener) in the type Control is not applicable for the arguments (new MouseAdapter(){})
MouseEvent cannot be resolved to a type
MessageDialog cannot be resolved

at helloworld.main(helloworld.java:32)
皮皮 2011-07-26
  • 打赏
  • 举报
回复
import java.awt.event.MouseAdapter;
import java.awt.event.MouseListener;

要用这两个包。

58,452

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧