lb.setOpaque(true);加上就好用了!!

解决方案 »

  1.   

    /*
     * Created on 2004-12-14
     *
     * To change the template for this generated file go to
     * Window>Preferences>Java>Code Generation>Code and Comments
     */
    package test;/**
     * @author Administrator
     *
     * To change the template for this generated type comment go to
     * Window>Preferences>Java>Code Generation>Code and Comments
     */
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;public class Area extends JApplet
    {
    public void init()
    {
    lb = new JLabel(cl, JLabel.CENTER);
    getContentPane().add(lb, BorderLayout.CENTER);
    lb.setOpaque(true);
    lb.addMouseListener(new AreaHandler(this));
    } public void changeColor()
    {
    lb.setBackground(Color.blue);
    lb.setForeground(Color.BLUE);
    lb.setText("我变");
    } public void resumeColor()
    {
    lb.setBackground(Color.white);
    lb.setForeground(Color.BLACK);
    lb.setText("恢复");
    } private String cl = "变色框";
    private JLabel lb;
    }class AreaHandler extends MouseAdapter
    {
    AreaHandler(Area ap)
    {
    app = ap;
    } public void mouseEntered(MouseEvent e)
    {
    app.changeColor();
    } public void mouseExited(MouseEvent e)
    {
    app.resumeColor();
    } private Area app;
    }
      

  2.   

    我是用appletviewer来运行的,文字会变,可就是看不到颜色变
      

  3.   

    真是高手,谢谢cuizm(射天狼)了