当鼠标放在一个按钮图片上时,就切换到另一张图片!当鼠标离开时就恢复原来的图片!很急,请各位老大帮个忙!跪谢啊!
------解决方案--------------------
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Test extends JFrame{
private JButton jButton;
public Test(){
jButton = new JButton("测试1");
jButton.addMouseListener(new MyMouseAdapter());
this.add(jButton);
setBounds(200, 200, 200, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) {
new Test();
}
private class MyMouseAdapter extends MouseAdapter{
@Override
public void mouseEntered(MouseEvent e) {
jButton.setText("测试1");
super.mouseEntered(e);
}
@Override
public void mouseExited(MouseEvent e) {
jButton.setText("测试2");
super.mouseExited(e);
}
}
}
图片同理