private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
File archivo = null;
FileReader fr = null;
BufferedReader br = null;
try {
archivo = new File ("C://destiny.txt");
fr = new FileReader (archivo);
br = new BufferedReader(fr);
// normally I would prefer to use an ArrayList, but JList
// has a constructor that takes a Vector directly.
DefaultListModel listModel = new DefaultListModel();
String line;
while((line=br.readLine())!=null) {
System.out.println(line);
if(!listModel.contains(line))
listModel.addElement(line);
}
jList1.setModel(listModel);
} catch(Exception e) {
e.printStackTrace();
} finally {
try{
if( null != fr ) {
fr.close();
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
// TODO add your handling code here:
File archivo = null;
FileReader fr = null;
BufferedReader br = null;
try {
archivo = new File ("C://destiny.txt");
fr = new FileReader (archivo);
br = new BufferedReader(fr);
// normally I would prefer to use an ArrayList, but JList
// has a constructor that takes a Vector directly.
DefaultListModel listModel = new DefaultListModel();
String line;
while((line=br.readLine())!=null) {
System.out.println(line);
if(!listModel.contains(line))
listModel.addElement(line);
}
jList1.setModel(listModel);
} catch(Exception e) {
e.printStackTrace();
} finally {
try{
if( null != fr ) {
fr.close();
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
No comments:
Post a Comment