java进度条代码_进度条 - java代码库 - 云代码

[java]代码库package wang1;

import java.awt.EventQueue;

import java.awt.Toolkit;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JScrollBar;

import javax.swing.JTextField;

import javax.swing.SwingUtilities;

import javax.swing.JProgressBar;

import javax.swing.JLabel;

import java.awt.Color;

public class JProcessBar extends JFrame {

// 得到显示器屏幕的宽高

public static int width = Toolkit.getDefaultToolkit().getScreenSize().width;

public static int height = Toolkit.getDefaultToolkit().getScreenSize().height;

// 定义窗体的宽高

public static int windowsWedth = 600;

public static int windowsHeight = 600;

private static final long serialVersionUID = 1L;

private JProgressBar progressBar = new JProgressBar();

private boolean state = false;

private int count = 0;

// 工作线程workThead

private Thread workThead = null;

private Runnable run = null;

public static void main(String[] args) {

JProcessBar jp = new JProcessBar();

jp.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

jp.setVisible(true);

}

/**

* Create the application.

*/

public JProcessBar() {

initialize();

}

JLabel lblNewLabel_1 = new JLabel("");

/**

* Initialize the contents of the frame.

*/

private void initialize() {

this.setTitle("\u52A0\u8F7D\u4E2D");

this.setBounds((width - windowsWedth) / 2, (height - windowsHeight) / 2, 545, 186);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.getContentPane().setLayout(null);

progressBar.setForeground(Color.BLACK);

progressBar.setStringPainted(true);

progressBar.setOpaque(false);

progressBar.setBounds(73, 103, 434, 24);

this.getContentPane().add(progressBar);

JLabel lblNewLabel = new JLabel("\u8FDB\u5EA6\u52A0\u8F7D\uFF1A");

lblNewLabel.setBounds(10, 106, 68, 15);

this.getContentPane().add(lblNewLabel);

lblNewLabel_1.setOpaque(true);

lblNewLabel_1.setBounds(73, 80, 235, 24);

getContentPane().add(lblNewLabel_1);

if (workThead == null) {

state = true;

workThead = new WorkThead();

workThead.start();

}

}

class WorkThead extends Thread {

public void run() {

while (count < 100) {

try {

Thread.sleep(100);

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

if (state) {

count++;

SwingUtilities.invokeLater(new Runnable() {

@Override

public void run() {

// TODO Auto-generated method stub

// 更新操作通过事件派发线程完成(一般实现Runnable()接口)

progressBar.setValue(count);

if(count==5){

lblNewLabel_1.setText("loading api-ms-win-core-xstate-l1-1-0.dll");

}else if(count==10){

lblNewLabel_1.setText("loading MaxxAudioAPO5064.dll");

}else if(count==20){

lblNewLabel_1.setText("loading MetroIntelGenericUIFramework.dll");

}else if(count==30){

lblNewLabel_1.setText("loading microsoft-windows-kernel-power-events.dll");

}else if(count==40){

lblNewLabel_1.setText("miguiresource.dll");

}else if(count==80){

lblNewLabel_1.setText("loading mfvdsp.dll");

}else if(count==90){

lblNewLabel_1.setText("loading miguiresource.dll");

}else if(count==100){

lblNewLabel_1.setText("loading end");

Thread.currentThread();

try {

Thread.sleep(500);

} catch (InterruptedException e) {

// TODO 自动生成的 catch 块

e.printStackTrace();

}

}

}

});

}

}

}

}

}

694748ed64b9390909c0d88230893790.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值