日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

java 进度条 百分比_java怎么让进度条带百分数

發布時間:2024/8/1 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java 进度条 百分比_java怎么让进度条带百分数 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

展開全部

public void setString(String s)

設置進度字符串的值。默認情況下,此字符串為 null,隱含使用簡單百分比字符串的內置行為62616964757a686964616fe78988e69d8331333264623135。如果已提供自定義進度字符串并要轉換回內置狀態,將字符串設置回 null 即可。

僅當 isStringPainted 方法返回 true 時繪制進度字符串。

參數:

s - 進度字符串的值

另請參見:

getString(), setStringPainted(boolean), isStringPainted()

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.beans.*;

import java.util.Random;

public class ProgressBarDemo extends JPanel

implements ActionListener,

PropertyChangeListener {

private JProgressBar progressBar;

private JButton startButton;

private JTextArea taskOutput;

private Task task;

class Task extends SwingWorker {

/*

* Main task. Executed in background thread.

*/

@Override

public Void doInBackground() {

Random random = new Random();

int progress = 0;

//Initialize progress property.

setProgress(0);

while (progress < 100) {

//Sleep for up to one second.

try {

Thread.sleep(random.nextInt(1000));

} catch (InterruptedException ignore) {}

//Make random progress.

progress += random.nextInt(10);

setProgress(Math.min(progress, 100));

}

return null;

}

/*

* Executed in event dispatching thread

*/

@Override

public void done() {

Toolkit.getDefaultToolkit().beep();

startButton.setEnabled(true);

setCursor(null); //turn off the wait cursor

taskOutput.append("Done!\n");

}

}

public ProgressBarDemo() {

super(new BorderLayout());

//Create the demo's UI.

startButton = new JButton("Start");

startButton.setActionCommand("start");

startButton.addActionListener(this);

progressBar = new JProgressBar(0, 100);

progressBar.setValue(0);

progressBar.setStringPainted(true);

taskOutput = new JTextArea(5, 20);

taskOutput.setMargin(new Insets(5,5,5,5));

taskOutput.setEditable(false);

JPanel panel = new JPanel();

panel.add(startButton);

panel.add(progressBar);

add(panel, BorderLayout.PAGE_START);

add(new JScrollPane(taskOutput), BorderLayout.CENTER);

setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

}

/**

* Invoked when the user presses the start button.

*/

public void actionPerformed(ActionEvent evt) {

startButton.setEnabled(false);

setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

//Instances of javax.swing.SwingWorker are not reusuable, so

//we create new instances as needed.

task = new Task();

task.addPropertyChangeListener(this);

task.execute();

}

/**

* Invoked when task's progress property changes.

*/

public void propertyChange(PropertyChangeEvent evt) {

if ("progress" == evt.getPropertyName()) {

int progress = (Integer) evt.getNewValue();

progressBar.setValue(progress);

taskOutput.append(String.format(

"Completed %d%% of task.\n", task.getProgress()));

}

}

/**

* Create the GUI and show it. As with all GUI code, this must run

* on the event-dispatching thread.

*/

private static void createAndShowGUI() {

//Create and set up the window.

JFrame frame = new JFrame("ProgressBarDemo");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Create and set up the content pane.

JComponent newContentPane = new ProgressBarDemo();

newContentPane.setOpaque(true); //content panes must be opaque

frame.setContentPane(newContentPane);

//Display the window.

frame.pack();

frame.setVisible(true);

}

public static void main(String[] args) {

//Schedule a job for the event-dispatching thread:

//creating and showing this application's GUI.

javax.swing.SwingUtilities.invokeLater(new Runnable() {

public void run() {

createAndShowGUI();

}

});

}

}

已贊過

已踩過<

你對這個回答的評價是?

評論

收起

總結

以上是生活随笔為你收集整理的java 进度条 百分比_java怎么让进度条带百分数的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。