《Java2图形设计卷II:Swing》配套光盘源码

源代码在线查看: coloricon.java

软件大小: 4504 K
上传用户: guigong
关键词: Java2 Swing 图形 光盘
下载地址: 免注册下载 普通下载 VIP

相关代码

				import java.awt.*;
				import javax.swing.*;
				
				public class ColorIcon implements Icon {
					private int w, h;
				
					public ColorIcon(int w, int h) {
						this.w = w;
						this.h = h;
					}
					public void paintIcon(Component c, Graphics g, int x, int y) {
						Color fillColor = Color.lightGray;
				
						g.setColor(Color.black);
						g.drawRect(x, y, w-1, h-1);
				
						if(c instanceof JComponent) {
							JComponent jc = (JComponent)c;
							fillColor = (Color)jc.getClientProperty("fill color");
						}
						g.setColor(fillColor);
						g.fillRect(x+1, y+1, w-2, h-2);
					}
					public int getIconWidth() {
						return w;
					}
					public int getIconHeight() {
						return h;
					}
				}
							

相关资源