package com.vci.client.ui.process;
|
|
import java.awt.Color;
|
import java.awt.Dimension;
|
import java.awt.Font;
|
import java.awt.Toolkit;
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
|
import javax.swing.JButton;
|
import javax.swing.JFrame;
|
import javax.swing.JPanel;
|
|
|
public class QANProcessBarFrame extends JFrame implements ProcessBarInterface {
|
|
private static QANProcessBarFrame frame = null;
|
private boolean isCancel = false;
|
private String content = "";
|
private int value = 0;
|
private int processBarDialogWidth = 600;
|
private int processBarDialogHeight = 150;
|
private boolean showStartButton = false;
|
private boolean showCancelButton = false;
|
private Color contentColor = Color.BLUE;
|
private Font contentFont = new Font("宋体", Font.PLAIN, 14);
|
public QANProcessBarFrame() {
|
|
}
|
|
public static void main(String[] args) {
|
frame = new QANProcessBarFrame();
|
|
JPanel panel = new JPanel();
|
JButton button = new JButton("sfd");
|
|
|
button.addActionListener(new ActionListener(){
|
|
public void actionPerformed(ActionEvent e) {
|
frame.setProcessBarCancel(false);
|
Thread t = new Thread(){
|
public void run() {
|
test();
|
}
|
};
|
QANProcessBar bar = new QANProcessBar(t, frame, frame,false);
|
bar.setVisible(true);
|
}});
|
panel.add(button);
|
frame.add(panel);
|
Dimension screenSize = Toolkit.getDefaultToolkit ().getScreenSize ();
|
Dimension frameSize = frame.getPreferredSize ();
|
frameSize.height = screenSize.height / 5 * 4;
|
frameSize.width = screenSize.width / 5 * 4 + 20;
|
frame.setSize (frameSize);
|
frame.setLocation ( (screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
|
frame.setVisible (true);
|
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
|
}
|
|
public static void test() {
|
for (int i = 0; i < 100; i++) {
|
if(frame.getProcessBarCancel()) {
|
break;
|
}
|
System.out.println(i);
|
try {
|
Thread.sleep(200);
|
} catch (InterruptedException e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
// frame.setValue(i);
|
// frame.setContent("现在传输到第 " + i + "个!");
|
frame.setContent("正在导入,请稍定......");
|
}
|
frame.setProcessBarCancel(true);
|
}
|
|
public void setProcessBarCancel(boolean isCancel) {
|
this.isCancel = isCancel;
|
}
|
|
public boolean getProcessBarCancel() {
|
return isCancel;
|
}
|
|
public String getProcessBarContent() {
|
return this.content;
|
}
|
|
public int getProcessBarValue() {
|
return this.value;
|
}
|
|
public void setValue(int value) {
|
this.value = value;
|
}
|
|
public void setContent(String content) {
|
this.content = content;
|
}
|
|
public String getProcessBarTitle() {
|
return "title";
|
}
|
|
public boolean isProcessSure() {
|
return false;
|
}
|
|
@Override
|
public int getProcessBarDialogWidth() {
|
return processBarDialogWidth;
|
}
|
|
@Override
|
public void setProcessBarDialogWidth(int width) {
|
this.processBarDialogWidth = width;
|
}
|
|
@Override
|
public int getProcessBarDialogHeight() {
|
return processBarDialogHeight;
|
}
|
|
@Override
|
public void setProcessBarDialogHeight(int height) {
|
this.processBarDialogHeight = height;
|
}
|
|
@Override
|
public boolean isShowStartButton() {
|
return this.showStartButton;
|
}
|
|
@Override
|
public void setShowStartButton(boolean showStartButton) {
|
this.showStartButton = showStartButton;
|
}
|
|
@Override
|
public boolean isShowCancelButton() {
|
return this.showCancelButton;
|
}
|
|
@Override
|
public boolean setShowCancelButton(boolean showCancelButton) {
|
return this.showCancelButton;
|
}
|
|
@Override
|
public Color getContentColor() {
|
return contentColor;
|
}
|
|
@Override
|
public void setContentColor(Color contentColor) {
|
this.contentColor = contentColor;
|
}
|
|
@Override
|
public Font getContentFont() {
|
return contentFont;
|
}
|
|
@Override
|
public void setContentFont(Font contentFont) {
|
this.contentFont = contentFont;
|
}
|
|
}
|