我在Main外定义了JButton JProgressBar 让Swing_mainWindows里其它函数能访问.public class Swing_mainWindows {
private JButton button;
JProgressBar progressBar = new JProgressBar();
/**
* Launch the application
* @param args
*/
public static void main(String args[]) {=============================================================================
修改progressBar的百分比
public void setJProgressBar(int a){
progressBar.setValue(a);
}
下面是BUTTON的MouseClicked过程,每完成一个就增加10%,但程序运行时进度条是不会一格一格动的,只会由按了BUTTON开始到结束完成后就到100%了,我还特意用hread.sleep(1000);暂停一下主程序但依然是不动!button = new JButton("开始数据转换");
button.addMouseListener(new MouseAdapter() {
public void mouseClicked(final MouseEvent arg0) {
try {
FunctionPro com = new FunctionPro();
Collection c2 = a.getselectcheckNew(19);
setJProgressBar(10);
hread.sleep(1000);
Collection c3 = a.getselectcheckNew(20);
setJProgressBar(progressBar.getValue()+10);
Collection c = com.linkCheckTime(c2,c3);
if(c.size() <=0)
{SetActionLable("没有新数据可转换");
setJProgressBar(100);
return;}
setJProgressBar(progressBar.getValue()+10);
// CHECKTIME USERID BADGENUMBER SENSORID
//取指纹记录集合 2008-06-24 08:06:31.000 1249 01006 19
//提取所有 单独 BADGENUMBER生成List
ArrayList st = com.FPBadgen(c);
// BPEID BPECode
//xuserver83221 01006
Collection c4 = b.getMainserverSSID(com.FPBadgenStr(st));
setJProgressBar(progressBar.getValue()+10);
Thread.sleep(1000);
// BPEID KH
//xuserver1174229 40561583
Collection c5 = b.getHRSendCheckInRs();
setJProgressBar(progressBar.getValue()+10);
Thread.sleep(1000);
//合成(i+"",KH,it.getBPEID(),"","","","","");
Collection c45 = com.CountBpHrc(c4,c5);
//查找丢失的KH到C45
Collection c46 = b.getNotFoundKHList(com.FPBadgenStr(com.getFoundHkList(c45)));
Collection c47 = com.HRDocatLinkKh(c45, c46);
Collection creatPass = com.HRDocatLink(c,c47);
setJProgressBar(progressBar.getValue()+10);
Thread.sleep(1000);
if(com.InsertSource(a,b,creatPass).endsWith(""))
SetActionLable("完成转换");
setJProgressBar(100);
} catch (InterruptedException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
});
private JButton button;
JProgressBar progressBar = new JProgressBar();
/**
* Launch the application
* @param args
*/
public static void main(String args[]) {=============================================================================
修改progressBar的百分比
public void setJProgressBar(int a){
progressBar.setValue(a);
}
下面是BUTTON的MouseClicked过程,每完成一个就增加10%,但程序运行时进度条是不会一格一格动的,只会由按了BUTTON开始到结束完成后就到100%了,我还特意用hread.sleep(1000);暂停一下主程序但依然是不动!button = new JButton("开始数据转换");
button.addMouseListener(new MouseAdapter() {
public void mouseClicked(final MouseEvent arg0) {
try {
FunctionPro com = new FunctionPro();
Collection c2 = a.getselectcheckNew(19);
setJProgressBar(10);
hread.sleep(1000);
Collection c3 = a.getselectcheckNew(20);
setJProgressBar(progressBar.getValue()+10);
Collection c = com.linkCheckTime(c2,c3);
if(c.size() <=0)
{SetActionLable("没有新数据可转换");
setJProgressBar(100);
return;}
setJProgressBar(progressBar.getValue()+10);
// CHECKTIME USERID BADGENUMBER SENSORID
//取指纹记录集合 2008-06-24 08:06:31.000 1249 01006 19
//提取所有 单独 BADGENUMBER生成List
ArrayList st = com.FPBadgen(c);
// BPEID BPECode
//xuserver83221 01006
Collection c4 = b.getMainserverSSID(com.FPBadgenStr(st));
setJProgressBar(progressBar.getValue()+10);
Thread.sleep(1000);
// BPEID KH
//xuserver1174229 40561583
Collection c5 = b.getHRSendCheckInRs();
setJProgressBar(progressBar.getValue()+10);
Thread.sleep(1000);
//合成(i+"",KH,it.getBPEID(),"","","","","");
Collection c45 = com.CountBpHrc(c4,c5);
//查找丢失的KH到C45
Collection c46 = b.getNotFoundKHList(com.FPBadgenStr(com.getFoundHkList(c45)));
Collection c47 = com.HRDocatLinkKh(c45, c46);
Collection creatPass = com.HRDocatLink(c,c47);
setJProgressBar(progressBar.getValue()+10);
Thread.sleep(1000);
if(com.InsertSource(a,b,creatPass).endsWith(""))
SetActionLable("完成转换");
setJProgressBar(100);
} catch (InterruptedException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
});
楼主【jackwin】截止到2008-07-17 08:55:26的历史汇总数据(不包括此帖):
发帖的总数量:10 发帖的总分数:385 每贴平均分数:38
回帖的总数量:12 得分贴总数量:1 回帖的得分率:8%
结贴的总数量:8 结贴的总分数:325
无满意结贴数:1 无满意结贴分:30
未结的帖子数:2 未结的总分数:60
结贴的百分比:80.00 % 结分的百分比:84.42 %
无满意结贴率:12.50 % 无满意结分率:9.23 %
楼主加油
你应该把显示button监听里面的代码放到一个线程里面,监听时间里面启动线程就可以了-------------------------------------------------------------
Quietly through .....
/*
* 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();
}//这儿有段代码,不过是swt,他们理论上都是差不多的,希望对你有帮助 -------------------------------------------------------------
Quietly through .....