注册 登录
编程论坛 JAVA论坛

java从入门到精通

java魔 发布于 2019-12-02 12:00, 3516 次点击
13.3 这个例题  运行不了。
5 回复
#2
林月儿2019-12-02 12:32
我没买这本书怎么看题目?
#3
java魔2019-12-02 13:33
import javax.swing.*;
import java.awt.*;
public class DrawIcon implements Icon{
    private int width;
    private int height;
    public int getIconHeight() {
        return this.height;
    }
    public int getIconWidth() {
        return this.width;
    }
   
    public DrawIcon(int width, int height) {
        this.width = width;
        this.height = height;
    }
   
    public void piantIcon(Component arg0, Fraphics arg1, int x, int y) {
        arg1.fillOval(x,y,width,height);
    }
   
    public static void main(String[] args) {
        DrawIcon icon = new DrawIcon(15,15);
        
        JLabel j = new JLabel("测试", icon,SwingConstants.CENTER);
        JFrame jf = new JFrame();
        Container c = jf.getContentPane();
        c.add(j);
        jf.setVisible(true);
        jf.setSize(500,300);
        jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }
   
   

}
#4
java魔2019-12-02 13:35
不是F 是Graphics
就是这个Graphics 这个有问题。
#5
java魔2019-12-03 16:41
怎么没有人进来解决问题啊?
#6
bianguji782019-12-15 20:51
piantIcon  应该为 paintIcon
1