62,614
社区成员
发帖
与我相关
我的任务
分享
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();
}
}
}
button.addMouseListener(new MouseAdapter(){ public void mouseClicked(MouseEvent e){
MessageDialog.openInformation(null,"","Hello world");
}
});