title: Jbutton acction listener
body: <p>I am trying to create a form. there is a button that when clicking the button, a photo which is specified would appear. my problem is, when I click the button, the picture pops up and if the cursor passes the form boundary, the image disappears. here is my code:</p>
  
  <pre><code>import java.awt.Frame;
  import java.awt.Graphics;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.awt.image.BufferedImage;
  import java.io.File;
  import java.io.IOException;
  import static java.lang.Math.abs;
  import static java.lang.Math.min;
  import javax.imageio.ImageIO;
  import javax.swing.JButton;
  import javax.swing.JFrame;
  
  public class SeamCarving extends JFrame
  {     
  public static void main(String[] args) throws IOException {
      final BufferedImage input = ImageIO.read(new File("path"));
  
      final BufferedImage[] toPaint = new BufferedImage[]{input};
      final Frame frame = new Frame("Seams") {
  
          @Override
          public void update(Graphics g) {
              final BufferedImage im = toPaint[0];
              if (im != null) {
                  g.clearRect(0, 0, getWidth(), getHeight());
                  g.drawImage(im, 0, 0, this);
              }
          }
      };
      frame.setSize(input.getWidth(), input.getHeight());
      frame.setVisible(true);
      frame.add(startButton);
  
      startButton.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
              BufferedImage out = input;
              out = deleteVerticalSeam(out);
              toPaint[0] = out;
              frame.repaint();
              System.out.println("Do Something Clicked");
          }
      });
   }
  }
  </code></pre>