设置JButton在不同状态的图片

 
设置JButton在不同状态的图片

1.源代码:

//<wbr><wbr> 创建并设置一个登录按钮,并将其添加到用来添加按钮的面板中 <wbr><wbr>final JButton landButton = new JButton();// 创建登录按钮组件对象 <wbr><wbr>landButton.setMargin(new Insets(0, 0, 0, 0));// 设置按钮边框和标签之间的间隔 <wbr><wbr>landButton.setContentAreaFilled(false);// 设置不绘制按钮的内容区域 <wbr><wbr>landButton.setBorderPainted(false);// 设置不绘制按钮的边框 <wbr><wbr>URL landUrl = this.getClass().getResource("/land_submit.png");// 获得默认情况下登录按钮显示图片的URL <wbr><wbr>landButton.setIcon(new ImageIcon(landUrl));// 设置默认情况下登录按钮显示的图片 <wbr><wbr>URL landOverUrl = this.getClass().getResource( <wbr><wbr><wbr><wbr>"/land_submit_over.png");// 获得当鼠标经过登录按钮时显示图片的URL <wbr><wbr>landButton.setRolloverIcon(new ImageIcon(landOverUrl));// 设置当鼠标经过登录按钮时显示的图片 <wbr><wbr>URL landPressedUrl = this.getClass().getResource( <wbr><wbr><wbr><wbr>"/land_submit_pressed.png");// 获得当登录按钮被按下时显示图片的URL <wbr><wbr>landButton.setPressedIcon(new ImageIcon(landPressedUrl));// 设置当登录按钮被按下时显示的图片 </wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

<wbr><wbr>landButton.addActionListener(new LandButtonActionListener<wbr>());// 为登录按钮添加事件监听器 <wbr><wbr>buttonPanel.add(landButton);// 将登录按钮添加到用来添加按钮的面板中</wbr></wbr></wbr></wbr></wbr>

2.相关代码:

class LandButtonActionListener<wbr> implements ActionListener {</wbr>

<wbr><wbr><wbr><wbr><wbr> public void actionPerformed(ActionEvent e){</wbr></wbr></wbr></wbr></wbr>

}

}

3.又一个例子

<wbr>final MButton passwordButton = new MButton(); <wbr><wbr>URL passwordUrl = this.getClass().getResource("/img/password.png"); <wbr><wbr>passwordButton.setIcon(new ImageIcon(passwordUrl)); <wbr><wbr>URL passwordOverUrl = this.getClass().getResource( <wbr><wbr><wbr><wbr>"/img/password_over.png"); <wbr><wbr>passwordButton.setRolloverIcon(new ImageIcon(passwordOverUrl)); <wbr><wbr>toolBar.add(passwordButton);</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值