在java里面有JProgressBar 這個(gè)類,你查下文檔看看如何實(shí)現(xiàn),我也沒有使用過
專注于為中小企業(yè)提供成都做網(wǎng)站、網(wǎng)站建設(shè)服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)東海免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了上千多家企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
public class MyProgressBar extends Canvas {
private float scaleSize;
private float currentValue;
public MyProgressBar() {
this(100, 50);
}
public MyProgressBar(float scaleSize, float currentValue) {
this.scaleSize = scaleSize;
this.currentValue = currentValue;
this.setBackground(Color.lightGray);
this.setForeground(Color.magenta);
setSize(150, 25);
}
public float getCurrentValue() {
return currentValue;
}
public void setCurrentValue(float currentValue) {
this.currentValue = Math.max(0, currentValue);
if (this.scaleSize this.currentValue) {
this.currentValue = this.scaleSize;
}
}
public float getScaleSize() {
return scaleSize;
}
public void setScaleSize(float scaleSize) {
this.scaleSize = Math.max(1.0f, scaleSize);
if (this.scaleSize this.currentValue) {
this.scaleSize = this.currentValue;
}
}
public synchronized void paint(Graphics g) {
int w = getSize().width;
int h = getSize().height;
g.setColor(getBackground());
g.fillRect(1, 1, w - 2, h - 2);
g.fill3DRect(0, 0, w - 1, h - 1, true);
g.setColor(getForeground());
g.fillRect(3, 3, (int) (currentValue * (w - 6) / scaleSize), h - 6);
}
}
下面是程序執(zhí)行入口點(diǎn):
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class TestMyProgressBar extends JFrame implements Runnable,
ActionListener {
private MyProgressBar bar;
private JButton btnStart;
static TestMyProgressBar tmpb;
public TestMyProgressBar() {
setSize(400, 300);
setLocation(400, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("演示自定義進(jìn)度條");
setLayout(new FlowLayout());
btnStart = new JButton("開始");
this.add(btnStart);
btnStart.addActionListener(this);
bar = new MyProgressBar();
setVisible(true);
}
public static void main(String[] args) {
tmpb = new TestMyProgressBar();
}
@Override
public void run() {
for (int i = 1; i = 20; i++) {
int x = i * 5;
bar.setCurrentValue(x);
if (x 0 x 100) {
btnStart.setEnabled(false);
}
if (x == 100) {
btnStart.setEnabled(true);
}
try {
Thread.sleep(200);
add(bar);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("開始")) {
Thread t = new Thread(tmpb);
t.start();
}
}
}
import java.awt.Color; import java.awt.Toolkit; import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JProgressBar; import javax.swing.JWindow; @SuppressWarnings("serial") public class Demo extends JWindow implements Runnable { // 定義加載窗口大小 public static final int LOAD_WIDTH = 455; public static final int LOAD_HEIGHT = 295; // 獲取屏幕窗口大小 public static final int WIDTH = Toolkit.getDefaultToolkit().getScreenSize().width; public static final int HEIGHT = Toolkit.getDefaultToolkit().getScreenSize().height; // 定義進(jìn)度條組件 public JProgressBar progressbar; // 定義標(biāo)簽組件 public JLabel label; // 構(gòu)造函數(shù) public Demo() { // 創(chuàng)建標(biāo)簽,并在標(biāo)簽上放置一張圖片 label = new JLabel(new ImageIcon("images/background.jpg")); label.setBounds(0, 0, LOAD_WIDTH, LOAD_HEIGHT - 15); // 創(chuàng)建進(jìn)度條 progressbar = new JProgressBar(); // 顯示當(dāng)前進(jìn)度值信息 progressbar.setStringPainted(true); // 設(shè)置進(jìn)度條邊框不顯示 progressbar.setBorderPainted(false); // 設(shè)置進(jìn)度條的前景色 progressbar.setForeground(new Color(0, 210, 40)); // 設(shè)置進(jìn)度條的背景色 progressbar.setBackground(new Color(188, 190, 194)); progressbar.setBounds(0, LOAD_HEIGHT - 15, LOAD_WIDTH, 15); // 添加組件 this.add(label); this.add(progressbar); // 設(shè)置布局為空 this.setLayout(null); // 設(shè)置窗口初始位置 this.setLocation((WIDTH - LOAD_WIDTH) / 2, (HEIGHT - LOAD_HEIGHT) / 2); // 設(shè)置窗口大小 this.setSize(LOAD_WIDTH, LOAD_HEIGHT); // 設(shè)置窗口顯示 this.setVisible(true); } public static void main(String[] args) { Demo t = new Demo(); new Thread(t).start(); } @Override public void run() { for (int i = 0; i 100; i++) { try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } progressbar.setValue(i); } JOptionPane.showMessageDialog(this, "加載完成"); this.dispose(); } }
分享題目:java中進(jìn)度條代碼 java項(xiàng)目進(jìn)度表
文章網(wǎng)址:http://jinyejixie.com/article18/dohhpdp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供營銷型網(wǎng)站建設(shè)、App設(shè)計(jì)、用戶體驗(yàn)、動(dòng)態(tài)網(wǎng)站、網(wǎng)站策劃、網(wǎng)頁設(shè)計(jì)公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)