1.創建新class的名稱Gui
2.put 2圖片(40X40)在你的/ bin
import
java.awt.FlowLayout;
import
java.awt.event.ActionListener;
import
java.awt.event.ActionEvent;
import
javax.swing.JFrame;
import
javax.swing.JButton;
import
javax.swing.Icon;
import
javax.swing.ImageIcon;
import
javax.swing.JOptionPane;
public
class
Gui
extends
JFrame{
private
JButton reg;
private
JButton custom;
public
Gui(){
super("The
title");
setLayout(new
FlowLayout());
reg
= new
JButton("reg
Button");
add(reg);
Icon
b = new
ImageIcon(getClass().getResource("b.png"));
→
圖片名稱
Icon
x = new
ImageIcon(getClass().getResource("g.png"));
custom
= new
JButton("Custom",b);
custom.setRolloverSelectedIcon(x);
add(custom);
}
}
沒有留言:
張貼留言