当前页面: 开发资料首页 → J2SE 专题 → 请帮我这一个小程序添加一下鼠标动作!
请帮我这一个小程序添加一下鼠标动作!
摘要: 请帮我这一个小程序添加一下鼠标动作!
请为下面的一个小程序加一个鼠标动作,当鼠标动作移动到那个button上时,变成手形!
第一时间结帖给分!
/*
-#60;applet code=component_t2.class width=500 height=200-#62;-#60;/applet-#62;
*/
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(-#34;横向行走-#34;);
label=new Label(-#34;我可能被碰掉-#34;,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(-#34;纵向移动-#34;);
}
}
}
button.addMouseListener(new MouseAdapter()
{
public void mouseEntered(MouseEvent event)
{
button.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
}
});