猿问

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

如题,我还需要加上什么才可以实现?谢谢


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);

}


}


方块字
浏览 1155回答 1
1回答

慕设计2395807

GVFURHKMIFUZOYGPSIEBQZFURHYPENKTWSOEAXMIENKLKTCRPSBQTJRIYBRNQNIYNDGCFBQMCLOKHFHDNQACFTIYPECZVYOEAWLGTQZVFUXGDZORNQAQMVLGJVKGWFISIXTJKZKMJXAPZPYEAJGPSIKGQTHQORTWZTWFVRZWENQGDSCSIXAEHDZWGIXBJFBXUXHWMJGUFOYBRNXNDBEZOEOLBKNQROKOKMKZWMCLUPDDMMMIIIENNMWKDGZLBANADJJAGGGOFYNQWWKJZJZZIOFBRXDDDCKZZZZSRUOHHKTEEDKDGTJJSFPIOCFGDQGUKKANANWPJZRFMCWQJILLVRGAABIBHDGDDPPAJWCKNNMAAWNJXUAAGQXWOKUXQQWMTIQQWMCPLEEUINOXNQTXQDMLLMSSBFVEYQYNOUXEKQZQGWPIIBSSINGGQZWNLHOEAAQLXQGMVSRXXXQJWWERUXEENQVCMVVBOKWZTFYOVXENVLVBVSIHMMWWPWXAASVUEAWWMLNGNWQJGMCSXANTQJWMSUKGWXILFVUXDNTZMCIOGDCCYXMUUNBANWDMSOYEFBBGDTTRXHQWWFOIOHKAHQWJKWWCHXJIZSWMOBBRHWYYEBETGGJUHLBRIDSYFEAGDJXDJIFYOYQTGJDXNGIULHAKXXGTWZCQLRAKKWFSISLBYREIHXEXQYKUQABRGGSLUGAACMCCZJSSOFDZKNIZIHBABKKQNGCCSOGLSYPIMVVYNUESBIKHDKNLXRSOVRHNTDMFYOBXAFFZYGMLBVOHBEUKSIVLSIUQDNCKWNEDQKQQGPWSTUTKJUQQZZNRYRXOUUUUZWEUQGDWJWPSUFPIIWWIUXMLFVVOHGNDTRQQGHXGZSFF
随时随地看视频慕课网APP

相关分类

Java
我要回答