swing进度条

package com.hooypay.view;
import java.awt.Image;
import java.awt.Toolkit;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JRootPane;

public class LoadingFrame2 extends JFrame {
    private JLabel statusLabel = new JLabel("");

    public LoadingFrame2() {

        this.setUndecorated(true); // 去掉窗口的装饰
        this.getRootPane().setWindowDecorationStyle(JRootPane.NONE);// 采用指定的窗口装饰风格
        statusLabel.setIcon(new ImageIcon(ClassLoader
                .getSystemResource("image/loding1.gif")));
        this.getContentPane().add(statusLabel);

        statusLabel.setHorizontalAlignment(JLabel.CENTER);
        this.setBounds(700, 500, 30, 30);
         // 任务栏图标
           Toolkit toolkit = Toolkit.getDefaultToolkit();
           Image image = toolkit.createImage(ClassLoader.getSystemResource("image/01.png"));
           this.setIconImage(image); 
           //设置标题
           this.setTitle("正在请求...");
    }
    public static void main(String[] args) {
        new LoadingFrame2().setVisible(true);
    }
}

1.上面是图片进度条

2.绘图进度条

package com.hooypay.test;

import java.awt.FlowLayout;   
import java.awt.event.ActionEvent;   
import java.awt.event.ActionListener;   
import javax.swing.JButton;   
import javax.swing.JFrame;   
import javax.swing.JProgressBar;   
import javax.swing.JTextField;   
import javax.swing.SwingUtilities;   
public class SwingThreadTest3 extends JFrame {   
   private static final long serialVersionUID = 1L;   
   private static final String STR = "Completed : ";   
   private JProgressBar progressBar = new JProgressBar();   
   private JTextField text = new JTextField(10);   
  private JButton start = new JButton("Start");   
   private JButton end = new JButton("End");   
   private boolean flag = false;   
   private int count = 0;   
      
   private GoThread t = null;   
      
   private Runnable run = null;//更新组件的线程   
   public SwingThreadTest3() {   
       this.setLayout(new FlowLayout());   
       add(progressBar);   
       text.setEditable(false);   
       add(text);   
       add(start);   
       add(end);   
       start.addActionListener(new Start());   
      end.addActionListener(new End());   
          
       run = new Runnable(){//实例化更新组件的线程   
           public void run() {   
               progressBar.setValue(count);   
               text.setText(STR + String.valueOf(count) + "%");   
          }   
       };   
   }   
   private void go() {   
       while (count < 100) {   
           try {   
               Thread.sleep(100);   
           } catch (InterruptedException e) {   
               e.printStackTrace();   
           }   
           if (flag) {   
               count++;   
               SwingUtilities.invokeLater(run);//将对象排到事件派发线程的队列中   
          }   
       }   
   }   
   private class Start implements ActionListener {   
       public void actionPerformed(ActionEvent e) {   
           flag = true;   
           if(t == null){   
               t = new GoThread();   
               t.start();   
           }   
       }   
   }   
      
   class GoThread extends Thread{   
       public void run() {   
           //do something   
           go();   
       }   
   }   
   private class End implements ActionListener {   
       public void actionPerformed(ActionEvent e) {   
           flag = false;   
       }   
   }   
   public static void main(String[] args) {   
       SwingThreadTest3 fg = new SwingThreadTest3();   
       fg.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);   
       fg.setSize(300, 100);   
       fg.setVisible(true);   
   }   
}


 

转载于:https://www.cnblogs.com/xiaomuv587/archive/2013/01/24/2875168.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值