请问为什么我没有图标显示,是不是要调用paintIcon()的方法,如果是,怎么调用
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;public class Swing_test extends JFrame{
public Swing_test(){
this.setSize(300,150);
this.setLocation(300,200);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
class MyIcon implements Icon{
private int width;
private int heigth;
public int getIconHeight(){
return this.heigth;
}
public int getIconWidth(){
return this.width;
}
public MyIcon(int width, int height){
this.width = width;
this.heigth = heigth;
}
public void paintIcon(Component arg0, Graphics arg1, int x, int y){
arg1.fillOval(x, y, width, heigth);
}
}
MyIcon a = new MyIcon(15,15);
JLabel label = new JLabel("测试", a, JLabel.CENTER);
label.setVisible(true);
this.add(label);
this.setVisible(true);
}
public static void main(String[] ar){
new Swing_test();
}
}