为了账号安全,请及时绑定邮箱和手机立即绑定

JAVA单击按钮改变图标,再次单击改变回原来的图标

JAVA单击按钮改变图标,再次单击改变回原来的图标

方块字 2019-01-15 11:39:36
如题,我还需要加上什么才可以实现?谢谢import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.Icon;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.SwingConstants;class llbb extends JFrame implements ActionListener{ JButton jb; llbb() { JPanel jp=new JPanel(); Icon icon=new ImageIcon("1.png"); jb=new JButton("kafei",icon); jp.add(jb); add(jp); jb.addActionListener(this); } @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub Icon icon=new ImageIcon("2.png"); jb.setIcon(icon); jb.setText("qq"); } }public class ex02 { public static void main(String[] args) { // TODO Auto-generated method stub llbb f=new llbb(); f.setTitle("图标"); f.setSize(200,150); f.setLocation(400,300); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }}
查看完整描述
  • 1 回答
  • 0 关注
  • 1138 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信