我在Eclipse中运行这个程序:
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import java.awt.Color;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class A{
/**
* 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();
final Button button = new Button(shell, SWT.NONE);
button.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
button.setForground(Color.blue);
button.setBackgrond(Color.cyan);
}
});
button.setText("button");
button.setBounds(60, 60, 120, 60);
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
}
提示这两行 button.setForeground(Color.blue);
button.setBackground(Color.cyan);
出错了,类型 Control 中的方法 setForeground(Color)对于参数(Color)不适用,请问应该怎么改才能让按钮能够响应到这个事件?
[此贴子已经被作者于2006-10-17 12:57:05编辑过]