Advertisement
resacr

Aplikasi Zip Sederhana

Dec 22nd, 2015
603
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.29 KB | None | 0 0
  1. package ZipApp;
  2.  
  3. import java.awt.EventQueue;
  4. import javax.swing.JFrame;
  5. import javax.swing.JPanel;
  6. import javax.swing.border.EmptyBorder;
  7. import javax.swing.JLabel;
  8. import java.awt.event.MouseAdapter;
  9. import java.awt.event.MouseEvent;
  10. import java.io.File;
  11. import java.io.FileNotFoundException;
  12. import java.io.FileOutputStream;
  13. import java.io.IOException;
  14. import java.util.zip.ZipEntry;
  15. import java.util.zip.ZipOutputStream;
  16. import javax.swing.JTextField;
  17. import javax.swing.ImageIcon;
  18. import java.awt.Color;
  19. import java.awt.Font;
  20.  
  21. @SuppressWarnings("serial")
  22. public class FrmZip extends JFrame {
  23.  
  24.     private JPanel contentPane;
  25.     private JLabel lblOk;
  26.     private JTextField txt;
  27.     private JLabel lblWall;
  28.     private JLabel label;
  29.  
  30.     /**
  31.      * Create the frame.
  32.      */
  33.     public FrmZip() {
  34.         setTitle("Simple Zip App");
  35.         setResizable(false);
  36.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  37.         setBounds(100, 100, 450, 300);
  38.         contentPane = new JPanel();
  39.         contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  40.         setContentPane(contentPane);
  41.         contentPane.setLayout(null);
  42.  
  43.         lblOk = new JLabel("Buat Zip");
  44.         lblOk.setFont(new Font("Comic Sans MS", Font.BOLD, 18));
  45.         lblOk.setForeground(Color.WHITE);
  46.         lblOk.setIcon(new ImageIcon(FrmZip.class
  47.                 .getResource("/ZipApp/file-roller-2.png")));
  48.         lblOk.addMouseListener(new MouseAdapter() {
  49.             @Override
  50.             public void mouseClicked(MouseEvent e) {
  51.                 final StringBuilder sb = new StringBuilder();
  52.                 sb.append("" + txt.getText());
  53.  
  54.                 final File f = new File("/home/resa/ArsipText.zip");
  55.                 ZipOutputStream out = null;
  56.                 try {
  57.                     out = new ZipOutputStream(new FileOutputStream(f));
  58.                 } catch (FileNotFoundException e3) {
  59.                     // TODO Auto-generated catch block
  60.                     e3.printStackTrace();
  61.                 }
  62.                 ZipEntry ze = new ZipEntry("TeksBaru.txt");
  63.                 try {
  64.                     out.putNextEntry(ze);
  65.                 } catch (IOException e2) {
  66.                     // TODO Auto-generated catch block
  67.                     e2.printStackTrace();
  68.                 }
  69.  
  70.                 byte[] data = sb.toString().getBytes();
  71.                 try {
  72.                     out.write(data, 0, data.length);
  73.                 } catch (IOException e1) {
  74.                     // TODO Auto-generated catch block
  75.                     e1.printStackTrace();
  76.                 }
  77.                 try {
  78.                     out.closeEntry();
  79.                 } catch (IOException e1) {
  80.                     // TODO Auto-generated catch block
  81.                     e1.printStackTrace();
  82.                 }
  83.  
  84.                 try {
  85.                     out.close();
  86.                 } catch (IOException e1) {
  87.                     // TODO Auto-generated catch block
  88.                     e1.printStackTrace();
  89.                 }
  90.             }
  91.         });
  92.         lblOk.setBounds(281, 138, 155, 70);
  93.         contentPane.add(lblOk);
  94.  
  95.         txt = new JTextField();
  96.         txt.setBounds(32, 72, 211, 23);
  97.         contentPane.add(txt);
  98.         txt.setColumns(10);
  99.  
  100.         label = new JLabel("<--Remote");
  101.         label.setIcon(new ImageIcon(FrmZip.class
  102.                 .getResource("/ZipApp/gupnp-tools_av-cp.png")));
  103.         label.setForeground(Color.WHITE);
  104.         label.setFont(new Font("Comic Sans MS", Font.BOLD, 18));
  105.         label.setBounds(266, 45, 170, 70);
  106.         contentPane.add(label);
  107.  
  108.         lblWall = new JLabel("");
  109.         lblWall.setIcon(new ImageIcon(FrmZip.class
  110.                 .getResource("/ZipApp/wall.png")));
  111.         lblWall.setBounds(0, 0, 448, 275);
  112.         contentPane.add(lblWall);
  113.         setLocationRelativeTo(null);
  114.     }
  115.  
  116.     /**
  117.      * Launch the application.
  118.      */
  119.     public static void main(String[] args) {
  120.         EventQueue.invokeLater(new Runnable() {
  121.             public void run() {
  122.                 try {
  123.                     FrmZip frame = new FrmZip();
  124.                     frame.setVisible(true);
  125.                 } catch (Exception e) {
  126.                     e.printStackTrace();
  127.                 }
  128.             }
  129.         });
  130.     }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement