具有差别显示气势的Jbutton[Java编程]
本文“具有差别显示气势的Jbutton[Java编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
现象:
JButton类按钮的一种扩大,当鼠标移入、移出、被点击时有差别的外观
办理筹划:
import javax.swing.*;
import javax.swing.border.*;
import java.awt.event.*;
import java.awt.*;
/** * Title: * Description: * Copyright: * Company: * @author * @version 1.0 */
/** * JButton类按钮的一种扩大,当鼠标移入、移出、被点击时有差别的外观 */
public class ZButton extends JButton
{
private Border borderOut;
private Border borderIn;
private Border borderPressed;
public ZButton() { init(); } /**初始化*/
private void init()
{
borderOut = BorderFactory.createEmptyBorder();//(2,2,2,2);
borderIn = BorderFactory.createBevelBorder(BevelBorder.RAISED,Color.white,Color.white, new Color(148, 145, 140),new Color(103, 101, 98));
borderPressed = BorderFactory.createBevelBorder(BevelBorder.LOWERED,Color.white,Color.white, new Color(148, 145, 140),new Color(103, 101, 98));
this.setBorder( borderOut );
this.addMouseListener(new java.awt.event.MouseAdapter()
{
public void mouseEntered(MouseEvent e)
{
thisButton_mouseEntered(e);
}
public void mouseExited(MouseEvent e)
{
thisButton_mouseExited(e);
}
public void mousePressed(MouseEvent e)
{
thisButton_mousePressed(e);
}
public void mouseReleased(MouseEvent e)
{
thisButton_mouseReleased(e);
}
});
}
/**鼠标移入时的外观*/
void thisButton_mouseEntered(MouseEvent e)
{
if( this.isEnabled() ) this.setBorder( borderIn ); }
/**鼠标移出时的外观*/
void thisButton_mouseExited(MouseEvent e)
{
this.setBorder( borderOut );
}
/**鼠标被点击时的外观*/
void thisButton_mousePressed(MouseEvent e)
{
if( this.isEnabled()) this.setBorder( borderPressed );
}
/**鼠标被释放时的外观*/
void thisButton_mouseReleased(MouseEvent e)
{
if( (this.getBounds().contains(e.getX(), e.getY())) && this.isEnabled() )
this.setBorder( borderIn ); else this.setBorder( borderOut ); }
}
以上是“具有差别显示气势的Jbutton[Java编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |