SWT问题啊 急!!!

来源:百度知道 编辑:UC知道 时间:2024/05/22 16:05:10
package com.swtdesigner;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;

public class Button {
public static void main (String [] args){
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setSize(500,500); //设置页面大小
shell.setText("SWT Application"); //设置标题
final Button button = new Button(shell, SWT.NONE);
button.addSelectionListener(new SelectionAdapter(){//加一个选择监听器
public void widgetSelected(SelectionEvent e){
MessageDialog.openInformation(shell, "", "你单击了" + button.getText() + "按钮");
}
});
button.setBounds(50, 51, 100, 25);
button.setText("确定");
shell.layout();
shell.open();
while (!shell.isDisposed()){
if(!display.readAndD

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;

是eclipse自带的包么

如果使用swt自带的Button这个类,你就不要再创建叫Button的类了,改个别的名字,或者在使用swt自带的Button时显示指明类的全名。
编译在解释final Button button = new Button(shell, SWT.NONE); 时认为这里的Button是你正在写的这个类,而这个类又没有下面提到的Button(Shell,int),setBounds(int,int,int,int),setText(String)几个方法,所以提示出错。

package com.swtdesigner;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.*;

public class Buttond {
public static void main (String [] args){
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setSize(500,500); //设置页面大小
shell.setText("SWT Application"); //设置标题
final Button button = new Button(shell, SWT.NONE);
button.addSelectionListener(new Selec