import javax
.swing
.*
;
import java
.awt
.*
;
public class IncoDemo extends JFrame implements Icon{
private int width
;
private int length
;
public IncoDemo(){
}
public IncoDemo(int width
,int length
){
this.width
=width
;
this.length
=length
;
}
public void init(){
IncoDemo incoDemo
= new IncoDemo(30, 30);
JLabel label
=new JLabel("icon",incoDemo
,SwingConstants
.CENTER
);
Container contentPane
= getContentPane();
contentPane
.add(label
);
setVisible(true);
setDefaultCloseOperation(WindowConstants
.EXIT_ON_CLOSE
);
}
@Override
public void paintIcon(Component c
, Graphics g
, int x
, int y
) {
g
.fillOval(x
,y
,width
,length
);
}
@Override
public int getIconWidth() {
return this.width
;
}
@Override
public int getIconHeight() {
return this.length
;
}
public static void main(String
[] args
) {
new IncoDemo().init();
}
}
转载请注明原文地址:https://tech.qufami.com/read-17004.html