long start;
long end;
start = System.currentTimeMillis();
//++++++++++++++++++++++++++++++++++++++++proses2
end = System.currentTimeMillis();
String selisih=((end - start) / 1000.0) + " Milidetik"
+++++++++++++++++++++++++++++++++++++++++++++++++++++++JAVA SWINGNYA
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.util.Calendar;
import java.util.Date;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileNameExtensionFilter;
public class mainMenu extends javax.swing.JFrame {
Dimension UM = Toolkit.getDefaultToolkit().getScreenSize();
public mainMenu() {
initComponents();
jam();
this.setTitle("Wellcome to Cryptograph World");
setLocation(UM.width/2-getWidth()/2,UM.height/2-getHeight()/2);
show();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private void btnPilihSimpanPublicActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPilihSimpanPublicActionPerformed
if (!(txt_key.getText().equals(""))){
try {
JFileChooser savedata = new JFileChooser("D:\\");
savedata.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int returnVal = savedata.showSaveDialog(null);
if(returnVal == JFileChooser.APPROVE_OPTION) {
txt_public.setText(savedata.getSelectedFile().toString());
}
} catch (Exception e) {
}
}else{
JOptionPane.showMessageDialog(null,"please input your key name!");
}
}//GEN-LAST:event_btnPilihSimpanPublicActionPerformed
private void btnHelpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnHelpActionPerformed
//new Help().setVisible(true);
// this.dispose();
}//GEN-LAST:event_btnHelpActionPerformed
private void btnPilihSimpanPrivateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPilihSimpanPrivateActionPerformed
if(!(txt_key.getText().equals("") || txt_public.getText().equals(""))){
try {
JFileChooser savedata = new JFileChooser("D:\\");
savedata.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int returnVal = savedata.showSaveDialog(null);
if(returnVal == JFileChooser.APPROVE_OPTION) {
txt_private.setText(savedata.getSelectedFile().toString());
}
} catch (Exception e) {
}
}else{
JOptionPane.showMessageDialog(null,"please input key name and choose your save public!");
}
}//GEN-LAST:event_btnPilihSimpanPrivateActionPerformed
private void btnGenerateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGenerateActionPerformed
Thread t = new Thread(new Runnable(){
public void run(){
progressbar.setIndeterminate(true);
long start;
long end;
String namakunci = (txt_key.getText());
String a = (txt_public.getText());
String b = (txt_private.getText());
KeysGenerator key = new KeysGenerator();
if(!(txt_key.getText().equals("") || txt_public.getText().equals(""))){
try{
key.setId(namakunci);
key.setDir(a.replace("\\", "/")+"/");
key.setDirec(b.replace("\\", "/")+"/");
start = System.currentTimeMillis();//menghitung waktu proses dalam detik
key.createKeys();
progressbar.setIndeterminate(false);
end = System.currentTimeMillis();
//System.out.println("\nWaktu yang diperlukan selama proses adalah " + ((end - start) / 1000.0) + " detik");
JOptionPane.showMessageDialog(null, "Generate Key Success with duration : " +((end - start) / 1000.0) + " Milidetik", "Message", JOptionPane.INFORMATION_MESSAGE);
key.getLog();
txt_private.setText("");
txt_key.setText("");
txt_public.setText("");
}catch(Exception e){
JOptionPane.showMessageDialog(null, "Failed Generate Key", "Warning", JOptionPane.ERROR_MESSAGE);
}
}else{
JOptionPane.showMessageDialog(null, "Please entry all coloumn", "Warning", JOptionPane.ERROR_MESSAGE);
}
}
});
t.start();
}//GEN-LAST:event_btnGenerateActionPerformed
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
txt_private.setText("");
txt_key.setText("");
txt_public.setText("");
}//GEN-LAST:event_btnCancelActionPerformed
private void btnPilihFileAsalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPilihFileAsalActionPerformed
JFileChooser datafile = new JFileChooser("D:\\");
FileNameExtensionFilter filter = new FileNameExtensionFilter("File Document", "txt","doc","docx","xls","xlsx","ppt","pptx","pdf");
FileNameExtensionFilter image = new FileNameExtensionFilter("File Images", "jpg","png","bmp");
FileNameExtensionFilter audio = new FileNameExtensionFilter("File Audio", "wav","amr", "mp3");
FileNameExtensionFilter files = new FileNameExtensionFilter("File", "zip","rar");
datafile.setFileFilter(image);
datafile.setFileFilter(files);
datafile.setFileFilter(audio);
datafile.setFileFilter(filter);
datafile.setFileFilter(filter);
int returnVal = datafile.showOpenDialog(null);
if(returnVal == JFileChooser.APPROVE_OPTION) {
File file = datafile.getSelectedFile();
String dir = file.getAbsolutePath();
//System.out.println(dir);
txt_chose.setText(dir);
}
}//GEN-LAST:event_btnPilihFileAsalActionPerformed
private void btnSimpanHasilActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSimpanHasilActionPerformed
JFileChooser savedata = new JFileChooser("D:\\");
savedata.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int returnVal = savedata.showSaveDialog(null);
if(returnVal == JFileChooser.APPROVE_OPTION) {
txt_output.setText(savedata.getSelectedFile().toString());
}
}//GEN-LAST:event_btnSimpanHasilActionPerformed
private void btnPilihKeyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPilihKeyActionPerformed
//pilih PubKey
JFileChooser datafile = new JFileChooser("D:\\");
FileNameExtensionFilter filter = new FileNameExtensionFilter("public key","key");
datafile.setFileFilter(filter);
int returnVal = datafile.showOpenDialog(null);
if(returnVal == JFileChooser.APPROVE_OPTION) {
File file = datafile.getSelectedFile();
String dir = file.getAbsolutePath();
txt_select.setText(dir);
}
}//GEN-LAST:event_btnPilihKeyActionPerformed
private void btnEnkripActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEnkripActionPerformed
Thread t = new Thread(new Runnable(){
public void run(){
progressbar.setIndeterminate(true);
long start;
long end;
String Kunci = (txt_select.getText());
String filename = (txt_chose.getText());//file dipilih
String fileoutput = (txt_output.getText());//directory-folder mau simpan di?
int dot = filename.lastIndexOf(".");
int sep = filename.replace("\\", "/").lastIndexOf("/");
System.out.println("dot="+dot);//22
System.out.println("sep="+sep);//6
EncryptionFile enk = new EncryptionFile();
if (!(Kunci.equals("") || filename.equals(""))){
try {
enk.setPublicKey(Kunci);//membaca isi file Public key, set= n dan e
//String directory, String filename, String extensi=D:/Lat/en.Sistem Berjalan.doc
enk.setFile(fileoutput.replace("\\", "/"), filename.substring(sep + 1, dot), filename.substring(dot + 1) );
System.out.println("file1="+fileoutput.replace("\\", "/"));//D:/Lat
System.out.println("file2="+filename.substring(sep + 1, dot));//Sistem Berjalan
System.out.println("file3="+filename.substring(dot + 1));//doc
System.out.println("file4="+filename.replace("\\", "/"));
start = System.currentTimeMillis();//menghitung waktu proses dalam detik
enk.encrypt(filename.replace("\\", "/"));//D:/Lat/Sistem Berjalan.doc
progressbar.setIndeterminate(false);
end = System.currentTimeMillis();
//System.out.println("\nWaktu yang diperlukan selama proses adalah " + ((end - start) / 1000.0) + " detik");
JOptionPane.showMessageDialog(null, "Encryption Success with duration : " + ((end - start) / 1000.0) + " Milidetik", "Message", JOptionPane.INFORMATION_MESSAGE);
} catch (IOException ex) {
JOptionPane.showMessageDialog(null, "Failed Encryption", "Warning", JOptionPane.ERROR_MESSAGE);
}
}else{
JOptionPane.showMessageDialog(null, "Please entry all coloumn", "Warning", JOptionPane.ERROR_MESSAGE);
}
}
});
t.start();
}//GEN-LAST:event_btnEnkripActionPerformed
private void btnDekripActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDekripActionPerformed
Thread t = new Thread(new Runnable(){
public void run(){
progressbar.setIndeterminate(true);
long start;
long end;
String kunciPrivate = (txt_select.getText());
String file = (txt_chose.getText());
String fileoutput = (txt_output.getText());
int dot = file.lastIndexOf(".");
int sep = file.replace("\\", "/").lastIndexOf("/");
DecryptionFile dek = new DecryptionFile();
if (!(file.equals("") || kunciPrivate.equals(""))){
try {
dek.setPrivateKey(kunciPrivate);
dek.setFile(fileoutput.replace("\\", "/"), file.substring(sep + 1, dot), file.substring(dot + 1) );
start = System.currentTimeMillis();//menghitung waktu proses dalam milidetik
dek.decrypt(file.replace("\\", "/"));
progressbar.setIndeterminate(false);
end = System.currentTimeMillis();
//System.out.println("\nWaktu yang diperlukan selama proses adalah " + ((end - start) / 1000.0) + " detik");
JOptionPane.showMessageDialog(null, " Decryption Success with duration : "+ ((end - start) / 1000.0) + " Milidetik" , "Message", JOptionPane.INFORMATION_MESSAGE);;
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Failed Decryption", "Warning", JOptionPane.ERROR_MESSAGE);
}
}else{
JOptionPane.showMessageDialog(null, "Entry all data", "Warning", JOptionPane.ERROR_MESSAGE);
}
}
});
t.start();
}//GEN-LAST:event_btnDekripActionPerformed
void Exit () {
try {
int reply = JOptionPane.showConfirmDialog (this,
"Yakin Ingin Keluar dari Sistem?",
"SISTEM KRIPTOGRAFI FILE", JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE);
if (reply == JOptionPane.YES_OPTION) {
setVisible (false);
dispose();
System.out.println ("TERIMA KASIH TELAH MENGGUNAKAN SYSTEM INI.");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
System.exit(0);
}
else{
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
}
}
catch (Exception e) {
}
}
public void jam(){
ActionListener taskPerformer;
taskPerformer = new ActionListener() {
private Object lbljam;
@Override
public void actionPerformed(ActionEvent evt){
String nol_jam = "";
String nol_menit = "";
String nol_detik = "";
Date dt = new Date();
Calendar ca = Calendar.getInstance();
int tgl = dt.getDate();
int bln = dt.getMonth()+1;
int thn = ca.get(Calendar.YEAR);
int hari = dt.getDay();
int nilai_jam = dt.getHours();
int nilai_menit = dt.getMinutes();
int nilai_detik = dt.getSeconds();
if (nilai_jam <= 9) {
nol_jam = "0";
}
if (nilai_menit <= 9) {
nol_menit = "0";
}
if (nilai_detik <= 9) {
nol_detik = "0";
}
String jam = nol_jam + Integer.toString(nilai_jam);
String menit = nol_menit + Integer.toString(nilai_menit);
String detik = nol_detik + Integer.toString(nilai_detik);
lbl_jam.setText("<html><center> "+jam+" : "+menit+" : " + detik + "<br>" + tgl+ "/" + bln + "/"+thn+"</center></html>");
}
};
new javax.swing.Timer(0, taskPerformer).start();
}
}
Tidak ada komentar:
Posting Komentar