Slider users can use a slider to move back and forth to enter data, which in many cases is intuitive (such as voice control). The process bar displays the status of the relevant data from "empty" to "full", so the user gets a perspective of the state. My favorite example of this program is simply to hook up the slider with the process bar, so when we move the slider, the process bar changes accordingly:
: Progress.java
//Using Progress bars and Sliders
package c13.swing;
Import java.awt.*;
Import java.awt.event.*;
Import javax.swing.*;
Import javax.swing.event.*;
Import javax.swing.border.*;
public class Progress extends JPanel {
JProgressBar PB = new JProgressBar ();
JSlider sb =
new JSlider (jslider.horizontal, 0, MB);
Public Progress () {
setlayout (new GridLayout (2,1));
Add (pb);
Sb.setvalue (0);
Sb.setpaintticks (true);
Sb.setmajortickspacing (a);
Sb.setminortickspacing (5);
Sb.setborder (New Titledborder ("Slide Me"));
Pb.setmodel (Sb.getmodel ()); Share Model
Add (SB);
}
public static void Main (String args[]) {
show.inframe (new Progress (), 200,150);
}
///:~
JProgressBar is very simple, but JSlider has a number of options, such as methods, large or small marker labels. Note how easy it is to add a border with a caption.