This week's book giveaway is in the HTML/CSS/JavaScript forum.
We're giving away four copies of Practical SVG and have Chris Coyier on-line!
See this thread for details.
Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JCheckBox and File IO **Help**

Jessie Tan
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
***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) {
} else if (e.getStateChange() == ItemEvent.DESELECTED) {
public void actionPerformed (ActionEvent e) {

try {
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 {
if (inputStr==null)
else {
gObject=new GuestFile(inputStr,";");
} catch (EOFException e) {
} catch (IOException e) {
System.out.println("Error reading from file");
} catch (NoSuchElementException e) {
System.out.println("Error reading record:"+inputStr);

//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()) {

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());


Ilja Preuss
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at
And please use code tags to preserve the formatting of your code...
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!