title: Background color change Java
body: <p>I tried to program about mouselistener. I wanted to make program that if mouse cursor enter or exit frame, the frame's background color change.</p>
  
  <pre><code>import java.awt.event.MouseListener;
  import java.awt.event.MouseEvent;
  import java.awt.Color;
  import javax.swing.JFrame;
  import java.awt.event.ActionListener;
  
  public class EnterExitListener extends JFrame
  {
     public static void main(String [] args)
     {
        JFrame frame=new JFrame();
        final int FRAME_WIDTH=500;
        final int FRAME_HEIGHT=600;
        frame.setSize(FRAME_WIDTH,FRAME_HEIGHT);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);   
  
        class MouseEnterExitListener implements MouseListener
        {
           public void mouseEntered(MouseEvent event)
        {
           System.out.println("ENTER");
           frame.setBackground(Color.BLUE);
        }
        public void mouseExited(MouseEvent event)
           {
           System.out.println("EXIT");
           frame.setBackground(Color.RED);
           }  
        public void mouseReleased(MouseEvent event) {}
        public void mouseClicked(MouseEvent event) {}
        public void mousePressed(MouseEvent event) {} 
        }
  
        MouseListener listener = new MouseEnterExitListener();
        frame.addMouseListener(listener);   
     }
  }
  </code></pre>
  
  <p>compiling has no problem, and if I run the program, it shows ENTER, EXIT on I/O message. However, the problem is color is not changing. It's just white frame at all.</p>