I want to implement a panel that draws two eyes that move to look up, in the center or down, depending on whether the mouse cursor is above, inside or under the eyes. I first used this code to make eyes:
public class EyesPanel extends JPanel implements ActionListener {
public void paintComponent(Graphics g) {
super.paintComponents(g);
g.drawOval(130, 100, 120, 120);
g.drawOval(250, 100, 120, 120);
g.fillOval(175, y, 30, 30);
g.fillOval(295, y, 30, 30);
}

And then it's time to add an event listener for this class to work, but here is the part that I'm stuck with. I know how to do graphics moving (ActionListener), and I know how to implement MouseInputListener (extends MouseInputListener). However, combining the two together, I feel upset. Can someone tell me how to do this, give me sample code can be very helpful.
Below is my code, not a valid and complete code:
public class EyesPanel extends JPanel implements ActionListener {
private JPanel panel;
private int y;
private int dy;
private Timer t;
private Mouse move;
public EyesPanel() {
dy = 5;
y = 145;
this.addMouseListener(new Mouse());
this.addMouseMotionListener(new Mouse());
t = new Timer(100, this);
}
public void paintComponent(Graphics g) {
super.paintComponents(g);
g.drawOval(130, 100, 120, 120);
g.drawOval(250, 100, 120, 120);
g.fillOval(175, y, 30, 30);
g.fillOval(295, y, 30, 30);
}
public void actionPerformed(ActionEvent event) {
moveDown();
}
private void moveUp() {
if (move.move() == 1) {
t.start();
y = y + dy;
repaint();
} else {
t.stop();
}
}
private void moveDown() {
if (move.move() == -1) {
t.start();
y = y - dy;
repaint();
} else {
t.stop();
}
}
}
My mouse event class:
public class Mouse extends MouseInputAdapter {
private int y;
public void mouseEntered(MouseEvent event) {
JPanel pane = (JPanel) event.getSource();
y = pane.getHeight();
}
}