i default a var, present="No"; then i wanna it to change to "Yes" when i checked the checkbox.. and then update to the text file... but cannot update to textfile...
no changes have been made...
Hope there's someone out there to help..
Thanx...
***Here's my code for the checkBox...***
public void itemStateChanged(ItemEvent e) {
JCheckBox checkCb = (JCheckBox)e.getSource();
Object item = e.getItem();
if (e.getStateChange() == ItemEvent.SELECTED) {
present="Yes";
} else if (e.getStateChange() == ItemEvent.DESELECTED) {
present="No";
}
}
public void actionPerformed (ActionEvent e) {
if(e.getSource()==doneBtn){
try {
mark();
}
catch (IOException ex) {
}JOptionPane.showMessageDialog(this, "Entry Entered", "Successful", JOptionPane.INFORMATION_MESSAGE);
}
***Here's my add method to textFile***
public void mark() throws IOException {
Object rela = relation.getSelectedItem().toString();
String n = nameTf.getText();
String tel = telTf.getText();
String fam = famNoTf.getText();
String table = tableNoTf.getText();
String attend = present;
//create new object
GuestFile updatedGuest = new GuestFile(rela, n, tel, fam, table, present);
//retrieve objects from text and store in ArrayList
boolean eof=false;
String inputStr="";
ArrayList gList=new ArrayList();
GuestFile gObject;
File inputFile = new File("GuestsData.txt");
FileInputStream in = new FileInputStream(inputFile);
InputStreamReader reader = new InputStreamReader(in);
BufferedReader fileInput = new BufferedReader(reader);
while (!eof) {
try {
inputStr=fileInput.readLine();
if (inputStr==null)
eof=true;
else {
gObject=new GuestFile(inputStr,";");
gList.add(gObject);
}
} catch (EOFException e) {
eof=true;
} catch (IOException e) {
System.out.println("Error reading from file");
eof=true;
} catch (NoSuchElementException e) {
System.out.println("Error reading record:"+inputStr);
}
}
in.close();
//overwrite object to be updated with the new Object
gList.set(index, updatedGuest);
//store ArrayList back into text
File outputFile = new File("GuestsData.txt");
if (outputFile.exists()) {
outputFile.delete();
}
FileOutputStream out = new FileOutputStream(outputFile);
PrintStream fileOutput = new PrintStream(out);
for (int i=0; i<gList.size(); i++) {
gObject = (GuestFile)gList.get(i);
fileOutput.println(gObject.getRelationship() + ";" + gObject.getName() + ";" + gObject.getTel() + ";" + gObject.getFamNo() + ";" + gObject.getTableNo() + ";" + gObject.getPresent());
}
out.close();
}