设置JButton在不同状态的图片

 
 
设置JButton在不同状态的图片

1.源代码:

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

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

2.相关代码:

class LandButtonActionListener implements ActionListener {

      public void actionPerformed(ActionEvent e){

}

}

3.又一个例子

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值