/* * 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; }
* 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;
}