import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.WindowConstants;
public class Test implements Lcon {
private int width;
private int height;
public int getLconHeight() {
return this.height;
}
public int getLconwidth() {
return this.width;
}
public Test(int width, int height) {
this.width = width;
this.height = height;
}
// 实现paintLcon()方法
public void paintLcon(Component arg0, Graphics arg1, int x, int y) {
arg1.fillOval(x, y, width, height); // 绘制一个圆形
}
public static void main(String[] args) {
Test icon = new Test(15, 15);
JLabel j = new JLabel("测试", icon, SwingConstants.CENTER);
JFrame jf = new JFrame();
Container c = jf.getContentPane();
c.setBackground(Color.black);
jf.setVisible(true);
jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
}
JLabel j = new JLabel("测试", icon, SwingConstants.CENTER);
提示 构造函数 JLabel(String, Test, int)未定义
请问原因, 以及 分开书写的方式.
第二个问题 , public class Test implements Lcon
会提示没有创建Lcon创建接口,书上没有提, 直接按照提示创建了一个Lcon的接口 是否是一样的?