package lesson4;
import java.awt.event.ActionEvent;
import javax.swing.filechooser.FileNameExtensionFilter;
public class Action implements java.awt.event.ActionListener{
public void actionPerformed(ActionEvent e) {
String commen = e.getActionCommand();
if(commen.equals("压缩")){
System.out.println("压缩了~");
//文件选择
javax.swing.JFileChooser Chooser = new javax.swing.JFileChooser();
int t=Chooser.showOpenDialog(null);//弹出文件选择框
if(t==Chooser.APPROVE_OPTION){//如果点击的是确定
//得到文件的绝对路径
String path=Chooser.getSelectedFile().getAbsolutePath();
HuffmanCode code = new HuffmanCode(path);
code.readFile();//读取文件
code.writeFile();//写出压缩文件
}
}if("解压缩".equals(commen)){
System.out.println("解压缩了~~");
//显示打开的窗口
javax.swing.JFileChooser chooser = new javax.swing.JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter(
"stzip压缩文件", "stzip");
chooser.setFileFilter(filter);
int returnVal = chooser.showOpenDialog(null);
if(returnVal == chooser.APPROVE_OPTION) {
String path = chooser.getSelectedFile().getAbsolutePath();//得到压缩文件的路径
HuffmanDecode decode = new HuffmanDecode(path);
decode.Decode();//解压缩文件
}
}if("退出".equals(commen)){
System.exit(0);
}if("关于".equals(commen)){
javax.swing.JOptionPane.showConfirmDialog(null, "By Stchou 2010@NetJava","关于",javax.swing.JOptionPane.YES_OPTION, javax.swing.JOptionPane.QUESTION_MESSAGE);
}
}
}