62,614
社区成员
发帖
与我相关
我的任务
分享
/*
* Created on July 10 2008
*
* Copyright by 布谷鸟
*/
package swt;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
/**
*
* @author cuckoo
*
*/
public class RefreshTry {
public static void main(String args[]) {
new RefreshTry().createShell();
}
private void createShell() {
_shell = new Shell(_display, SWT.MIN);
_shell.setSize(300, 200);
_shell.setText("Refresh Contents");
createContents();
_shell.open();
while (!_shell.isDisposed()) {
if (!_display.readAndDispatch()) {
_display.sleep();
}
}
_display.dispose();
}
private void createContents() {
final Button button = new Button(_shell, SWT.PUSH);
button.setBounds(2, 2, 100, 20);
button.setText("Click me");
displayLabel = new Label(_shell, SWT.SHADOW_IN);
displayLabel.setText("Default ....");
displayLabel.setBounds(10, 50, 40, 20);
_methodLabel = new Label(_shell, SWT.SHADOW_ETCHED_OUT);
_methodLabel.setBackground(new Color(_display, 0, 0, 0));
_methodLabel.setForeground(new Color(_display, 140, 140, 140));
_methodLabel.setBounds(120, 50, 100, 15);
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
// TODO Auto-generated method stub
displayLabel.setBounds(10, 50, 40, 40);
displayLabel.setText("");
displayLabel
.setBackgroundImage(new Image(_display, "89_m.bmp"));
// sleep one minutes
processThread();
}
});
}
private void processThread() {
Thread thread = new Thread() {
public void run() {
// TODO Auto-generated method stub
_display.asyncExec(new Runnable() {
public void run() {
// TODO Auto-generated method stub
int i = 0;
while (i <= 30) {
if (i != 30) {
_methodLabel.setText("当前值为: " + i);
} else {
if (i == 30) {
_methodLabel
.setText("方法调用结束 ");
Image image = new Image(_display,
"89_m.bmp");
displayLabel.setBackgroundImage(image);
displayLabel.setSize(
image.getBounds().width, image
.getBounds().height);
}
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
i ++ ;
}
}
});
}
};
thread.start();
}
private Shell _shell = null;
private Label _methodLabel = null;
private Label displayLabel = null;
private Display _display = Display.getDefault();
}