import java.io.*; import java.util.zip.*; import java.awt.*; import java.awt.event.*; import java.applet.Applet; import java.util.*; import javax.swing.*; public class FreeZip extends JApplet implements ActionListener{ final String[] pealkiri={"Nimi", "Kuupäev","Suurus","Pakituna"}; JButton nupp=new JButton("Loo uus zip"); JButton nupp1=new JButton("Ava zip"); JButton nupp2=new JButton("Paki lahti"); JLabel kiri=new JLabel("© 2001"); JTextField tf1=new JTextField("",30); Object[][] andmed=new Object[30][4]; Frame q=new Frame("Failid"); FileDialog vv=new FileDialog(q,"vali fail"); ZipInputStream zin; ZipFile uus; String fail; JTable tabel; public FreeZip(){ JPanel p =new JPanel(); JPanel p2 =new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); p2.setLayout(new BoxLayout(p2, BoxLayout.X_AXIS)); p2.add(nupp); p2.add(Box.createRigidArea(new Dimension(10,0))); p2.add(nupp1); p2.add(Box.createRigidArea(new Dimension(10,0))); p2.add(nupp2); p.add(p2); tabel=new JTable(andmed, pealkiri); JScrollPane skrollitav = new JScrollPane(tabel); p.add(tf1); p.add(skrollitav); p.add(kiri); getContentPane().add(p); p.setBorder(BorderFactory.createEmptyBorder(5,5,2,5)); p2.setBorder(BorderFactory.createEmptyBorder(0,5,5,5)); tabel.setBorder(BorderFactory.createLoweredBevelBorder()); tabel.setShowHorizontalLines(false); tf1.setEditable(false); nupp.addActionListener(this); nupp1.addActionListener(this); nupp2.addActionListener(this); nupp2.setEnabled(false); } public void actionPerformed(ActionEvent e){ if(e.getSource()==nupp){ Frame f=new Frame(" Uus ZIP fail "); f.add(new UusZip(f)); f.setSize(400,270); f.setBackground(Color.lightGray); f.setVisible(true); f.setResizable(false); } if(e.getSource()==nupp1){ Ava(); } if(e.getSource()==nupp2){ Extract(); } } public void Ava(){ for (int i=1;i<=30;i++) for (int j=1;j<=4;j++) andmed[i-1][j-1]=""; tabel=new JTable(andmed, pealkiri); tf1.setText(""); vv.setVisible(true); fail=vv.getDirectory()+vv.getFile(); tf1.setText(fail); try{ uus=new ZipFile(fail); zin=new ZipInputStream(new FileInputStream(fail)); ZipEntry ze=zin.getNextEntry(); int i=0; while(ze!=null){ andmed[i][0]=ze.getName(); Date jj=new Date(); jj.setTime(ze.getTime()); andmed[i][1]=jj+""; andmed[i][2]=ze.getSize()+""; andmed[i][3]=ze.getCompressedSize()+""; i++; ze=zin.getNextEntry(); } } catch (Exception aa) {} nupp2.setEnabled(true); } public void Extract(){ PrintWriter valja; String nimi=fail.substring(0,fail.length()-4); try{ zin=new ZipInputStream(new FileInputStream(fail)); ZipEntry ze=zin.getNextEntry(); while(ze!=null){ File kataloog=new File(nimi); kataloog.mkdir(); while(ze.isDirectory()){ String nimi2=nimi+File.separator+ze.getName(); kataloog=new File(nimi2); kataloog.mkdir(); ze=zin.getNextEntry(); } valja=new PrintWriter( new FileWriter(nimi+File.separator+ze.getName())); int nr=zin.read(); while(nr!=-1){ valja.print((char)nr); nr=zin.read(); } valja.close(); ze=zin.getNextEntry(); } } catch (Exception aa) {} } public static void main(String Arg[] ){ Frame f=new Frame(" FreeZip "); f.add(new FreeZip()); f.setSize(475,300); f.setBackground(Color.lightGray); f.setVisible(true); f.setResizable(false); f.addWindowListener(new ara3()); } }