import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;

public class frame extends Frame
{
 Label l1,l2,l3;
 MyMouseListener adapter;

 public frame()
 {
  super("frame change color");
 }
 public void init()
 {
  setLayout(new FlowLayout());

  adapter = new MyMouseListener(this);
  //addMouseListener(adapter);
  setSize(300,300);

  l1 = new Label("빨강");
  l1.addMouseListener(adapter);
  add(l1);
  l2 = new Label("녹색");
  l2.addMouseListener(adapter);
  add(l2);
  l3 = new Label("파랑");
  l3.addMouseListener(adapter);
  add(l3);

  show();


 }

 public static void main(String args[])
 {
  frame f = new frame();

  f.init();
 }
}

 

class MyMouseListener extends MouseAdapter
{
 frame source;
 frame l1, l2, l3, f;

 public MyMouseListener(frame m)
 {
  source = m;
 }
 public void mouseEntered(MouseEvent e)
 {
  if(e.getText().equals("빨강"))
  {
   source.setBackground(new Color(255,0,0));
  }
  if(e.getSource() == "녹색")
  {
   source.setBackground(new Color(0,255,0));
  }
  if(e.getSource() == "파랑")
  {
   source.setBackground(new Color(0,0,255));
  }
 }
 public void mouseExited(MouseEvent e)
 {
  source.setBackground(new Color(255,0,0));
 }
 
}