⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loadingprogress.java

📁 Rapla是一个灵活的多用户资源管理系统。它提供的一些功能有:日历GUI
💻 JAVA
字号:
/*--------------------------------------------------------------------------*
 | Copyright (C) 2006 Christopher Kohlhaas                                  |
 |                                                                          |
 | This program is free software; you can redistribute it and/or modify     |
 | it under the terms of the GNU General Public License as published by the |
 | Free Software Foundation. A copy of the license has been included with   |
 | these distribution in the COPYING file, if not go to www.fsf.org         |
 |                                                                          |
 | As a special exception, you are granted the permissions to link this     |
 | program with every library, which license fulfills the Open Source       |
 | Definition as published by the Open Source Initiative (OSI).             |
 *--------------------------------------------------------------------------*/
package org.rapla.client.internal;
import java.net.URL;
import java.awt.image.ImageObserver;
import java.awt.Color;
import java.awt.Image;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.MediaTracker;
import java.awt.Toolkit;
import java.awt.Cursor;
import java.awt.Component;
import java.awt.Dimension;
import javax.swing.JProgressBar;

final public class LoadingProgress {
    JProgressBar progressBar;
    Frame frame;
    ImageObserver observer;
    Image image;
    Component canvas;

    int maxValue;
    /** this method creates the progress bar*/
    public void start(int startValue,int maxValue) {
        this.maxValue = maxValue;
        frame= new Frame() {
            private static final long serialVersionUID = 1L;
            public void paint(Graphics g) {
                super.paint(g);
                g.drawRect(0,0,getWidth()-1,getHeight()-1);
            }
            };
        observer = new ImageObserver() {
            public boolean imageUpdate(Image img, int flags,int x,int y,int w,int h) {
                if ((flags & ALLBITS) != 0) {
                    canvas.repaint();
                }
                return (flags & (ALLBITS|ABORT|ERROR)) ==0;
            }
        };
        frame.setBackground(new Color(255,255,204));
        canvas = new Component() {
            private static final long serialVersionUID = 1L;
            public void paint(Graphics g) {
                g.drawImage(image,0,0,observer);
            }
        };
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        URL url = LoadingProgress.class.getResource("/org/rapla/gui/images/tafel.png");


        int width = 108;
        int height = 46;
        image = toolkit.createImage(url);
        frame.setResizable(false);
        frame.setLayout(null);
        frame.add(canvas);
        canvas.setBounds(125-width/2,50-height/2,width,height);
        try {
            // If run on jdk < 1.4 this will throw a MethodNotFoundException
            //frame.setUndecorated(true);
            Frame.class.getMethod("setUndecorated",new Class[] {boolean.class}).invoke(frame,new Object[] {new Boolean(true)});
        } catch (Exception ex) {
        }
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        frame.setBounds(screenSize.width/2-125,screenSize.height/2-60,250,120);
        frame.validate();
        MediaTracker mt = new MediaTracker(frame);
        mt.addImage(image, 0);
        try
        {
            mt.waitForID(0);
        } catch (InterruptedException e)
        {
        }
        frame.setVisible(true);
        frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        progressBar = new JProgressBar(0,maxValue);
        progressBar.setValue(startValue);
        progressBar.setBounds(50,80,150,15);
        frame.add(progressBar);
        progressBar.repaint();
    }

    public void advance() {
        int oldValue = progressBar.getValue();
        if (oldValue < maxValue)
            progressBar.setValue(oldValue + 1);
        progressBar.repaint();
    }

    public void close() {
        frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        frame.dispose();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -