请为下面的一个小程序加一个鼠标动作,当鼠标动作移动到那个button上时,变成手形!
第一时间结帖给分!
/*
<applet code=component_t2.class width=500 height=200></applet>
*/
import java.awt.*;
import java.applet.*;import java.awt.event.*;
public class component_t2 extends Applet implements ActionListener
{
  Button button;
  Label label;
  public void init()
  {
    button=new Button("横向行走");
    label=new Label("我可能被碰掉",Label.CENTER);
    label.setBackground(Color.yellow);
    button.addActionListener(this);
    add(button);add(label);
  }
  public void actionPerformed(ActionEvent e)
  {
    Rectangle rect=button.getBounds();
    if(rect.intersects(label.getBounds()))
    {
      label.setVisible(false);
    }
    if (label.isVisible())
    {
      button.setLocation(rect.x+3,rect.y);
    }
    else
    {
      button.setLocation(rect.x,rect.y+3);
      button.setLabel("纵向移动");
    }
  }
  
}

解决方案 »

  1.   

    button.addMouseListener(new MouseAdapter()
                            { 
                                public void mouseEntered(MouseEvent event)
                                {
                                     button.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
                                }
                            });