挺着急的,请高手帮帮忙,谢谢
我想实现单击或双击一个文本框,弹出一个对话框的效果,一个是实现了mouselistener接口,这个能运行
第二个是继承mouseadapter,这个不能运行 !
这个是能运行的代码
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class B {
private static Text text;
/**
* 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();
text = new Text(shell, SWT.BORDER);
text.setBounds(111, 222, 80, 25);
text.addMouseListener(new My());
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
private static final class My implements MouseListener{
public void mouseDoubleClick(MouseEvent arg0) {
// TODO Auto-generated method stub
MessageDialog.openInformation(null,"","HelloWorld");
}
public void mouseDown(MouseEvent arg0) {
// TODO Auto-generated method stub
}
public void mouseUp(MouseEvent arg0) {
// TODO Auto-generated method stub
}
}
}
这个是不能运行的代码:
public class H {
private static Text text;
/**
* 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();
text = new Text(shell, SWT.BORDER);
text.addMouseListener(new MyMouse());
text.setBounds(113, 200, 80, 25);
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
private static final class MyMouse extends MouseAdapter{
public void mouseClicked(MouseEvent e){
MessageDialog.openInformation(null,"",e.getSource().toString());
}
}
}
请高手给解释一下为什么,谢谢啦!
问题点数:30、回复次数:3Top
1 楼aboy85()回复于 2006-10-05 21:55:14 得分 0
没人说话?真郁闷!!!
Top
2 楼bo111()回复于 2006-10-05 23:03:34 得分 0
private static final class MyMouse extends MouseAdapter{
你用了final也能继承MouseAdapter这个吗?Top
3 楼F555666(毛主席光茫照四方!)回复于 2006-10-24 16:05:34 得分 0
顶一下,Top




