• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 765
  • Last Modified:

How to set backgound color of default panel from mouse event

This is a class assignment and I'm sorta stuck:
The following is a snippet from Panel class.   The assigment is to set the background color of the default panel to one color if the mouse enters over the panel and another upon it's exit.   I've identified the events but don't know how to reference the default content panel.

I'd appreciate any thoughts.

Thank you.

//****************************
// CirclePanel.java
//****************************
 
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
 
public class CirclePanel extends JPanel {
 
    private final int WIDTH = 600,  HEIGHT = 400;
    private Circle circle;
 
    public CirclePanel() {
        // instantiate new object and add listeners
        // replaces addMouseListener(new CirclesListener());
        CirclesListener listener = new CirclesListener(); 
        addMouseListener(listener);
        addMouseMotionListener(listener);
 
        setPreferredSize(new Dimension(WIDTH, HEIGHT));
        
    }
 
...
    private class CirclesListener implements MouseListener, MouseMotionListener {
 
        public void mouseEntered(MouseEvent event) {
            // how to identify default content panel??
            // setBackground(Color.WHITE);
        }
 
        public void mouseExited(MouseEvent event) {
            // how to identify default content panel??
            // setBackground(Color.BLUE);
        }
    }
}

Open in new window

0
RichardKline
Asked:
RichardKline
  • 2
1 Solution
 
CEHJCommented:
Your commented out code will work fine as part of an inner class of the JPanel
0
 
CEHJCommented:
:-)
0
 
RichardKlineAuthor Commented:
yeah... story of my life.  Never, ever, Ever look for the easy way.   *sigh*

Thanks!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now