ludc
2024-09-14 36c2449aec5b51e5ed4e5c6841154b746060e09a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
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;
    }
    
}