/*
* JFrameUnGZip.java
*
* Created on 18
Agustus 2008, 22:42
*/
/**
*
* @author Administrator
*/
import java.util.zip.*;
import java.io.*;
import java.awt.event.*;
import javax.swing.*;
public class JFrameUnGZip extends javax.swing.JFrame
implements ActionListener{
int
hasil,karakter;
File
nama_file;
String
nama="",output,input,extensi,zipper;
/** Creates new
form JFrameUnGZip */
public
JFrameUnGZip() {
super("UnGZip File");
initComponents();
setResizable(false);
tombolopen.addActionListener(this);
tombolunzip.addActionListener(this);
}
public void
actionPerformed(ActionEvent x){
if(x.getSource()==tombolopen){
setTitle("Open Gzip");
open_file.setFileSelectionMode(JFileChooser.FILES_ONLY);
open_file.setDialogTitle("Pilih File Gzip");
hasil = open_file.showOpenDialog(null);
if(hasil
== JFileChooser.CANCEL_OPTION){
setTitle("UnGZip File");
return;
}
nama_file
= open_file.getSelectedFile();
nama=nama_file.getAbsolutePath();
setTitle(nama);
karakter=nama.length();
}
if(x.getSource()==tombolunzip){
if(!nama.equals("")){
zipper="."+nama.charAt(karakter-4)+nama.charAt(karakter-3)+nama.charAt(karakter-2)+nama.charAt(karakter-1);
if(zipper.equals(".gzip")){
extensi=nama.substring(karakter-9,karakter-4);
open_file = new JFileChooser();
open_file.setFileSelectionMode(JFileChooser.FILES_ONLY);
open_file.setDialogTitle("Simpan Output File");
hasil = open_file.showSaveDialog(null);
if(hasil == JFileChooser.CANCEL_OPTION){
setTitle("UnGZip File");
return;
}
nama_file = open_file.getSelectedFile();
try {
GZIPInputStream input = new GZIPInputStream(new FileInputStream(nama));
FileOutputStream output = new
FileOutputStream(nama_file.getAbsolutePath()+extensi);
byte[] bufer = new byte[1024];
int len;
while ((len = input.read(bufer)) > 0){
output.write(bufer, 0, len);
}
output.close();
input.close();
}
catch (IOException e) {}
setTitle("UnGZip File"+nama);
}
else
JOptionPane.showMessageDialog(this,"Bukan File Gzip,
om","Error",JOptionPane.ERROR_MESSAGE);
}
else
JOptionPane.showMessageDialog(this,"Pilih Filenya dulu,
om","Error",JOptionPane.WARNING_MESSAGE);
}
}
/** 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.
*/
// <editor-fold
defaultstate="collapsed" desc="Generated
Code">//GEN-BEGIN:initComponents
private void
initComponents() {
open_file =
new javax.swing.JFileChooser();
panel1 = new
javax.swing.JPanel();
tombolopen =
new javax.swing.JButton();
tombolunzip =
new javax.swing.JButton();
tombolexit =
new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
tombolopen.setText("Open");
tombolopen.addActionListener(new java.awt.event.ActionListener() {
public
void actionPerformed(java.awt.event.ActionEvent evt) {
tombolopenActionPerformed(evt);
}
});
tombolunzip.setText("Decompress");
tombolunzip.addActionListener(new java.awt.event.ActionListener() {
public
void actionPerformed(java.awt.event.ActionEvent evt) {
tombolunzipActionPerformed(evt);
}
});
tombolexit.setText("Exit");
tombolexit.addActionListener(new java.awt.event.ActionListener() {
public
void actionPerformed(java.awt.event.ActionEvent evt) {
tombolexitActionPerformed(evt);
}
});
javax.swing.GroupLayout panel1Layout = new
javax.swing.GroupLayout(panel1);
panel1.setLayout(panel1Layout);
panel1Layout.setHorizontalGroup(
panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panel1Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
.addComponent(tombolopen, javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addComponent(tombolunzip,
javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addComponent(tombolexit, javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
.addContainerGap())
);
panel1Layout.setVerticalGroup(
panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(tombolopen)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tombolunzip)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tombolexit)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new
javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addContainerGap(187, Short.MAX_VALUE)
.addComponent(panel1,
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(panel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}//
</editor-fold>//GEN-END:initComponents
private void
tombolexitActionPerformed(java.awt.event.ActionEvent evt)
{//GEN-FIRST:event_tombolexitActionPerformed
// TODO add
your handling code here:
System.exit(0);
}//GEN-LAST:event_tombolexitActionPerformed
private void
tombolopenActionPerformed(java.awt.event.ActionEvent evt)
{//GEN-FIRST:event_tombolopenActionPerformed
// TODO add
your handling code here:
}//GEN-LAST:event_tombolopenActionPerformed
private void
tombolunzipActionPerformed(java.awt.event.ActionEvent evt)
{//GEN-FIRST:event_tombolunzipActionPerformed
// TODO add
your handling code here:
}//GEN-LAST:event_tombolunzipActionPerformed
/**
* @param args the
command line arguments
*/
public static void
main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public
void run() {
new
JFrameUnGZip().setVisible(true);
}
});
}
// Variables
declaration - do not modify//GEN-BEGIN:variables
private
javax.swing.JFileChooser open_file;
private
javax.swing.JPanel panel1;
private
javax.swing.JButton tombolexit;
private
javax.swing.JButton tombolopen;
private
javax.swing.JButton tombolunzip;
// End of
variables declaration//GEN-END:variables
}
Tidak ada komentar:
Posting Komentar