📄 process.java
字号:
package hfmCompress;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JProgressBar;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Color;
public class Process extends JDialog implements Runnable {
private final int WIDTH = 200, HEIGHT = 100;
private Toolkit kit = null;
private int screenWidth = 0, screenHeight = 0;
private Dimension screenSize = null;
private JLabel jl = null;
private JProgressBar jp = null;
private Font f = new Font("", Font.BOLD, 15);
private static int nowValue = 0;
private static String nowLabelText=null;
private static boolean compress = false,deCompress=false;
public Process() {
this.setSize(WIDTH, HEIGHT);
kit = Toolkit.getDefaultToolkit();
screenSize = kit.getScreenSize();
screenWidth = screenSize.width;
screenHeight = screenSize.height;
this
.setLocation((screenWidth - WIDTH) / 2,
(screenHeight - HEIGHT) / 2);
this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
Container content = this.getContentPane();
content.setLayout(new FlowLayout());
jp = new JProgressBar();
jp.setBackground(Color.WHITE);
jp.setForeground(Color.GREEN);
jp.setMaximum(100);
jp.setMinimum(0);
jp.setValue(5);
jp.setStringPainted(true);
jl = new JLabel("正在读取原文件……");
jl.setFont(f);
content.add(jl);
content.add(jp);
this.setAlwaysOnTop(true);
}
public void setTitle(String newTitleArg) {
super.setTitle(newTitleArg);
}
public static void setCompressTrue(int nowValueArg,String nowLabelTextArg) {
compress = true;
nowValue=nowValueArg;
nowLabelText=nowLabelTextArg;
}
public static void setDeCompressTrue(int nowValueArg,String nowLabelTextArg){
deCompress=true;
nowValue=nowValueArg;
nowLabelText=nowLabelTextArg;
}
public void run() {
try {
while (true) {
if (nowValue == 100) {
return;
}
if (compress) {
compress = false;
jp.setValue(nowValue);
jl.setText(nowLabelText);
} else if(deCompress){
deCompress=false;
jl.setText(nowLabelText);
}else {
Thread.sleep(100);
}
}
} catch (Exception e) {
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -