欢迎来到天天文库
浏览记录
ID:42710923
大小:16.83 KB
页数:3页
时间:2019-09-20
《程序加载示例》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、程序加载示例:学习Java的人一定都用过Eclipse吧,在Eclipse启动的过程中是不是出现了下面的界面对,这就是程序加载。细心的人一定会发现它使用了进度条,并且在界面上它会实时显示当前正在加载的内容。下面我就给大家模拟一下实现这种效果。哈哈,先上效果图。接着给出代码:importjavax.swing.SwingUtilities;importjava.awt.BorderLayout;importjava.awt.Dimension;importjava.awt.Toolkit;importjava.lang.reflect.Invocation
2、TargetException;importjavax.swing.ImageIcon;importjavax.swing.JLabel;importjavax.swing.JPanel;importjavax.swing.JFrame;importjavax.swing.JProgressBar;publicclassProgressBarTimerextendsJFrame{privatestaticfinallongserialVersionUID=1L;privatestaticProgressBarTimerthisClass;privates
3、taticThreadthread;privateJPaneljContentPane=null;privatestaticJProgressBarProgressBar;privateJProgressBargetJProgressBar(){if(ProgressBar==null){ProgressBar=newJProgressBar(0,100);ProgressBar.setStringPainted(true);}returnProgressBar;}//继承自Thread的BartheadpublicstaticclassBarthrea
4、dextendsThread{//定义jProgressBarJProgressBarjProgressBar;publicBarthread(JProgressBarprogressBar){//TODO自动生成构造函数存根jProgressBar=progressBar;}publicvoidrun(){//设置进度条的minimun和maximunintminimun=jProgressBar.getMinimum();intmaximun=jProgressBar.getMaximum();//进度条运行方法Runnablerunner=newR
5、unnable(){publicvoidrun(){//设置进度条的参数intvalue=jProgressBar.getValue();jProgressBar.setValue(value+1);//设置窗体在进度条完成率为50%的时候实例化SQLNew类.//设置窗体在进度条完成率为100%的时候运行Opening方法if(jProgressBar.getPercentComplete()==1.0){Opening();}}//Opening方法的实例privatevoidOpening(){//实例化ProgressBarTimer2窗体Pro
6、gressBarTimerprogressBarTimer=newProgressBarTimer();progressBarTimer.setVisible(true);progressBarTimer.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//将第一个窗体(ProgressBarTimer)的可见性设置为falsethisClass.setVisible(false);thisClass.dispose();jProgressBar.setVisible(false);}};//线程的运行,休眠
7、,中断for(inti=minimun;i8、okeLater(newRunnable(){publicvoidrun(){t
8、okeLater(newRunnable(){publicvoidrun(){t
此文档下载收益归作者所有