OnJava8-Examples/ui/Progress.java

36 lines
1.1 KiB
Java
Raw Normal View History

2015-09-07 11:44:36 -06:00
// ui/Progress.java
2015-12-15 11:47:04 -08:00
// (c)2016 MindView LLC: see Copyright.txt
2015-11-15 15:51:35 -08:00
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
2015-06-15 17:47:35 -07:00
// Using sliders, progress bars and progress monitors.
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import static onjava.SwingConsole.*;
2015-06-15 17:47:35 -07:00
public class Progress extends JFrame {
private JProgressBar pb = new JProgressBar();
private ProgressMonitor pm = new ProgressMonitor(
this, "Monitoring Progress", "Test", 0, 100);
private JSlider sb =
new JSlider(JSlider.HORIZONTAL, 0, 100, 60);
public Progress() {
setLayout(new GridLayout(2,1));
add(pb);
pm.setProgress(0);
pm.setMillisToPopup(1000);
sb.setValue(0);
sb.setPaintTicks(true);
sb.setMajorTickSpacing(20);
sb.setMinorTickSpacing(5);
sb.setBorder(new TitledBorder("Slide Me"));
pb.setModel(sb.getModel()); // Share model
add(sb);
sb.addChangeListener(e ->
pm.setProgress(sb.getValue()));
}
public static void main(String[] args) {
run(new Progress(), 300, 200);
}
2015-09-07 11:44:36 -06:00
}