SWT Application Window 的问题

edsion 2006-08-22 10:35:41
我在新建了SWT Application Window
想给TEXT 加一个addMouseListener

但是有错误
我是按照eclipse从入门到精通的例子

我的 代码是这样的
/*
* Created on 2006-8-22
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.swtdesigner;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

/**
* @author Administrator
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class Test {

private static Text helloText;
/**
* 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("SWT Application");
//

shell.open();

helloText = new Text(shell, SWT.BORDER);
helloText.addMouseListener(new myTextMouseListener());

helloText.setText("Hello");
//helloText.set
helloText.setBounds(171, 103, 95, 24);
// text.set
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
private static final class myTextMouseListener extends MouseAdapter {
public void MouseDoubleClick(MouseEvent e)
{
MessageDialog.openInformation(null,"","fdsfsadfas");
}
}
}


helloText.addMouseListener(new myTextMouseListener());
eclipse 提示错误
The method addMouseListener(MouseListener) in the type Control is not applicable for the
arguments (Test.myTextMouseListener)



...全文
179 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
java_ER 2006-08-23
  • 打赏
  • 举报
回复
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

不要IMPORT AWT的事件.试试IMPORT org.eclipse.swt.events.*;

private static final class myTextMouseListener extends MouseAdapter {
public void MouseDoubleClick(MouseEvent e)
{
MessageDialog.openInformation(null,"","fdsfsadfas");
SWT中有自己的事件处理机制.还是用SWT自己的吧.你那样用混乱了.
zhmt 2006-08-23
  • 打赏
  • 举报
回复
路过,友情up...

58,454

社区成员

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

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