1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| class Test extends JFrame implements Icon { private int height; private int width;
public Test() {
}
public Test(int height, int width) { this.height = height; this.width = width; }
public void init() { Test iconTest = new Test(15, 15); JLabel label = new JLabel("label", iconTest, SwingConstants.CENTER); setBounds(100, 100, 200, 200); getContentPane().add(label); this.setVisible(true); }
@Override public void paintIcon(Component c, Graphics g, int x, int y) { g.fillOval(x, y, width, height); }
@Override public int getIconWidth() { return this.width; }
@Override public int getIconHeight() { return this.height; }
public static void main(String[] args) { new Test().init(); } }
|