GUI:IconDemo


import javax.swing.*;
import java.awt.*;

public class IconDemo implements Icon {
    private  int width;
    private  int height;
public IconDemo(){}
    public IconDemo(int width,int height) {
        this.width = width;
        this.height = height;
    }
    public  void init(){
        IconDemo iconDemo=new IconDemo(15,15);
        JFrame jf=new JFrame();
        JLabel label=new JLabel("icontest", iconDemo,SwingConstants.CENTER);
        Container container=jf.getContentPane();
        container.add(label);

        jf.setVisible(true);
        jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }

    public static void main(String[] args) {
        new IconDemo().init();
    }

    @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;
    }
}

 

 

你可能感兴趣的:(Gui,java,开发语言)