Topic: 进度条的问题,请大虾指教 |
Print this page |
1.进度条的问题,请大虾指教 | Copy to clipboard |
Posted by: ljw8080 Posted on: 2005-07-01 16:40 这是一本资料上的例子。它是在打开一副图片时,下面用进度条显示速度。可结果却不是这样,进度条有显示,但和面版分开时间还有就图片无显示。大虾运行一下就知道了。 import javax.swing.*; import java.awt.*; //import java.awt.event.*; import java.net.*; public class JSplashWindowEx extends JWindow implements Runnable{ Thread splashThread=null; private JProgressBar progress; public JSplashWindowEx() { setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); JPanel splash=new JPanel(new BorderLayout()); URL url=getClass().getResource("/winter.jpg");//返回一个对象的运行时间类 if(url!=null){ splash.add(new JButton(new ImageIcon(url)),BorderLayout.CENTER); } progress=new JProgressBar(1,100); progress.setStringPainted(true); progress.setBorderPainted(false); progress.setString("Program is Nwe Loading........"); progress.setBackground(Color.white); splash.add(progress,BorderLayout.SOUTH); setContentPane(splash); Dimension screen=getToolkit().getScreenSize(); pack();//按首选尺寸放置该窗口子组件。 setLocation((screen.width-getSize().width)/2,(screen.height-getSize().height)/2); } public void start(){ this.toFront();//将该窗口放到前面 splashThread=new Thread(this); splashThread.start(); } public void run(){ show(); try{ for(int i=0;i<100;i++) { Thread.sleep(100); progress.setValue(progress.getValue()+1); } } catch(Exception ex){ ex.printStackTrace(); } dispose(); } static void showFrame(String title){ JFrame frame=new JFrame(title); frame.setSize(640,480); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize=frame.getSize(); if(frameSize.height>screenSize.height){ frameSize.height=screenSize.height; } if(frameSize.width>screenSize.width){ rameSize.width=screenSize.width;} frame.setLocation((screenSize.width-frameSize.width)/2,(screenSize.height- frameSize.height)/2);//将这个组件移动到新位置 try{Thread.sleep(10000); } catch(Exception ex) { ex.printStackTrace(); } frame.setVisible(true); } public static void main(String[] args){ JSplashWindowEx splash=new JSplashWindowEx(); splash.start(); showFrame("Splash window demo"); } } |
2.Re:进度条的问题,请大虾指教 [Re: ljw8080] | Copy to clipboard |
Posted by: ljw8080 Posted on: 2005-07-03 15:02 没有顶啊。自己顶一下。 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |