title: How to store a image and rename that image at the same time while storing?
body: <p>Want to create a <code>JFileChooser</code> and a <code>JTextField</code>Then browse an image from any folder. Path is given, so it will rename the image and the image name would be the <code>jtextfield.getText();</code> then store in my specified path. 
  I know it's hard to implement. I did some part. </p>
  
  <p><code>JFileChooser</code> and <code>jtextfield</code> is created. Image is getting stored in my specified path. But it's not renaming the image. (Rename image should be the jtextfield.jpg)</p>
  
  <pre><code>import java.awt.GridBagLayout;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.awt.image.BufferedImage;
  import java.io.IOException;
  import java.util.logging.Level;
  import java.util.logging.Logger;
  import javax.imageio.ImageIO;
  import javax.swing.*;
  import javax.swing.filechooser.FileNameExtensionFilter;
  import java.io.File;
  
  public class ImgClass {
  
      public ImgClass() {
          final JFrame frame = new JFrame("Save Image");
  
                      final JTextField username = new JTextField();
              username.setBounds(105, 102, 192, 20);
              frame.add(username);
              username.setColumns(10);
  
          JButton saveImage = new JButton("Browse");
          saveImage.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                  JFileChooser chooser = new JFileChooser();
                  FileNameExtensionFilter filter = new FileNameExtensionFilter(
                          "JPG, GIF, and PNG Images", "jpg", "gif", "png");
                  chooser.setFileFilter(filter);
                  int returnVal = chooser.showOpenDialog(frame);
                  if (returnVal == JFileChooser.APPROVE_OPTION) {
                      File file = chooser.getSelectedFile();
                      System.out.println("You choose to open this file: "
                              + file.getName());
                      BufferedImage image;
                      try {
                          image = ImageIO.read(file);
                         ImageIO.write(image, "jpg",new File("D:\\Img\\" + username.getText()+".jpg"));
                      } catch (IOException ex) {
                          Logger.getLogger(ImgClass.class.getName()).log(Level.SEVERE, null, ex);
                      }              
                  }
              }
          });
  
  
  
          frame.add(saveImage);
          frame.setLayout(new GridBagLayout());
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setSize(300, 300);
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
  
  
      }
  
      public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
              @Override
              public void run() {
                  ImgClass saveImageFile = new ImgClass();
              }
          });
      }
  }
  </code></pre>