Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ZipApp;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import javax.swing.JLabel;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.util.zip.ZipEntry;
- import java.util.zip.ZipOutputStream;
- import javax.swing.JTextField;
- import javax.swing.ImageIcon;
- import java.awt.Color;
- import java.awt.Font;
- @SuppressWarnings("serial")
- public class FrmZip extends JFrame {
- private JPanel contentPane;
- private JLabel lblOk;
- private JTextField txt;
- private JLabel lblWall;
- private JLabel label;
- /**
- * Create the frame.
- */
- public FrmZip() {
- setTitle("Simple Zip App");
- setResizable(false);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 450, 300);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- lblOk = new JLabel("Buat Zip");
- lblOk.setFont(new Font("Comic Sans MS", Font.BOLD, 18));
- lblOk.setForeground(Color.WHITE);
- lblOk.setIcon(new ImageIcon(FrmZip.class
- .getResource("/ZipApp/file-roller-2.png")));
- lblOk.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- final StringBuilder sb = new StringBuilder();
- sb.append("" + txt.getText());
- final File f = new File("/home/resa/ArsipText.zip");
- ZipOutputStream out = null;
- try {
- out = new ZipOutputStream(new FileOutputStream(f));
- } catch (FileNotFoundException e3) {
- // TODO Auto-generated catch block
- e3.printStackTrace();
- }
- ZipEntry ze = new ZipEntry("TeksBaru.txt");
- try {
- out.putNextEntry(ze);
- } catch (IOException e2) {
- // TODO Auto-generated catch block
- e2.printStackTrace();
- }
- byte[] data = sb.toString().getBytes();
- try {
- out.write(data, 0, data.length);
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- try {
- out.closeEntry();
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- try {
- out.close();
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- });
- lblOk.setBounds(281, 138, 155, 70);
- contentPane.add(lblOk);
- txt = new JTextField();
- txt.setBounds(32, 72, 211, 23);
- contentPane.add(txt);
- txt.setColumns(10);
- label = new JLabel("<--Remote");
- label.setIcon(new ImageIcon(FrmZip.class
- .getResource("/ZipApp/gupnp-tools_av-cp.png")));
- label.setForeground(Color.WHITE);
- label.setFont(new Font("Comic Sans MS", Font.BOLD, 18));
- label.setBounds(266, 45, 170, 70);
- contentPane.add(label);
- lblWall = new JLabel("");
- lblWall.setIcon(new ImageIcon(FrmZip.class
- .getResource("/ZipApp/wall.png")));
- lblWall.setBounds(0, 0, 448, 275);
- contentPane.add(lblWall);
- setLocationRelativeTo(null);
- }
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- FrmZip frame = new FrmZip();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement