java前端中的icon

编程入门 行业动态 更新时间:2024-10-26 14:38:02

<a href=https://www.elefans.com/category/jswz/34/1770091.html style=java前端中的icon"/>

java前端中的icon

展开全部

java中的icon是属于62616964757a686964616fe4b893e5b19e31333337623431接口类,主要设置窗口图标,实例如下: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{//该类实现该接口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

本文发布于:2024-02-25 16:13:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1699563.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:java   icon

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!