高分求一SWT编译不通过

a156435646 2012-09-02 07:04:16
package edu.ch4;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.*;
public class Jiemian extends Shell {

protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}

public Jiemian(Display display)
{
super(display, SWT.SHELL_TRIM);



Label lb1=new Label(this,SWT.NONE);

lb1.setText("请输入姓名:");
lb1.setBounds(20,50,70,20);
final Text text1=new Text(this,SWT.BORDER);
text1.setBounds(100,49,70,20);

Label lb2=new Label(this,SWT.NONE);

lb2.setText("请输入年龄:");
lb2.setBounds(20,100,70,20);
final Text text2=new Text(this,SWT.BORDER);
text2.setBounds(100,100,70,20);
Button bt=new Button(this,SWT.NONE);
bt.setBounds(20,150,70,20);
bt.setText("确定");

bt.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e){
MessageBox dialog=new MessageBox(this,SWT.OK|SWT.ICON_INFORMATION);
dialog.setText("组件选择事件");
dialog.setMessage("您的姓名是:"+text1.getText()+"您的年龄是:"+text2.getText());
dialog.open();
}
});

Button bt1=new Button(this,SWT.NONE);
bt1.setBounds(100,150,70,20);
bt1.setText("重置");

bt1.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e){
text1.setText("");
text2.setText("");

}
}
);


}
public static void main(String[] args)
{


Display display = Display.getDefault();
final Jiemian shell=new Jiemian(display);
shell.setText("系统登录");
shell.setSize(300, 300);
shell.layout();


shell.open();
while(!shell.isDisposed())
{
display.sleep();
if(!display.readAndDispatch())
{

}
}

display.dispose();
}


}


里面的MessageBox dialog=new MessageBox(this,SWT.OK|SWT.ICON_INFORMATION);


提示构造函数 MessageBox(new SelectionAdapter(){}, int)未定义
...全文
106 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
a156435646 2012-09-02
  • 打赏
  • 举报
回复
谢谢,CSDN就是靠你们这些高手了。。。给分谢谢。。
scbb 2012-09-02
  • 打赏
  • 举报
回复
改成

MessageBox dialog=new MessageBox(Jiemian.this, SWT.OK|SWT.ICON_INFORMATION);

因为你的代码写在了new SelectionAdapter里,光写this表示SelectionAdapter的地址。

62,621

社区成员

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

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