分享

painticon java

 好汉勃士 2024-03-19 发布于广东

import java.awt.Color;

import java.awt.Component;

import java.awt.Graphics;

import java.awt.GridLayout;

import javax.swing.Icon;

import javax.swing.JFrame;

import javax.swing.JLabel;

public class Main {

public static void main(String[] args) {

JFrame frame = new JFrame();

JLabel label = new JLabel(new ElliptIcon(380, 260, Color.red));

label.setLayout(new GridLayout(2, 2));

frame.setContentPane(label);

for (int i = 0; i < 4; i++) {

label.add(new JLabel(new ElliptIcon(100, 60, Color.blue)));

}

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.pack();

frame.setVisible(true);

}

}

class ElliptIcon implements Icon {

private int w, h;

private Color color;

public ElliptIcon(int w, int h, Color color) {

this.w = w;

this.h = h;

this.color = color;

}

@Override

public void paintIcon(Component c, Graphics g, int x, int y) {

g.setColor(color);

g.fillOval(x, y, w, h);

}

@Override

public int getIconWidth() {

return w;

}

@Override

public int getIconHeight() {

return h;

}

}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多