Longprocess.zul:
<?XML version= "1.0" encoding= "UTF-8"?><windowID=""Border= "normal"> <Buttonlabel= "Count from 1 to 10000"> <attributename= "OnClick">String url = "/progressmeter.zul"; window window = (window) executions.createcomponents (URL, null, NULL); Window.domodal (); </attribute> </Button></window>
Progressmeter.zul:
<?page title= "new page title" Contenttype= "Text/html;charset=utf-8"?><ZK><windowID= "Progresswindow"title= "Progress bar display"Border= "normal"width= "500px"Apply= "Test. Importuserprogressviewctrl "><VBox> <labelID= "Progresslabel"value= "In process, please wait patiently ..."/> <Separatorspacing= "5px" /> <ProgressmeterID= "Userprogress"width= "400px"value= "0"/></VBox></window></ZK>
Importuserprogressviewctrl.java:
Packagetest;Importorg.zkoss.zk.ui.Component;ImportOrg.zkoss.zk.ui.Desktop;Importorg.zkoss.zk.ui.Executions;ImportOrg.zkoss.zk.ui.util.GenericAutowireComposer;ImportOrg.zkoss.zul.Label;ImportOrg.zkoss.zul.Progressmeter;ImportOrg.zkoss.zul.Window; Public classImportuserprogressviewctrlextendsGenericautowirecomposer<component>{ Private Static Final LongSerialversionuid = 1L; PrivateWindow Progresswindow; PrivateProgressmeter userprogress; PrivateLabel Progresslabel; @Override Public voidDoaftercompose (Component comp)throwsException {//TODO auto-generated Method Stub Super. Doaftercompose (comp); //Start progress barDesktop.enableserverpush (true); Thread T1=NewThread (NewUserhandlethread (userprogress, Progresswindow, Progresslabel)); T1.start (); } classUserhandlethreadImplementsRunnable {PrivateDesktop DT; PrivateProgressmeter pg; PrivateWindow win; PrivateLabel prglb; PublicUserhandlethread (progressmeter watchpg, Window window, Label lb) {pg=WATCHPG; DT=Watchpg.getdesktop (); Win=window; PRGLB=lb; } @Override Public voidrun () {introws = 10000; //as a progress bar zone value Standard int[] Rowslarge =New int[10]; rowslarge[0] = (int) (Rows * 0.1) >= 0? (int) (Rows * 0.1): 0; rowslarge[1] = (int) (Rows * 0.2) >= 0? (int) (Rows * 0.2): 0; rowslarge[2] = (int) (Rows * 0.3) >= 0? (int) (Rows * 0.3): 0; rowslarge[3] = (int) (Rows * 0.4) >= 0? (int) (Rows * 0.4): 0; rowslarge[4] = (int) (Rows * 0.5) >= 0? (int) (Rows * 0.5): 0; rowslarge[5] = (int) (Rows * 0.6) >= 0? (int) (Rows * 0.6): 0; rowslarge[6] = (int) (Rows * 0.7) >= 0? (int) (Rows * 0.7): 0; rowslarge[7] = (int) (Rows * 0.8) >= 0? (int) (Rows * 0.8): 0; rowslarge[8] = (int) (Rows * 0.9) >= 0? (int) (Rows * 0.9): 0; rowslarge[9] = (int) (Rows * 1) >= 0? (int) (Rows * 1): 0; Try { //from 1 count to 10000 for(inti = 0; I <= rows; i++) { if(i = = rowslarge[0]) {executions.activate (dt); Pg.setvalue (10); Prglb.setvalue ("Completed 10% ..."); Executions.deactivate (DT); Thread.Sleep (2000); } Else if(i = = rowslarge[1]) {executions.activate (dt); Pg.setvalue (20); Prglb.setvalue ("Completed 20% ..."); Executions.deactivate (DT); Thread.Sleep (2000); } Else if(i = = rowslarge[2]) {executions.activate (dt); Pg.setvalue (30); Prglb.setvalue ("Completed 30% ..."); Executions.deactivate (DT); Thread.Sleep (2000); } Else if(i = = rowslarge[3]) {executions.activate (dt); Pg.setvalue (40); Prglb.setvalue ("Completed 40% ..."); Executions.deactivate (DT); Thread.Sleep (2000); } Else if(i = = Rowslarge[4]) {executions.activate (dt); Pg.setvalue (50); Prglb.setvalue ("Completed 50% ..."); Executions.deactivate (DT); Thread.Sleep (2000); } Else if(i = = rowslarge[5]) {executions.activate (dt); Pg.setvalue (60); Prglb.setvalue ("Completed 60% ..."); Executions.deactivate (DT); Thread.Sleep (2000); } Else if(i = = Rowslarge[6]) {executions.activate (dt); Pg.setvalue (70); Prglb.setvalue ("Completed 70% ..."); Executions.deactivate (DT); Thread.Sleep (2000); } Else if(i = = Rowslarge[7]) {executions.activate (dt); Pg.setvalue (80); Prglb.setvalue ("Completed 80% ..."); Executions.deactivate (DT); Thread.Sleep (2000); }Else if(i = = Rowslarge[8]) {executions.activate (dt); Pg.setvalue (90); Prglb.setvalue ("Completed 90% ..."); Executions.deactivate (DT); Thread.Sleep (2000); }Else if(i = = rowslarge[9]) {executions.activate (dt); Pg.setvalue (100); Prglb.setvalue ("100%, the import is successful, the window is automatically closed, please wait a moment ..."); Executions.deactivate (DT); Thread.Sleep (2000); }} executions.activate (dt); Win.detach (); Executions.deactivate (DT); } Catch(Exception e) {//Todo:handle Exception } } } }
The final effect is as follows:
ZK long-time operation with progress bar