You are on page 1of 13

package aplks;

import java.io.BufferedInputStream;

import java.io.BufferedOutputStream;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.util.zip.Adler32;

import java.util.zip.CheckedInputStream;

import java.util.zip.ZipEntry;

import java.util.zip.ZipInputStream;

import javax.swing.JFileChooser;

import javax.swing.JOptionPane;

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

/*

* form.java

* Created on 30 Mar 11, 12:54:05

*/
/**

* @author Cq-510

*/

public class Decompresi extends javax.swing.JFrame {

private final JFileChooser eChooser;

public Decompresi () {

initComponents();

setLocationRelativeTo(this);

eChooser = new JFileChooser();

/** This method is called from within the constructor to

* initialize the form.

* WARNING: Do NOT modify this code. The content of this method is

* always regenerated by the Form Editor.

*/
@SuppressWarnings("unchecked")

// <editor-fold defaultstate="collapsed" desc="Generated Code">

private void initComponents() {

jPanel1 = new javax.swing.JPanel();

jLabel1 = new javax.swing.JLabel();

decompresi = new javax.swing.JButton();

jLabel2 = new javax.swing.JLabel();

jLabel3 = new javax.swing.JLabel();

input = new javax.swing.JTextField();

output = new javax.swing.JTextField();

browse1 = new javax.swing.JButton();

browse2 = new javax.swing.JButton();

kosong = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

setBackground(new java.awt.Color(255, 102, 102));

jPanel1.setBackground(new java.awt.Color(255, 102, 204));

jPanel1.setForeground(new java.awt.Color(255, 51, 51));

jLabel1.setFont(new java.awt.Font("Times New Roman", 3, 18));

jLabel1.setText("Mobile Voip Decompresi");

decompresi.setFont(new java.awt.Font("Garamond", 0, 15));


decompresi.setText("Decompresi");

decompresi.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

decompresiActionPerformed(evt);

});

jLabel2.setFont(new java.awt.Font("Garamond", 0, 15));

jLabel2.setText("AddFiles");

jLabel3.setFont(new java.awt.Font("Garamond", 0, 15));

jLabel3.setText("SaveTo");

input.setBackground(new java.awt.Color(204, 255, 204));

input.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));

input.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

inputActionPerformed(evt);

});

output.setBackground(new java.awt.Color(204, 255, 204));

output.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

outputActionPerformed(evt);
}

});

browse1.setText("Browse");

browse1.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

browse1ActionPerformed(evt);

});

browse2.setText("Browse");

browse2.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

browse2ActionPerformed(evt);

});

kosong.setFont(new java.awt.Font("Garamond", 0, 15));

kosong.setText("Clear");

kosong.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

kosongActionPerformed(evt);

});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);

jPanel1.setLayout(jPanel1Layout);

jPanel1Layout.setHorizontalGroup(

jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addContainerGap()

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILI
NG)

.addGroup(javax.swing.GroupLayout.Alignment.LEADING,
jPanel1Layout.createSequentialGroup()

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TR
AILING, false)

.addGroup(jPanel1Layout.createSequentialGroup()

.addComponent(jLabel2)

.addGap(75, 75, 75))

.addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TR
AILING, false)

.addComponent(output, javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(input, javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)))

.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 345,


javax.swing.GroupLayout.PREFERRED_SIZE))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN
G)

.addComponent(browse1)

.addComponent(browse2)))

.addGroup(jPanel1Layout.createSequentialGroup()

.addGap(169, 169, 169)

.addComponent(decompresi, javax.swing.GroupLayout.PREFERRED_SIZE, 114,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addGap(61, 61, 61)

.addComponent(kosong, javax.swing.GroupLayout.PREFERRED_SIZE, 114,


javax.swing.GroupLayout.PREFERRED_SIZE)))

.addContainerGap(16, Short.MAX_VALUE))

);

jPanel1Layout.setVerticalGroup(

jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addContainerGap()

.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 35,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addGap(36, 36, 36)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 25,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(input, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE)

.addComponent(browse1, javax.swing.GroupLayout.PREFERRED_SIZE, 27,


javax.swing.GroupLayout.PREFERRED_SIZE))

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(33, 33, 33)

.addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE))

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup()

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELI
NE)

.addComponent(output, javax.swing.GroupLayout.PREFERRED_SIZE, 35,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(browse2, javax.swing.GroupLayout.PREFERRED_SIZE, 27,


javax.swing.GroupLayout.PREFERRED_SIZE))))

.addGap(63, 63, 63)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(kosong, javax.swing.GroupLayout.PREFERRED_SIZE, 37,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(decompresi, javax.swing.GroupLayout.PREFERRED_SIZE, 37,


javax.swing.GroupLayout.PREFERRED_SIZE))

.addGap(76, 76, 76))

);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

);

layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addContainerGap(14, Short.MAX_VALUE))

);

pack();

}// </editor-fold>

private void inputActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

private void outputActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

private void decompresiActionPerformed(java.awt.event.ActionEvent evt) {

if (input.getText().equals("")) {

JOptionPane.showMessageDialog(null, "Klik dulu File Inputnya !!!", "Pesan...", 1);

browse1.doClick();

} else if (output.getText().equals("")) {

JOptionPane.showMessageDialog(null, "Klik File Outputnya !!!", "Pesan...", 1);

browse2.doClick();
}

try {

final int BUFFER = 2048;

BufferedOutputStream dest = null;

FileInputStream fis = new

FileInputStream("myfigs.zip");

CheckedInputStream checksum = new

CheckedInputStream(fis, new Adler32());

ZipInputStream zis = new

ZipInputStream(new BufferedInputStream(checksum));

ZipEntry entry;

while((entry = zis.getNextEntry()) != null) {

System.out.println("Extracting: " +entry);

int count;

byte data[] = new byte[BUFFER];

// write the files to the disk

FileOutputStream fos = new

FileOutputStream(entry.getName());

dest = new BufferedOutputStream(fos,BUFFER);

while ((count = zis.read(data, 0,

BUFFER)) != -1) {

dest.write(data, 0, count);

dest.flush();

dest.close();
}

zis.close();

System.out.println("Checksum:"+ checksum.getChecksum().getValue());

} catch(Exception e) {

e.printStackTrace();

// TODO add your handling code here:

private void browse1ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

int returnVal = eChooser.showOpenDialog(this);

if (returnVal == JFileChooser.APPROVE_OPTION) {

File source = eChooser.getSelectedFile().getAbsoluteFile();

File folder = eChooser.getSelectedFile().getParentFile();

String namaF = eChooser.getSelectedFile().getName();

input.setText(source.toString());
output.setText(folder.toString());

private void browse2ActionPerformed(java.awt.event.ActionEvent evt) {

int returnVal = eChooser.showSaveDialog(this);

if (returnVal == JFileChooser.APPROVE_OPTION) {

File folder = eChooser.getSelectedFile().getParentFile();

output.setText(folder.toString());

// TODO add your handling code here:

private void kosongActionPerformed(java.awt.event.ActionEvent evt) {

input.setText("");

output.setText("");

browse1.requestFocus();

// TODO add your handling code here:

/**

* @param args the command line arguments

*/
public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new Decompresi().setVisible(true);

});

// Variables declaration - do not modify

private javax.swing.JButton browse1;

private javax.swing.JButton browse2;

private javax.swing.JButton decompresi;

private javax.swing.JTextField input;

private javax.swing.JLabel jLabel1;

private javax.swing.JLabel jLabel2;

private javax.swing.JLabel jLabel3;

private javax.swing.JPanel jPanel1;

private javax.swing.JButton kosong;

private javax.swing.JTextField output;

// End of variables declaration

You might also like