Java by API/javax.swing/ProgressMonitor — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 14:18, 31 мая 2010
Содержание
- 1 new ProgressMonitor(Component p, Object m, String n, int min, int max)
- 2 ProgressMonitor: getMillisToDecideToPopup()
- 3 ProgressMonitor: getMillisToPopup()
- 4 ProgressMonitor: isCanceled()
- 5 ProgressMonitor.progressText
- 6 ProgressMonitor: setMillisToDecideToPopup(int millisToDecideToPopup)
- 7 ProgressMonitor: setMillisToPopup(int millisToPopup)
- 8 ProgressMonitor: setNote(String note)
- 9 ProgressMonitor: setProgress(int nv)
new ProgressMonitor(Component p, Object m, String n, int min, int max)
import java.awt.ruponent;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.ProgressMonitor;
import javax.swing.Timer;
public class MainClass {
static ProgressMonitor monitor;
static int progress;
static Timer timer;
static class ProgressMonitorHandler implements ActionListener {
public void actionPerformed(ActionEvent actionEvent) {
if (monitor == null)
return;
if (monitor.isCanceled()) {
System.out.println("Monitor canceled");
timer.stop();
} else {
progress += 3;
monitor.setProgress(progress);
monitor.setNote("Loaded " + progress + " files");
}
}
}
public static void main(String args[]) {
JFrame frame = new JFrame("ProgressMonitor Sample");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton autoIncreaseButton = new JButton("Automatic Increase");
ActionListener autoIncreaseActionListener = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
Component parent = (Component) actionEvent.getSource();
monitor = new ProgressMonitor(parent, "Loading Progress", "Getting Started...", 0, 200);
progress = 0;
if (monitor != null) {
if (timer == null) {
timer = new Timer(250, new ProgressMonitorHandler());
}
timer.start();
}
}
};
autoIncreaseButton.addActionListener(autoIncreaseActionListener);
frame.add(autoIncreaseButton);
frame.setSize(300, 200);
frame.setVisible(true);
}
}
ProgressMonitor: getMillisToDecideToPopup()
import javax.swing.JFrame;
import javax.swing.ProgressMonitor;
import javax.swing.UIManager;
public class Main {
public static void main(String[] argv) throws Exception {
String message = "Description of Task";
String note = "subtask";
String title = "Task Title";
UIManager.put("ProgressMonitor.progressText", title);
int min = 0;
int max = 100;
JFrame component = new JFrame();
ProgressMonitor pm = new ProgressMonitor(component, message, note, min, max);
int millisToPopup = pm.getMillisToPopup(); // 2000
int millisToDecideToPopup = pm.getMillisToDecideToPopup(); // 500
pm.setMillisToPopup(0);
pm.setMillisToDecideToPopup(0);
}
}
ProgressMonitor: getMillisToPopup()
import javax.swing.JFrame;
import javax.swing.ProgressMonitor;
import javax.swing.UIManager;
public class Main {
public static void main(String[] argv) throws Exception {
String message = "Description of Task";
String note = "subtask";
String title = "Task Title";
UIManager.put("ProgressMonitor.progressText", title);
int min = 0;
int max = 100;
JFrame component = new JFrame();
ProgressMonitor pm = new ProgressMonitor(component, message, note, min, max);
int millisToPopup = pm.getMillisToPopup(); // 2000
int millisToDecideToPopup = pm.getMillisToDecideToPopup(); // 500
pm.setMillisToPopup(0);
pm.setMillisToDecideToPopup(0);
}
}
ProgressMonitor: isCanceled()
import java.awt.ruponent;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.ProgressMonitor;
import javax.swing.Timer;
public class MainClass {
static ProgressMonitor monitor;
static int progress;
static Timer timer;
static class ProgressMonitorHandler implements ActionListener {
public void actionPerformed(ActionEvent actionEvent) {
if (monitor == null)
return;
if (monitor.isCanceled()) {
System.out.println("Monitor canceled");
timer.stop();
} else {
progress += 3;
monitor.setProgress(progress);
monitor.setNote("Loaded " + progress + " files");
}
}
}
public static void main(String args[]) {
JFrame frame = new JFrame("ProgressMonitor Sample");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton autoIncreaseButton = new JButton("Automatic Increase");
ActionListener autoIncreaseActionListener = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
Component parent = (Component) actionEvent.getSource();
monitor = new ProgressMonitor(parent, "Loading Progress", "Getting Started...", 0, 200);
progress = 0;
if (monitor != null) {
if (timer == null) {
timer = new Timer(250, new ProgressMonitorHandler());
}
timer.start();
}
}
};
autoIncreaseButton.addActionListener(autoIncreaseActionListener);
frame.add(autoIncreaseButton);
frame.setSize(300, 200);
frame.setVisible(true);
}
}
ProgressMonitor.progressText
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.ProgressMonitor;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import javax.swing.UIManager;
public class MainClass extends JFrame implements ActionListener {
static ProgressMonitor pbar = new ProgressMonitor(null, "Monitoring Progress", "Initializing . . .", 0, 100);
static int counter = 0;
public MainClass() {
super("Progress Monitor Demo");
setSize(250, 100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Timer timer = new Timer(500, this);
timer.start();
setVisible(true);
}
public static void main(String args[]) {
UIManager.put("ProgressMonitor.progressText", "This is progress?");
new MainClass();
}
public void actionPerformed(ActionEvent e) {
SwingUtilities.invokeLater(new Update());
}
class Update implements Runnable {
public void run() {
if (pbar.isCanceled()) {
pbar.close();
System.exit(1);
}
pbar.setProgress(counter);
pbar.setNote("Operation is " + counter + "% complete");
counter += 2;
}
}
}
ProgressMonitor: setMillisToDecideToPopup(int millisToDecideToPopup)
import javax.swing.JFrame;
import javax.swing.ProgressMonitor;
import javax.swing.UIManager;
public class Main {
public static void main(String[] argv) throws Exception {
String message = "Description of Task";
String note = "subtask";
String title = "Task Title";
UIManager.put("ProgressMonitor.progressText", title);
int min = 0;
int max = 100;
JFrame component = new JFrame();
ProgressMonitor pm = new ProgressMonitor(component, message, note, min, max);
int millisToPopup = pm.getMillisToPopup(); // 2000
int millisToDecideToPopup = pm.getMillisToDecideToPopup(); // 500
pm.setMillisToPopup(0);
pm.setMillisToDecideToPopup(0);
}
}
ProgressMonitor: setMillisToPopup(int millisToPopup)
import javax.swing.JFrame;
import javax.swing.ProgressMonitor;
import javax.swing.UIManager;
public class Main {
public static void main(String[] argv) throws Exception {
String message = "Description of Task";
String note = "subtask";
String title = "Task Title";
UIManager.put("ProgressMonitor.progressText", title);
int min = 0;
int max = 100;
JFrame component = new JFrame();
ProgressMonitor pm = new ProgressMonitor(component, message, note, min, max);
int millisToPopup = pm.getMillisToPopup(); // 2000
int millisToDecideToPopup = pm.getMillisToDecideToPopup(); // 500
pm.setMillisToPopup(0);
pm.setMillisToDecideToPopup(0);
}
}
ProgressMonitor: setNote(String note)
import java.awt.ruponent;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.ProgressMonitor;
import javax.swing.Timer;
public class MainClass {
static ProgressMonitor monitor;
static int progress;
static Timer timer;
static class ProgressMonitorHandler implements ActionListener {
public void actionPerformed(ActionEvent actionEvent) {
if (monitor == null)
return;
if (monitor.isCanceled()) {
System.out.println("Monitor canceled");
timer.stop();
} else {
progress += 3;
monitor.setProgress(progress);
monitor.setNote("Loaded " + progress + " files");
}
}
}
public static void main(String args[]) {
JFrame frame = new JFrame("ProgressMonitor Sample");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton autoIncreaseButton = new JButton("Automatic Increase");
ActionListener autoIncreaseActionListener = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
Component parent = (Component) actionEvent.getSource();
monitor = new ProgressMonitor(parent, "Loading Progress", "Getting Started...", 0, 200);
progress = 0;
if (monitor != null) {
if (timer == null) {
timer = new Timer(250, new ProgressMonitorHandler());
}
timer.start();
}
}
};
autoIncreaseButton.addActionListener(autoIncreaseActionListener);
frame.add(autoIncreaseButton);
frame.setSize(300, 200);
frame.setVisible(true);
}
}
ProgressMonitor: setProgress(int nv)
import java.awt.ruponent;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.ProgressMonitor;
import javax.swing.Timer;
public class MainClass {
static ProgressMonitor monitor;
static int progress;
static Timer timer;
static class ProgressMonitorHandler implements ActionListener {
public void actionPerformed(ActionEvent actionEvent) {
if (monitor == null)
return;
if (monitor.isCanceled()) {
System.out.println("Monitor canceled");
timer.stop();
} else {
progress += 3;
monitor.setProgress(progress);
monitor.setNote("Loaded " + progress + " files");
}
}
}
public static void main(String args[]) {
JFrame frame = new JFrame("ProgressMonitor Sample");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton autoIncreaseButton = new JButton("Automatic Increase");
ActionListener autoIncreaseActionListener = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
Component parent = (Component) actionEvent.getSource();
monitor = new ProgressMonitor(parent, "Loading Progress", "Getting Started...", 0, 200);
progress = 0;
if (monitor != null) {
if (timer == null) {
timer = new Timer(250, new ProgressMonitorHandler());
}
timer.start();
}
}
};
autoIncreaseButton.addActionListener(autoIncreaseActionListener);
frame.add(autoIncreaseButton);
frame.setSize(300, 200);
frame.setVisible(true);
}
}