【发布时间】:2011-09-28 23:33:24
【问题描述】:
谁能帮我写代码。我有两个图像1.jpg 和2.jpg,当我运行程序时,1.jpg 出现在按钮上,但是当我将鼠标悬停在按钮上时,2.jpg 不会出现。下面是代码,谢谢
import javax.swing.*;
class ButtonRollover {
public static void main(String[] args) throws Exception {
String path1 = ("C:\\1.jpg");
String path2 = ("C:\\2.jpg");
final JLabel pic1 = new JLabel(new ImageIcon(path1));
final JLabel pic2 = new JLabel(new ImageIcon(path2));
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JButton button = new JButton("Hover");
button.setRolloverIcon(new ImageIcon("C:\\2.jpg"));
button.add(pic1);
button.setRolloverEnabled(true);
JOptionPane.showMessageDialog(null, button);
}
});
}
}
【问题讨论】: