Created
September 25, 2019 20:38
-
-
Save brunosantanati/3c9e5778ba591b6218b6a210da1fc17f to your computer and use it in GitHub Desktop.
Example using JProgressBar Java Swing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Java Program to create a | |
| // simple progress bar | |
| import java.awt.*; | |
| import javax.swing.*; | |
| import java.awt.event.*; | |
| public class progress extends JFrame { | |
| // create a frame | |
| static JFrame f; | |
| static JProgressBar b; | |
| public static void main(String args[]) | |
| { | |
| // create a frame | |
| f = new JFrame("ProgressBar demo"); | |
| // create a panel | |
| JPanel p = new JPanel(); | |
| // create a progressbar | |
| b = new JProgressBar(); | |
| // set initial value | |
| b.setValue(0); | |
| b.setStringPainted(true); | |
| // add progressbar | |
| p.add(b); | |
| // add panel | |
| f.add(p); | |
| // set the size of the frame | |
| f.setSize(500, 500); | |
| f.setVisible(true); | |
| fill(); | |
| } | |
| // function to increase progress | |
| public static void fill() | |
| { | |
| int i = 0; | |
| try { | |
| while (i <= 100) { | |
| // fill the menu bar | |
| b.setValue(i + 10); | |
| // delay the thread | |
| Thread.sleep(1000); | |
| i += 20; | |
| } | |
| } | |
| catch (Exception e) { | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment