62,614
社区成员
发帖
与我相关
我的任务
分享
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();
}
}
public MyIcon(int width, int height){
this.width = width;
this.heigth = height;
}
构造函数写错了。