当 继承JLabel怎么把ImageIcon设置进JLabel里面public class Aa extends JFrame{
Container con;
public Aa(){
con=this.getContentPane();
this.setSize(650,550);
this.setVisible(true);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(3);
this.setResizable(false);
}
public static void main(String[] args) {
new Aa();
}
}
class Bb extends JLabel{
public Bb(String x,String y,String mapX,String mapY,String path,Container con){

ImageIcon img = new ImageIcon(path);

this.setBounds(x,y, img.getIconWidth(), img.getIconHeight());
}

}

解决方案 »

  1.   

    继不继承没什么影响,多看看JLabel的api就能解决。我原来做过的,能实现。
      

  2.   

    你的本意不是想在JLabel上用ImageIcon,而是想把ImageIcon作为JLabel的背景?
    protected void paintComponent(Graphics g)
    {
    int cw = getWidth();
    int ch = getHeight(); ImageIcon scaledSymbol = new ImageIcon(img .getImage()
    .getScaledInstance(cw, ch, Image.SCALE_SMOOTH));
    g.drawImage(scaledSymbol.getImage(), 0, 0, this); // int iw = img.getWidth(this);
    // int ih = img.getHeight(this);
    // int x = 0;
    // int y = 0;
    // while (y <= ch)
    // {
    // g.drawImage(img, x, y, this);
    // x += iw;
    // if (x >= cw)
    // {
    // x = 0;
    // y += ih;
    // }
    // }
    }
      

  3.   

    好像是直接就能加上,看api吧JLabel.add();