private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
    int res=JOptionPane.showConfirmDialog(this,"Do you want to save this before quiting ?","New",JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE);      

if(res==JOptionPane.NO_OPTION){
JFileChooser fc=new JFileChooser();
fc.showOpenDialog(null);
 File f = fc.getSelectedFile();
    String fname=f.getAbsolutePath();
            BufferedWriter writer = null;
	try
	{
		//writer = new BufferedWriter( new FileWriter( fname));
                BufferedReader in = new BufferedReader(new FileReader(fname));
                String str;
                while ((str = in.readLine()) != null)
                    jTextArea1.append(str);
                      in.close();
	}
	catch ( IOException e)
	{
	}
	finally
	{
		try
		{
			if ( writer != null)
				writer.close( );
		}
		catch ( IOException e)
		{
		}
        }
}
else{
    JFileChooser fc=new JFileChooser();
    fc.showSaveDialog(null);
    File f = fc.getSelectedFile();
    String fname=f.getAbsolutePath()+".txt";
            BufferedWriter writer = null;
	try
	{
		writer = new BufferedWriter( new FileWriter( fname));
		writer.append(jTextArea1.getText());
                jTextArea1.setText(null);
                JOptionPane.showMessageDialog(this,"Saved","File Saved",JOptionPane.OK_OPTION);
                fc.showOpenDialog(null);
                File file=fc.getSelectedFile();
                String open=f.getAbsolutePath();
               BufferedReader in = new BufferedReader(new FileReader(open));
               jTextArea1.setText(null);
               String str;
    while ((str = in.readLine()) != null) {
                jTextArea1.append(str);
            }
	}
	catch ( IOException e)
	{
	}
	finally
	{
		try
		{
			if ( writer != null)
				writer.close( );
		}
		catch ( IOException e)
		{
		}
     }
   }

    }//GEN-LAST:event_jMenuItem1ActionPerformed