swt中窗口加载的事件
我在一个窗口上放了一个label和一个进度条,我想在窗口启动的时候,进度条的进度也随之慢慢改变,可是我运行之后进度条去不对,代码如下,请大侠指教importorg.ecl...
我在一个窗口上放了一个label和一个进度条,我想在窗口启动的时候,进度条的进度也随之慢慢改变,可是我运行之后进度条去不对,代码如下,请大侠指教
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.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Shell;
import com.swtdesigner.SWTResourceManager;
public class Main1 {
public static void main(String[] args) {
Display display = Display.getDefault();
Shell shell = new Shell();
shell.setBounds(50, 50, 682, 600);
shell.open();
final Label label = new Label(shell, SWT.NONE);
label.setText("Label");
final Label label_1 = new Label(shell, SWT.NONE);
label_1.setFont(SWTResourceManager.getFont("", 36, SWT.NONE));
label_1.setText("欢迎使用书店进销存管理系统");
label_1.setBounds(28, 146, 636, 69);
final ProgressBar progressBar = new ProgressBar(shell, SWT.NONE);
progressBar.setBounds(105, 395, 449, 17);
shell.addShellListener(new ShellAdapter() {
public void shellActivated(ShellEvent e) {
for(int i=1;i<11;i++){
progressBar.setSelection(i*10);
try {
Thread.sleep(1000);
}catch(Throwable t){
t.printStackTrace();
}
}
}
});
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
} 展开
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.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Shell;
import com.swtdesigner.SWTResourceManager;
public class Main1 {
public static void main(String[] args) {
Display display = Display.getDefault();
Shell shell = new Shell();
shell.setBounds(50, 50, 682, 600);
shell.open();
final Label label = new Label(shell, SWT.NONE);
label.setText("Label");
final Label label_1 = new Label(shell, SWT.NONE);
label_1.setFont(SWTResourceManager.getFont("", 36, SWT.NONE));
label_1.setText("欢迎使用书店进销存管理系统");
label_1.setBounds(28, 146, 636, 69);
final ProgressBar progressBar = new ProgressBar(shell, SWT.NONE);
progressBar.setBounds(105, 395, 449, 17);
shell.addShellListener(new ShellAdapter() {
public void shellActivated(ShellEvent e) {
for(int i=1;i<11;i++){
progressBar.setSelection(i*10);
try {
Thread.sleep(1000);
}catch(Throwable t){
t.printStackTrace();
}
}
}
});
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
} 展开
展开全部
public class Main1
{
public static void main(String[] args)
{
Display display = Display.getDefault();
Shell shell = new Shell();
shell.setBounds(50, 50, 682, 600);
shell.open();
final Label label = new Label(shell, SWT.NONE);
label.setText("Label");
final Label label_1 = new Label(shell, SWT.NONE);
label_1.setFont(SWTResourceManager.getFont("", 36, SWT.NONE));
label_1.setText("欢迎使用书店进销存管理系统");
label_1.setBounds(28, 146, 636, 69);
final ProgressBar progressBar = new ProgressBar(shell, SWT.NONE);
progressBar.setBounds(105, 395, 449, 17);
shell.layout();
shell.getDisplay().asyncExec(new Runnable(){
public void run()
{
System.out.println("dddd");
for(int i = 1; i < 11; i++)
{
progressBar.setSelection(i * 10);
try
{
Thread.sleep(1000);
}
catch (Throwable t)
{
t.printStackTrace();
}
}
}
});
// shell.addShellListener(new ShellAdapter()
// {
//
// public void shellActivated(ShellEvent e)
// {
// System.out.println("dddd");
// for(int i = 1; i < 11; i++)
// {
// progressBar.setSelection(i * 10);
// try
// {
// Thread.sleep(1000);
// }
// catch (Throwable t)
// {
// t.printStackTrace();
// }
// }
//
// }
//
// });
while(!shell.isDisposed())
{
if(!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
{
public static void main(String[] args)
{
Display display = Display.getDefault();
Shell shell = new Shell();
shell.setBounds(50, 50, 682, 600);
shell.open();
final Label label = new Label(shell, SWT.NONE);
label.setText("Label");
final Label label_1 = new Label(shell, SWT.NONE);
label_1.setFont(SWTResourceManager.getFont("", 36, SWT.NONE));
label_1.setText("欢迎使用书店进销存管理系统");
label_1.setBounds(28, 146, 636, 69);
final ProgressBar progressBar = new ProgressBar(shell, SWT.NONE);
progressBar.setBounds(105, 395, 449, 17);
shell.layout();
shell.getDisplay().asyncExec(new Runnable(){
public void run()
{
System.out.println("dddd");
for(int i = 1; i < 11; i++)
{
progressBar.setSelection(i * 10);
try
{
Thread.sleep(1000);
}
catch (Throwable t)
{
t.printStackTrace();
}
}
}
});
// shell.addShellListener(new ShellAdapter()
// {
//
// public void shellActivated(ShellEvent e)
// {
// System.out.println("dddd");
// for(int i = 1; i < 11; i++)
// {
// progressBar.setSelection(i * 10);
// try
// {
// Thread.sleep(1000);
// }
// catch (Throwable t)
// {
// t.printStackTrace();
// }
// }
//
// }
//
// });
while(!shell.isDisposed())
{
if(!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询