简易版WinZip

来源:互联网 发布:初识动画软件教学设计 编辑:程序博客网 时间:2024/04/25 17:13
  1. lsgZip.java
  2. import java.awt.BorderLayout;
  3. import java.awt.Container;
  4. import java.awt.Dimension;
  5. import java.awt.FlowLayout;
  6. import java.awt.Toolkit;
  7. import java.awt.event.ActionEvent;
  8. import java.awt.event.ActionListener;
  9. import java.awt.event.MouseAdapter;
  10. import java.awt.event.MouseEvent;
  11. import java.awt.event.WindowAdapter;
  12. import java.awt.event.WindowEvent;
  13. import java.io.File;
  14. import java.io.FileInputStream;
  15. import java.io.FileNotFoundException;
  16. import java.io.FileOutputStream;
  17. import java.io.IOException;
  18. import java.io.InputStream;
  19. import java.util.Date;
  20. import java.util.zip.ZipEntry;
  21. import java.util.zip.ZipFile;
  22. import java.util.zip.ZipInputStream;
  23. import java.util.zip.ZipOutputStream;
  24. import javax.swing.AbstractButton;
  25. import javax.swing.ImageIcon;
  26. import javax.swing.JButton;
  27. import javax.swing.JFileChooser;
  28. import javax.swing.JFrame;
  29. import javax.swing.JLabel;
  30. import javax.swing.JMenu;
  31. import javax.swing.JMenuBar;
  32. import javax.swing.JMenuItem;
  33. import javax.swing.JPanel;
  34. import javax.swing.JScrollPane;
  35. import javax.swing.JTable;
  36. import javax.swing.JToolBar;
  37. import javax.swing.ListSelectionModel;
  38. import javax.swing.filechooser.FileFilter;
  39. import javax.swing.filechooser.FileNameExtensionFilter;
  40. import javax.swing.table.DefaultTableModel;
  41. import javax.swing.JOptionPane;
  42. /**
  43.  * 作者:李 世贵
  44.  * JDK: 1.6
  45.  * 来源: http://blog.csdn.net/lishigui
  46.  * 欢迎转接,请保留作者和来源,谢谢!
  47.  * 2008-9-28 上午09:49:06
  48.  * 
  49.  */
  50. public class lsgZip extends JFrame{
  51.     
  52.      private static final long serialVersionUID = 1L;
  53.      private int r=0;
  54.      private int[] selectTableRow;
  55.      private byte[] b=new byte[4096];
  56.      private File file = null;
  57.      private JTable table = null;
  58.      private ZipEntry zipEntry = null;
  59.      private JLabel labStatus = new JLabel();
  60.      private String[] zipEntryInfo = new String[3];
  61.      private MyTable defaultModel = null;
  62.      private FileInputStream in = null;
  63.      private ZipOutputStream zipfile;
  64.      private JFileChooser filechooser = new JFileChooser();
  65.      private String[] tableFields = {"文件名","路径","文件大小"};
  66.      private FileFilter filter = new FileNameExtensionFilter("zip file","zip");
  67.      public lsgZip() {
  68.         super("李世贵简易版WinZip");
  69.         Container container = getContentPane();
  70.         container.setLayout(new BorderLayout());
  71.         JMenuBarEven action = new JMenuBarEven();
  72.         String[] emnuName ={"文件(F)@" + (int)'F'"操作(O)@" + (int)'O'"帮助(H)@" + (int)'H'};
  73.         String[][]itemName = {{"新建(N)@" + (int)'N'"打开(O)@" + (int)'O'"退出(Q)@" + (int)'Q'}, {"添加(A)@" + (int)'A'"删除(D)@" + (int)'D'"解压(E)@" + (int)'E'}, {"手册(S)@" + (int)'S'"关于(A)@" + (int)'A'}};
  74.         String[] name = {"把文件添加到压缩文件中""解压压缩文件""删除文件""退出"}; 
  75.         String[] image = {"image/Add.JPG""image/Extract.JPG""image/Delete.JPG""image/Exit.JPG"};
  76.         String[] text = {"添加""解压""删除""退出"};
  77.         
  78.         this.setJMenuBar(createJMenuBar(emnuName, itemName, action));
  79.         defaultModel = new MyTable(null, tableFields);
  80.         table = new JTable(defaultModel);
  81.         table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
  82.         table.addMouseListener(new MouseAdapter(){
  83.             public void mouseReleased(MouseEvent e){
  84.                 selectTableRow = table.getSelectedRows();
  85.             }
  86.         });
  87.         
  88.         this.addWindowListener(new WindowAdapter(){
  89.             public void windowClosing(WindowEvent e){
  90.                 try {
  91.                     if(zipfile != null){
  92.                         zipfile.close();
  93.                     }
  94.                 } catch (IOException e1) {
  95.                 }
  96.                 System.exit(0);
  97.             }
  98.         });
  99.         
  100.         container.add(createJToolBar(name, image, null, action), BorderLayout.NORTH);
  101.         container.add(new JScrollPane(table), BorderLayout.CENTER);
  102.         container.add(createStatusbar(), BorderLayout.SOUTH);
  103.         Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();
  104.         
  105.         this.setLocation((int)(screensize.getWidth()-300)/2, (int)(screensize.getHeight()-400)/2);
  106.         setSize(300,400);
  107.         setVisible(true);
  108.     }
  109.     //创建JMnuBar
  110.     private JMenuBar createJMenuBar(String[] menuName, String[][] itemName, ActionListener action) {
  111.         JMenuBar bar = new JMenuBar();
  112.         JMenu[] menu = new JMenu[menuName.length];
  113.         for(int i = 0; i < menuName.length; i++){
  114.             if(menuName[i].split("@").length > 1){
  115.                 menu[i] = new JMenu(menuName[i].split("@")[0]);
  116.                 menu[i].setMnemonic(Integer.parseInt(menuName[i].split("@")[1]));
  117.             }else{
  118.                 menu[i] = new JMenu(menuName[i]);
  119.             }
  120.             JMenuItem[] item = new JMenuItem[itemName[i].length];
  121.             for(int j = 0; j < itemName[i].length; j++){
  122.                 if(itemName[i][j].split("@").length > 1){
  123.                     item[j] = new JMenuItem(itemName[i][j].split("@")[0],Integer.parseInt(itemName[i][j].split("@")[1]));
  124.                 }else{
  125.                     item[j] = new JMenuItem(itemName[i][j]);
  126.                 }
  127.                 item[j].addActionListener(action);
  128.                 menu[i].add(item[j]);
  129.             }
  130.             bar.add(menu[i]);
  131.         }
  132.         return bar;
  133.         
  134.     }
  135.     //创建JToolBar
  136.     private JToolBar createJToolBar(String[] name, String[] image, String[] text,ActionListener action){
  137.         JToolBar bar = new JToolBar();
  138.         for(int i = 0; i < name.length; i++){
  139.             JButton b = new JButton(new ImageIcon(this.getClass().getResource(image[i])));
  140.             if(text!=null){
  141.                 b.setText(text[i]);
  142.                 b.setVerticalTextPosition(AbstractButton.BOTTOM);
  143.                 b.setHorizontalTextPosition(AbstractButton.CENTER);
  144.             }
  145.             if(name!=null){
  146.                 b.setToolTipText(name[i]);
  147.             }
  148.             b.addActionListener(action);
  149.             bar.add(b);
  150.         }
  151.         return bar;
  152.     }
  153.     //创建Statusbar
  154.     private JPanel createStatusbar(){
  155.         JPanel statusbar = new JPanel();
  156.         statusbar.setLayout(new FlowLayout(FlowLayout.LEADING));
  157.         statusbar.add(labStatus);
  158.         return statusbar;
  159.     }
  160.     //重写DefaultTableModel使它不能编辑
  161.     class MyTable extends DefaultTableModel {
  162.         public MyTable(Object[][] Info, String[] names){
  163.             super(Info,names);
  164.         }
  165.        public boolean isCellEditable(int rowIndex, int columnIndex) {
  166.             return false;
  167.        }     
  168.     }
  169.     //侦听JMenuBar和JToolBar事件
  170.     class JMenuBarEven implements ActionListener{
  171.         public void actionPerformed(ActionEvent e) {
  172.             //处理"新建"事件
  173.             if(e.getActionCommand().equals("新建(N)")){
  174.                 newFile();
  175.             }
  176.             //处理"打开"事件
  177.             if(e.getActionCommand().equals("打开(O)")){
  178.                 openFile();
  179.             }
  180.             //处理"退出"事件
  181.             if(e.getActionCommand().equals("退出(Q)")){
  182.                 if(zipfile != null){
  183.                     try {
  184.                         zipfile.close();
  185.                     } catch (IOException e1) {}
  186.                 }
  187.                 lsgZip.this.dispose();
  188.                 System.exit(0);
  189.             }
  190.             //处理"添加"事件
  191.             if(e.getActionCommand().equals("添加(A)")){
  192.                 if(zipfile == null ){
  193.                     newFile();
  194.                     addFile();
  195.                 }else{
  196.                     addFile();
  197.                 }
  198.             }
  199.             //处理"删除"事件
  200.             if(e.getActionCommand().equals("删除(D)")){
  201.                 if(selectTableRow != null){
  202.                     r = selectTableRow.length;
  203.                     for(int i= 0; i < r; i++){
  204.                         defaultModel.removeRow(selectTableRow[r-i-1]);
  205.                         table.validate();
  206.                     }
  207.                     if(r > 0){
  208.                         delFile();
  209.                     }
  210.                     r = 0;
  211.                 }
  212.             }
  213.             //处理"解压"事件
  214.             if(e.getActionCommand().equals("解压(E)")){
  215.                 if(selectTableRow != null ){
  216.                     if(selectTableRow.length > 0 ){
  217.                         unzip();
  218.                     }
  219.                 }
  220.             }
  221.             //处理"手册"事件
  222.             if(e.getActionCommand().equals("手册(S)")){
  223.                 new helpDialog(lsgZip.this,"手册",false);
  224.             }
  225.             //处理"关于"事件
  226.             if(e.getActionCommand().equals("关于(A)")){
  227.                 new aboutDialog(lsgZip.this,"关于",true);
  228.                 
  229.             }
  230.             //处理"JToolBar"事件
  231.             if(e.getActionCommand().equals("")){
  232.                 JButton button = (JButton)e.getSource();
  233.                 if(button.getToolTipText().equals("把文件添加到压缩文件中")){
  234.                     if(zipfile == null ){
  235.                         newFile();
  236.                         addFile();
  237.                     }else{
  238.                         addFile();
  239.                     }
  240.                 }
  241.                 if(button.getToolTipText().equals("解压压缩文件")){
  242.                     if(selectTableRow != null ){
  243.                         if(selectTableRow.length > 0 ){
  244.                             unzip();
  245.                         }
  246.                     }
  247.                 }
  248.                 if(button.getToolTipText().equals("删除文件")){
  249.                     if(selectTableRow != null){
  250.                         r = selectTableRow.length;
  251.                         for(int i= 0; i < r; i++){
  252.                             defaultModel.removeRow(selectTableRow[r-i-1]);
  253.                             table.validate();
  254.                         }
  255.                         if(r > 0){
  256.                             delFile();
  257.                         }
  258.                         r = 0;
  259.                     }
  260.                 }
  261.                 if(button.getToolTipText().equals("退出")){
  262.                     if(zipfile != null){
  263.                         try {
  264.                             zipfile.close();
  265.                         } catch (IOException e1) {}
  266.                     }
  267.                     lsgZip.this.dispose();
  268.                     System.exit(0);
  269.                 }
  270.             }
  271.         }
  272.     }
  273.     //新建处理
  274.     private void newFile(){
  275.         try{
  276.             filechooser.setFileFilter(filter);
  277.             filechooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
  278.             filechooser.setSelectedFile(new File("lsg.zip"));
  279.             int result = filechooser.showDialog(lsgZip.this"新建压缩文件");
  280.             
  281.             if ( result != JFileChooser.CANCEL_OPTION ){
  282.                 File newfile = filechooser.getSelectedFile(); 
  283.                 if(newfile.exists()){
  284.                     result = JOptionPane.showConfirmDialog(lsgZip.this"文件已存在,是否覆盖现有的文件""提示", JOptionPane.YES_NO_OPTION);
  285.                     if(result == JOptionPane.NO_OPTION){
  286.                         newFile();
  287.                     }
  288.                     if(result == JOptionPane.YES_OPTION){
  289.                         if(zipfile != null){
  290.                             zipfile.close();
  291.                             removeTableRow();
  292.                         }
  293.                         file = newfile;
  294.                         zipfile = new ZipOutputStream(new FileOutputStream(file));
  295.                     }
  296.                 }else{
  297.                     if(filechooser.getSelectedFile() != null){
  298.                         file = filechooser.getSelectedFile();
  299.                         if(zipfile != null){
  300.                             zipfile.close();
  301.                             removeTableRow();
  302.                         }
  303.                         zipfile = new ZipOutputStream(new FileOutputStream(file));
  304.                     }
  305.                     
  306.                 }
  307.             }
  308.         } catch (FileNotFoundException e) { 
  309.             e.printStackTrace(); 
  310.         } catch (IOException e) { 
  311.             e.printStackTrace(); 
  312.         }
  313.     }
  314.     //打开处理
  315.     private void openFile(){
  316.         try {
  317.             filechooser.setFileFilter(filter);
  318.             filechooser.setSelectedFile(null);
  319.             filechooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
  320.             int result = filechooser.showDialog(lsgZip.this"打开压缩文件");
  321.             if ( result != JFileChooser.CANCEL_OPTION ){
  322.                 File openfile = filechooser.getSelectedFile();
  323.                 if(openfile != null){
  324.                     startopen(openfile);
  325.                 }
  326.             }
  327.         } catch (IOException e) {
  328.             e.printStackTrace();
  329.         }
  330.     }
  331.     //开始执行打开处理
  332.     private void startopen(File openfile) throws IOException{
  333.         file = openfile;
  334.         if(zipfile != null){
  335.             try{
  336.                 zipfile.close();
  337.             }catch(Exception e){}
  338.         }
  339.         removeTableRow();
  340.         openfile = new File(file.getParent() + "/lsg.tem");
  341.         if(openfile.exists()){
  342.             openfile.delete();
  343.         }
  344.         file.renameTo(openfile);
  345.         while(!openfile.exists()){
  346.             file.renameTo(openfile);
  347.         }
  348.         zipfile = new ZipOutputStream(new FileOutputStream(file));
  349.         ZipInputStream zipin = new ZipInputStream(new FileInputStream(openfile));
  350.         zipEntry = zipin.getNextEntry();
  351.         while(zipEntry != null){
  352.             zipfile.putNextEntry(zipEntry);
  353.             while((r = zipin.read(b, 04096)) > -1){
  354.                 zipfile.write(b, 0, r);
  355.             }
  356.             getEntryInfo(zipEntry);
  357.             zipEntry = zipin.getNextEntry();
  358.         }
  359.         zipin.close();
  360.         openfile.delete();
  361.     }
  362.     //添加处理
  363.     private void addFile(){
  364.         try{
  365.             filechooser.setFileFilter(null);
  366.             filechooser.setSelectedFile(null);
  367.             filechooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
  368.             int result = filechooser.showDialog(lsgZip.this"添加文件到压缩文件中");
  369.             if(result == JFileChooser.CANCEL_OPTION){
  370.                 return;
  371.             }
  372.             File files = filechooser.getSelectedFile();
  373.             zipfile.setMethod(ZipOutputStream.DEFLATED);
  374.             if(files.isDirectory()){
  375.                  Visitor(files, files.getName(), zipfile);
  376.             }else{
  377.                 zipEntry = new ZipEntry(files.getName());
  378.                 zipEntry.setSize(files.length());
  379.                 zipEntry.setTime(new Date().getTime());
  380.                 zipfile.putNextEntry(zipEntry); 
  381.                 in = new FileInputStream(files); 
  382.                 while((r = in.read(b,0,4096)) > 0){ 
  383.                     zipfile.write(b,0,r); 
  384.                 } 
  385.                 getEntryInfo(zipEntry); 
  386.                 in.close(); 
  387.                 zipfile.closeEntry();
  388.             }
  389.         } catch (FileNotFoundException e) { 
  390.             e.printStackTrace(); 
  391.         } catch (IOException e) { 
  392.             e.printStackTrace(); 
  393.         }
  394.     }
  395.     
  396.     //删除文件处理
  397.     private void delFile(){
  398.         try {
  399.             File delfile = null;
  400.             if(selectTableRow.length > 0){
  401.                 if(zipfile != null){
  402.                     try{
  403.                         zipfile.finish();
  404.                         zipfile.close();
  405.                     }catch(Exception e){}
  406.                 }
  407.                 delfile = new File(file.getParent()+"/lsg.tem");
  408.                 delfile.delete();
  409.                 file.renameTo(delfile);
  410.                 zipfile = new ZipOutputStream(new FileOutputStream(file));
  411.                 ZipFile filein = new ZipFile(delfile);
  412.                 InputStream in = null;
  413.                 for(int i = 0;i < table.getRowCount(); i++){
  414.                     zipEntry = filein.getEntry(defaultModel.getValueAt(i, 1).toString());
  415.                     zipfile.putNextEntry(zipEntry);
  416.                     in = filein.getInputStream(zipEntry);
  417.                     while((r = in.read(b, 04096))>-1){
  418.                         zipfile.write(b, 0, r);
  419.                     }
  420.                 }
  421.                 if(in != null){
  422.                     in.close();
  423.                 }
  424.                 filein.close();
  425.                 delfile.delete();
  426.             }
  427.         } catch (IOException e) {
  428.             e.printStackTrace();
  429.         }
  430.     }
  431.     //解压处理
  432.     private void unzip(){
  433.         try{
  434.             filechooser.setFileFilter(null);
  435.             filechooser.setSelectedFile(null);
  436.             filechooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  437.             int result = filechooser.showDialog(lsgZip.this"解压");
  438.             if(result == JFileChooser.CANCEL_OPTION){
  439.                 return;
  440.             }
  441.             File outfile = filechooser.getSelectedFile();
  442.             String filetring;
  443.             if(outfile.toString().endsWith("//")){
  444.                 filetring = outfile.toString(); 
  445.             }else{
  446.                 filetring = outfile.toString() + "//"
  447.             }
  448.             if(file != null){
  449.                 zipfile.close();
  450.                 ZipFile zipin = new ZipFile(file);
  451.                 File f;
  452.                 File parent;
  453.                 InputStream in;
  454.                 FileOutputStream out = null;
  455.                 for(int i = 0; i < selectTableRow.length; i++){
  456.                     zipEntry = new ZipEntry(table.getValueAt(selectTableRow[i], 1).toString());
  457.                     f = new File(filetring + zipEntry.toString());
  458.                     parent = new File(f.getParent());
  459.                     if(!parent.exists()){
  460.                         parent.mkdirs();
  461.                     }
  462.                     in = zipin.getInputStream(zipEntry);
  463.                     out = new FileOutputStream(f);
  464.                     while((r = in.read(b, 04096)) > -1){
  465.                         out.write(b, 0, r);
  466.                     }
  467.                     in.close();
  468.                     out.close();
  469.                 }
  470.                 zipin.close();
  471.                 File openfile = new File(file.toString());
  472.                 startopen(openfile);
  473.             }
  474.             
  475.         } catch (FileNotFoundException e) { 
  476.              
  477.             e.printStackTrace(); 
  478.         } catch (IOException e) { 
  479.            
  480.             e.printStackTrace(); 
  481.         }
  482.     }
  483.     //将文件写到压缩文件
  484.     private void Visitor(File directory, String entry, ZipOutputStream zipfile){
  485.         try{
  486.             File file = null;
  487.             String[] fileList = directory.list();
  488.             for(int i = 0; i < fileList.length; i++){
  489.                 file = new File(directory.toString() + "/" + fileList[i]);
  490.                 if(file.isDirectory()){
  491.                      Visitor(file, entry + "/" + file.getName(), zipfile);
  492.                 }else{
  493.                     zipEntry = new ZipEntry(entry + "/" + file.getName());
  494.                     zipEntry.setSize(file.length());
  495.                     zipEntry.setTime(new Date().getTime());
  496.                     zipfile.putNextEntry(zipEntry); 
  497.                     in=new FileInputStream(file); 
  498.                     while((r=in.read(b,0,4096))>0){ 
  499.                         zipfile.write(b,0,r); 
  500.                     } 
  501.                     getEntryInfo(zipEntry);
  502.                     in.close(); 
  503.                     zipfile.closeEntry();
  504.                 }
  505.             }
  506.         } catch (FileNotFoundException e) { 
  507.             e.printStackTrace(); 
  508.         } catch (IOException e) { 
  509.             e.printStackTrace(); 
  510.         } 
  511.     }
  512.     //在Entry的信息插入table中显示
  513.     private void getEntryInfo(ZipEntry entry){
  514.         File file = null;
  515.         file = new File(entry.toString());
  516.         zipEntryInfo[0] = file.getName();
  517.         zipEntryInfo[1] = entry.toString();
  518.         if(entry.getSize()==-1){
  519.             zipEntryInfo[2] = "未知";
  520.         }else{
  521.             zipEntryInfo[2] = entry.getSize() / 1024 + "." + entry.getSize() % 1024 + "K";
  522.         }
  523.         defaultModel.addRow(zipEntryInfo);  
  524.         table.validate();
  525.         this.validate();
  526.     }
  527.     //删除表中所有的数据
  528.     private void removeTableRow(){
  529.         while(defaultModel.getRowCount()>0){
  530.             defaultModel.removeRow(0);
  531.             table.validate();
  532.         }       
  533.     }
  534.     
  535.     public static void main(String[] args) {
  536.         new lsgZip();
  537.     }
  538. }
  539. helpDialog.java
  540. import java.awt.Container;
  541. import java.awt.FlowLayout;
  542. import java.awt.Frame;
  543. import javax.swing.JDialog;
  544. import javax.swing.JLabel;
  545. public class helpDialog extends JDialog {
  546.     private static final long serialVersionUID = 1L;
  547.     public helpDialog(Frame arg0, String arg1, boolean arg2) {
  548.         super(arg0, arg1, arg2);
  549.         Container container = getContentPane();
  550.         container.setLayout(new FlowLayout(FlowLayout.LEFT));
  551.         JLabel label = new JLabel();
  552.         label.setText(
  553.             "<html><h2 align=center><FONT color=blue>手册  </FONT></h2>" +
  554.             "<p><FONT color=blue>新建压缩文件:</FONT>" +
  555.             "<br>在菜单栏中选择"文件"->"新建",在弹出" +
  556.             "<br>对话框中选择"新建压缩文件"的保存路径,然" +
  557.             "<br>后输入"新建压缩文件"的文件名,默认的文件" +
  558.             "<br>名是lag.zip.新建好压缩文件后就可以往"新" +
  559.             "<br>建压缩文件"中添加多个文件夹或文件"+
  560.             "<P><FONT color=blue>打开压缩文件:</FONT>" +
  561.             "<br>在菜单栏中选择"文件"->"打开",在弹出对" +
  562.             "<br>话框中选择要打开的压缩文件,单击打开,就可以" +
  563.             "<br>打开压缩文件"+
  564.             "<p><FONT color=blue>添加文件到压缩文件:</FONT>" +
  565.             "<br>在菜单栏中选择"操作"->"添加"或者单击工" +
  566.             "<br>具栏中的"添加",在弹出对话框中选择文件或文件" +
  567.             "<br>夹添加到当前的压缩文件"+
  568.             "<p><FONT color=blue>删除压缩文件中的文件:</FONT>" +
  569.             "<br>在表中选择一个或者多个文件,然后单击菜单栏中选" +
  570.             "<br>择"操作"->"删除"或者单击工具栏中的"删除"," +
  571.             "<br>就可以删除选择中的文件了"+
  572.             "<p><FONT color=blue>解压压缩文件:</FONT>" +
  573.             "<br>在表中选择一个或者多个文件,然后单击菜单栏中选择" +
  574.             "<br>"操作"->"解压"或者单击工具栏中的"解压"," +
  575.             "<br>在弹出对话框中选择保存解压文件的路径,就可" +
  576.             "<br>以解压选择中的文件了"+
  577.             "<p><FONT color=blue>退出程序:</FONT>" +
  578.             "<br>单击右上角的关闭,在菜单栏中选择"文件"->" +
  579.             "<br>"退出",单击工具栏中的"退出"都能退出程序"+"</html>"  
  580.         );
  581.         this.setResizable(false);
  582.         container.add(label);
  583.         setSize(390,550);
  584.         setVisible(true);
  585.     }
  586. }
  587. helpDialog.java
  588. import java.awt.Container;
  589. import java.awt.FlowLayout;
  590. import java.awt.Frame;
  591. import javax.swing.JDialog;
  592. import javax.swing.JLabel;
  593. public class helpDialog extends JDialog {
  594.     private static final long serialVersionUID = 1L;
  595.     public helpDialog(Frame arg0, String arg1, boolean arg2) {
  596.         super(arg0, arg1, arg2);
  597.         Container container = getContentPane();
  598.         container.setLayout(new FlowLayout(FlowLayout.LEFT));
  599.         JLabel label = new JLabel();
  600.         label.setText(
  601.             "<html><h2 align=center><FONT color=blue>手册  </FONT></h2>" +
  602.             "<p><FONT color=blue>新建压缩文件:</FONT>" +
  603.             "<br>在菜单栏中选择"文件"->"新建",在弹出" +
  604.             "<br>对话框中选择"新建压缩文件"的保存路径,然" +
  605.             "<br>后输入"新建压缩文件"的文件名,默认的文件" +
  606.             "<br>名是lag.zip.新建好压缩文件后就可以往"新" +
  607.             "<br>建压缩文件"中添加多个文件夹或文件"+
  608.             "<P><FONT color=blue>打开压缩文件:</FONT>" +
  609.             "<br>在菜单栏中选择"文件"->"打开",在弹出对" +
  610.             "<br>话框中选择要打开的压缩文件,单击打开,就可以" +
  611.             "<br>打开压缩文件"+
  612.             "<p><FONT color=blue>添加文件到压缩文件:</FONT>" +
  613.             "<br>在菜单栏中选择"操作"->"添加"或者单击工" +
  614.             "<br>具栏中的"添加",在弹出对话框中选择文件或文件" +
  615.             "<br>夹添加到当前的压缩文件"+
  616.             "<p><FONT color=blue>删除压缩文件中的文件:</FONT>" +
  617.             "<br>在表中选择一个或者多个文件,然后单击菜单栏中选" +
  618.             "<br>择"操作"->"删除"或者单击工具栏中的"删除"," +
  619.             "<br>就可以删除选择中的文件了"+
  620.             "<p><FONT color=blue>解压压缩文件:</FONT>" +
  621.             "<br>在表中选择一个或者多个文件,然后单击菜单栏中选择" +
  622.             "<br>"操作"->"解压"或者单击工具栏中的"解压"," +
  623.             "<br>在弹出对话框中选择保存解压文件的路径,就可" +
  624.             "<br>以解压选择中的文件了"+
  625.             "<p><FONT color=blue>退出程序:</FONT>" +
  626.             "<br>单击右上角的关闭,在菜单栏中选择"文件"->" +
  627.             "<br>"退出",单击工具栏中的"退出"都能退出程序"+"</html>"  
  628.         );
  629.         this.setResizable(false);
  630.         container.add(label);
  631.         setSize(390,550);
  632.         setVisible(true);
  633.     }
  634. }
  635. aboutDialog.java
  636. import java.awt.Container;
  637. import java.awt.Dialog;
  638. import java.awt.FlowLayout;
  639. import java.awt.Frame;
  640. import java.awt.GraphicsConfiguration;
  641. import java.awt.Window;
  642. import javax.swing.JDialog;
  643. import javax.swing.JLabel;
  644. public class aboutDialog extends JDialog {
  645.     public aboutDialog(Frame arg0, String arg1, boolean arg2) {
  646.         super(arg0, arg1, arg2);
  647.         Container container = getContentPane();
  648.         container.setLayout(new FlowLayout(FlowLayout.LEFT));
  649.         JLabel label = new JLabel();
  650.         label.setText("<html><h3 align=center><FONT color=blue>   李世贵简易版WinZip</FONT></h3>" +
  651.                             "<b align=left><FONT color=blue> Version:</FONT>1.0</b>" +
  652.                             "<br><b align=left> <FONT color=blue>Author:</FONT>   lishigui</b></html>");
  653.         container.add(label);
  654.         this.setResizable(false);
  655.         setSize(180,150);
  656.         setVisible(true);
  657.     }
  658. }
  659. 该程序在我的资源网可以下载,欢迎你下载使用哦!
  660. 我的资源网地址是:http://lishigui.download.csdn.net/

程序运行的界面如下:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

原创粉丝点击