JAVA中Icon接口的应用(以JLabel为例)
2012-01-02 18:07
525 查看
This example shows the drawing of an icon using the Icon interface for the JLable component.
package com.han; import java.awt.*; import javax.swing.*; /** * This example shows the drawing of an icon using the Icon interface * for the JLable component. * @author han * */ public class DrawIcon implements Icon{ private int width; private int height; @Override public int getIconHeight(){ return this.height; } @Override public int getIconWidth(){ return this.width; } @Override public void paintIcon(Component c, Graphics g, int x, int y){ g.setColor(Color.red); g.fillOval(x, y, width, height); } /*the construct function*/ public DrawIcon(int width, int height){ this.width=width; this.height=height; } public static void main(String[] args){ DrawIcon icon=new DrawIcon(15,15); JLabel jl=new JLabel("测试",icon,SwingConstants.CENTER); JFrame jf=new JFrame(); Container c=jf.getContentPane(); c.add(jl); jf.setVisible(true); jf.setSize(300,300); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }
相关文章推荐
- JAVA中Icon接口的应用(以JLabel为例)
- JAVA中Icon接口的应用(以JLabel为例)
- java---接口实现多态性应用案例
- JAVA学习--接口的应用:代理模式
- 第一天:Java源码级实战速成(通过动手实战类、对象等,通过Spark和Hadoop案例代码和源码解析具体指知识的应用、深度详解匿名接口在Spark开发中的运用)
- Selenium Webdriver自动化测试设计(webdriver自动化架构设计、定义接口、日志处理、Java Robot类应用)
- 漫谈Java程序设计中的接口应用
- 漫谈Java程序设计中的接口应用
- JAVA内置数据结构--set接口与应用
- java接口的高级应用
- java基础--类与对象(继承与接口应用)
- java 面向对象接口的应用
- java_接口的应用
- Java:应用Observer接口实践Observer模式
- 黑马程序员————java基础--------集合之set接口的特点及应用
- JAVA笔记7__接口应用/Object类/简单工厂模式/静态代理模式/适配器模式
- Java面向对象接口的应用实例练习
- java中接口和抽象类的应用[原创]
- Java中接口的应用
- java基础知识回顾之javaIO类--File类应用:过滤器接口FilenameFilter和FileFilter