initComponents();
//Saat di awal aplikasi
//Judul = Untitled
this.setTitle("Untitled - NOTES");
//Atur Fillter jenis file dengan Handle fc
fc = new JFileChooser();
fc.addChoosableFileFilter(new jenisFile(EXT));
fc.addChoosableFileFilter(new jenisFile(EXT2));
//Filter Bawaan (All Files) di disable-kan
fc.setAcceptAllFileFilterUsed(false);
//variabel fileBaru diinisialisai dengan TRUE
fileBaru = true;
}
JFileChooser fc;
File file;
boolean fileBaru;
final String[] EXT = { ".csv" };
final String[] EXT2 = { ".txt", ".java" };
public String text,namafiletext;
private void msg(String pesan) {
JOptionPane.showMessageDialog(this,pesan,"Informasi", JOptionPane.INFORMATION_MESSAGE);
}
private boolean okToReplace() {
return (JOptionPane.showConfirmDialog(this, "File "+file.getName()+" Sudah Ada\n"+ "Akan Ditimpa ?",
"Peringatan",JOptionPane.YES_NO_OPTION)==0) ;
}
class jenisFile extends FileFilter {
private String[] s;
jenisFile(String[] sArg) {
s = sArg;
}
// Tentukan file apa yang akan ditampilkan
public boolean accept(File fArg) {
if (fArg.isDirectory())
return true;
// Jika Extension dari file sesuai syarat, tampilkan
for (int i = 0; i < s.length; ++i)
if (fArg.getName().toLowerCase().indexOf(s[i].toLowerCase()) > 0)
return true;
// selain kedua hal di atas, anggap false
return false;
}
public String getDescription() {
String tmp = "";
for (int i = 0; i < s.length; ++i)
tmp += "*" + s[i] + " ";
return tmp;
}
}
private void SimpanFile() {
PrintWriter pw = null;
try {
pw = new PrintWriter(new BufferedWriter(new FileWriter(file)));
} catch (IOException e) {
msg("Gagal Simpan File : '" + file.getName());
return;
}
pw.print(isi1.getText());
pw.close();
this.setTitle(file.getName()+" - NOTES" );
fileBaru = false;
}
class Enskripsimd5 {
private String convertToHex(byte[] data) {
StringBuffer buf = new StringBuffer();
for (int i = 0; i < data.length; i++) {
int halfbyte = (data[i] >>> 4) & 0x0F;
int two_halfs = 0;
do {
if ((0 <= halfbyte) && (halfbyte <= 9)) {
buf.append((char) ('0' + halfbyte));
} else {
buf.append((char) ('a' + (halfbyte - (int) geser.getValue())));
}
halfbyte = data[i] & 0x0F;
} while (two_halfs++ < 1);
}
return buf.toString();
}
public String MD5(String text)
throws NoSuchAlgorithmException, UnsupportedEncodingException {
MessageDigest md;
md = MessageDigest.getInstance("MD5");
byte[] md5hash = new byte[32];
md.update(text.getBytes("iso-8859-1"), 0, text.length());
md5hash = md.digest();
return convertToHex(md5hash);
}
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ta_java().setVisible(true);
}
});
}
private String readFile(File file){
String result="";
try{
FileInputStream fis=new FileInputStream(file);
BufferedInputStream bis=new BufferedInputStream(fis);
DataInputStream dis=new DataInputStream(bis);
while(dis.available()!=0){
result +=dis.readLine()+"\n";
}
}
catch(FileNotFoundException e){
}
catch(IOException e){
}
return result;
}
0 comments:
Posting Komentar