kemudian tambahkan code di bawah ini di bagian atas code program...
--------------------------------
import javax.swing.DefaultListModel;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
--------------------------------
kemudian, tambahkan method baru...
--------------------------------
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;
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;
}
--------------------------------
masuk ke code di bagian buttonTambah, tapi sebelumnya tambahkan dulu code ini di atas code buttonTambah...
--------------------------------
DefaultListModel model = new DefaultListModel();
--------------------------------
kemudian masuk kedalam code button tambah...
--------------------------------
JFileChooser fc = new JFileChooser();
JFrame jf = new JFrame();
int setuju = fc.showOpenDialog(jf.add(fc));
int posisi = jList1.getModel().getSize();
if(setuju == JFileChooser.APPROVE_OPTION)
{
File file = fc.getSelectedFile();
String text = file.getPath().toString();
String[] txt = new String[]{text};
model.add(posisi, text);
}
jList1.setModel(model);
JFrame jf = new JFrame();
int setuju = fc.showOpenDialog(jf.add(fc));
int posisi = jList1.getModel().getSize();
if(setuju == JFileChooser.APPROVE_OPTION)
{
File file = fc.getSelectedFile();
String text = file.getPath().toString();
String[] txt = new String[]{text};
model.add(posisi, text);
}
jList1.setModel(model);
---------------------------------
masuk ke code buttonHapus...
---------------------------------
int posisi = jList1.getSelectedIndex();
model.remove(posisi);
---------------------------------
sebelum melangkah lebih jauh, jangan lupa uncheck properties "enabled" pada buttonBersihkan, lalu masuk ke code buttonBaca...
---------------------------------
String data = jList1.getSelectedValue().toString();
File file = new File(data);
String text = readFile(file);
jTextArea1.setText(text);
buttonBersihkan.setEnabled(true);
File file = new File(data);
String text = readFile(file);
jTextArea1.setText(text);
buttonBersihkan.setEnabled(true);
---------------------------------
code buttonBersihkan...
---------------------------------
jTextArea1.setText("");
buttonBersihkan.setEnabled(false);
buttonBersihkan.setEnabled(false);
---------------------------------
Silakan coba di-run... Kalo ada yang eror, coba di cek lagi code programnya...
kalo ada yang masih bingung, bisa PM ane di FB... Thanks..
download contoh program di netBeans
download contoh program di Eclipse
download contoh program di netBeans
download contoh program di Eclipse
2 comments:
Suwun zan postingannya :D
ujan...makasih :D
Post a Comment