在线等,简单的java程序,有个小小的问题

Mr__lonely 2008-09-05 10:01:45
package com.swtdesigner;

import java.awt.*;
import java.awt.event.*;

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

public class HelloWorld {

private static Group group;
private static Button check2Button;
private static Button check1Button;
private static Button button;
private static Text helloworldText;
/**
* Launch the application
* @param args
*/
public static void main(String[] args) {
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setSize(514, 375);
shell.setText("SWT Application");
//

shell.open();



helloworldText = new Text(shell, SWT.BORDER);

helloworldText.setText("helloworld");
helloworldText.setBounds(129, 42, 80, 25);



button = new Button(shell, SWT.NONE);
button.addMouseListener(new MouseAdapter(){ //错误在这一行addMouseListener下画了红线,有问题
public void mouseClicked(MouseEvent e){
MessageDialog.openInformation(null,"","Hello world");
}
});
button.setText("确定");
button.setBounds(141, 211, 80, 25);

group = new Group(shell, SWT.NONE);
group.setBounds(129, 113, 111, 70);

check1Button = new Button(group, SWT.CHECK);
check1Button.setBounds(10, 21,93, 16);
check1Button.setText("check1");

check2Button = new Button(group, SWT.CHECK);
check2Button.setBounds(10, 43,93, 16);
check2Button.setText("check2");
shell.setTabList(new Control[] {helloworldText, button, group});
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}

}

...全文
55 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
oyhj_nicholas 2008-09-05
  • 打赏
  • 举报
回复
可能是Button不能添加MouseEvent的事件的监听器吧
换成 Button.addActionListener试试
Mr__lonely 2008-09-05
  • 打赏
  • 举报
回复
button.addMouseListener(new MouseAdapter(){               public void mouseClicked(MouseEvent e){
MessageDialog.openInformation(null,"","Hello world");
}
});

这里有问题吗,提示说"类型 Control 中的方法 addMouseListener(MouseListener)对于参数(new
MouseAdapter(){})不适用"什么意思啊?

62,614

社区成员

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

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