Small thread example -- progress bar, thread example -- progress bar

Source: Internet
Author: User

Small thread example -- progress bar, thread example -- progress bar
Example of a small thread -- progress bar

Function: displays a progress bar in the form. The progress bar increases automatically.

Import java. awt. container; 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; public class ThreadDemo extends JFrame {Thread thread; public ThreadDemo () {super (); Container c = getContentPane (); setBounds (300,200,250,100 ); final JProgressBar B = new JProgressBar (); // progress bar c. add (B); B. setStringPainted (true); // set the progress bar to display the number thread = new Thread (new Runnable () {int count = 0; @ Override public void run () {// TODO Auto-generated method stub while (true) {B. setValue (count ++); // set the current value of the progress bar. try {Thread. sleep (100);} catch (InterruptedException e) {// TODO Auto-generated catch block e. printStackTrace () ;}}}); thread. start (); setVisible (true);} public static void main (String [] args) {new ThreadDemo ();}}

The only thing that is needed is probably the knowledge point of the progress bar:

JProgressBar:

SetStringPainted: Set whether a number is displayed on the progress bar.
SetValue sets the current value of the progress bar

The result is as follows:
 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.