Win a copy of Rust Web Development this week in the Other Languages forum!

charles dexter

Greenhorn
+ Follow
since May 21, 2009
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by charles dexter

I am trying to make an exit button which prompts to save the modified file (if file is modified) before quitting. Now whatever option I select (Yes, No or Cancel), it saves the file.
Here is my code for closing.

private void btnExitActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(ExitIndex ==1)
{
JOptionPane.showConfirmDialog(this, "Save?", "Confirm", 1);
if(WIDTH == 1)
{
try
{
ObjectOutputStream outstream = new ObjectOutputStream(new FileOutputStream(path));
outstream.writeObject(myList);

//dataDisplay.append("Array written to disk file;" +path + '\n');
outstream.close();
JOptionPane.showMessageDialog(null, "Your file is saved successfully");
}
catch(IOException err1)
{
JOptionPane.showMessageDialog(null, "Sorry, " + err1.getMessage());
}

}

else
{
return;
}

}

else
{
System.exit(0);
}
}
12 years ago
what are your charges?
12 years ago
Thanks for your reply, I am new to this. Would you be able to write some code? Thanks
12 years ago
I am making a contact book (for name & phone number). I am adding all contacts (as an object) in an ArrayList. I have made Save and SaveAs. I want to make "Exit" option in JMenu (in Swing menu) which when user clicks should exit the program but before exiting it should check whether file is modified, if modified it should prompt to save or discard. here is my code, but I dont think this is the right way
private void mnuExitActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
/*if(file is modifled)
{
JOptionPane.showConfirmDialog();
}
else
{
System.exit(0);
}*/
}
12 years ago
I am able to save file onto disc. How do I make Save menu, so that it does not open JFileChooser, if I want to save something already loaded file. I am using netbeans. Here is my code to save a file:

private void mnuSaveAsActionPerformed(java.awt.event.ActionEvent evt) {
// Save the ArrayList and its object with their data as binary file
myChoice = new JFileChooser();
myChoice.showSaveDialog(this);
path = myChoice.getSelectedFile().getPath();
try
{
ObjectOutputStream outstream = new ObjectOutputStream(
new FileOutputStream(path));
outstream.writeObject(myList);

//dataDisplay.append("Array written to disk file;" +path + '\n');
outstream.close();
JOptionPane.showMessageDialog(null,"Your file is saved successfully" );
}
catch(IOException err1)
{
JOptionPane.showMessageDialog(null,"Sorry, " + err1.getMessage());
}
}
12 years ago