zoukankan      html  css  js  c++  java
  • GUI 之 Icon(图标)

    编写代码 IconDemo测试类

    package com.xiang.lesson04;
    
    import javax.swing.*;
    import java.awt.*;
    
    //icon 图标是一个接口,需要实现类,Frame 继承
    public class IconDemo extends JFrame 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(12, 12);
            JLabel label = new JLabel("iconTest", iconDemo , SwingConstants.CENTER);
            Container container = getContentPane();
            container.add(label);
    
            setVisible(true);
            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            pack();
        }
    
        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;
        }
    }
    
    

    运行结果

  • 相关阅读:
    [HNOI2008] Cards
    loj #136
    a problem
    dp * 3
    STL
    套题1
    luogu 4211
    loj #2319
    loj #2316
    luogu 1144
  • 原文地址:https://www.cnblogs.com/d534/p/15111418.html
Copyright © 2011-2022 走看看