当 继承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());
}
}
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());
}
}
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;
// }
// }
}