Skip to content

Commit

Permalink
添加操作等待页面和垃圾回收按钮。
Browse files Browse the repository at this point in the history
  • Loading branch information
houyi committed Oct 21, 2014
1 parent 3164a35 commit 7aa2b53
Show file tree
Hide file tree
Showing 7 changed files with 603 additions and 101 deletions.
Binary file added resources/icons/trash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 22 additions & 4 deletions src/com/lottery/action/ImportLotteryAllAction.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package com.lottery.action;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JFileChooser;
import javax.swing.*;
import javax.swing.filechooser.FileFilter;

import com.lottery.component.ProgressPanel;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;

Expand All @@ -22,7 +24,15 @@
*/
public class ImportLotteryAllAction implements ActionListener {

@Override
private ProgressPanel progressPanel;
private Frame frame;

public ImportLotteryAllAction(Frame frame, ProgressPanel progressPanel) {
this.frame = frame;
this.progressPanel = progressPanel;
}

@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
Expand Down Expand Up @@ -53,8 +63,16 @@ public String getDescription() {
if (state == 1) {
return;
} else {
File file = fileChooser.getSelectedFile();
processImport(file);
final File file = fileChooser.getSelectedFile();
progressPanel.start();
Thread performer = new Thread(new Runnable() {
public void run() {
processImport(file);
progressPanel.stop();
JOptionPane.showMessageDialog(frame, "导入全排列数据成功!", "系统消息", JOptionPane.INFORMATION_MESSAGE);
}
}, "导入全排列数据");
performer.start();
}

}
Expand Down
22 changes: 20 additions & 2 deletions src/com/lottery/action/ImportLotteryAnyAction.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.lottery.action;

import com.lottery.common.SpringBeanFactory;
import com.lottery.component.ProgressPanel;
import com.lottery.model.LotteryAny;
import com.lottery.service.LotteryAnyService;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;

import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
Expand All @@ -21,6 +23,14 @@
*/
public class ImportLotteryAnyAction implements ActionListener {

private ProgressPanel progressPanel;
private Frame frame;

public ImportLotteryAnyAction(Frame frame, ProgressPanel progressPanel) {
this.frame = frame;
this.progressPanel = progressPanel;
}

@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = new JFileChooser();
Expand Down Expand Up @@ -52,8 +62,16 @@ public String getDescription() {
if (state == 1) {
return;
} else {
File file = fileChooser.getSelectedFile();
processImport(file);
final File file = fileChooser.getSelectedFile();
progressPanel.start();
Thread performer = new Thread(new Runnable() {
public void run() {
processImport(file);
progressPanel.stop();
JOptionPane.showMessageDialog(frame, "导入中奖数据成功!", "系统消息", JOptionPane.INFORMATION_MESSAGE);
}
}, "导入中奖数据");
performer.start();
}

}
Expand Down
48 changes: 48 additions & 0 deletions src/com/lottery/component/MemoryPanel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.lottery.component;

import javax.swing.*;
import java.awt.*;

/**
* Created by tasly on 2014/10/21.
*/
public class MemoryPanel extends JPanel {
//状态条的颜色
private Color edgeColor = new Color(82, 115, 214);
private Color centerColor = new Color(180, 200, 230);

public void paint(Graphics g) {
super.paint(g);
//得到当前组件(JPanel)的大小
Dimension dimension = getSize();
//得到各边框的宽度
Insets insets = getInsets();
int left = insets.left;
int top = insets.top;
//得到内存使用状态信息
Runtime runtime = Runtime.getRuntime();
long freeMemory = runtime.freeMemory();
long totalMemory = runtime.totalMemory();
//组件(JPanel)除去左、右边框后的宽度
int insideWidth = dimension.width - (insets.left + insets.right);
//内存使用量的显示宽度
int usedAmount = insideWidth - (int) (((long) insideWidth * freeMemory) / totalMemory);
int insideHeight = dimension.height - (insets.bottom + insets.top);
Graphics2D g2 = (Graphics2D) g;
//设置渐变效果的画笔
g2.setPaint(new GradientPaint(left, top, edgeColor, left, insideHeight / 2, centerColor, true));
g.fillRect(left, top, usedAmount, insideHeight);
g.setColor(getBackground());
g.fillRect(left + usedAmount, top, insideWidth - usedAmount, insideHeight);
g.setFont(getFont());
g.setColor(Color.black);
//显示状态的文字
String memory = (Long.toString((totalMemory - freeMemory) / 1048576L) + "M of " + Long.toString(totalMemory / 1048576L) + 'M');
//确定文字的显示位置
FontMetrics fontmetrics = g.getFontMetrics();
int stringWidth = fontmetrics.charsWidth(memory.toCharArray(), 0, memory.length());
int stringHeight = fontmetrics.getHeight() - fontmetrics.getDescent();
//显示文字
g.drawString(memory, left + (insideWidth - stringWidth) / 2, top + (insideHeight + stringHeight) / 2);
}
}
Loading

0 comments on commit 7aa2b53

Please sign in to comment.