首页>代码>java swing高仿酷我音乐界面代码例子下载>/ikuwo/src/ikuwo/comm/ui/CustSkinPanel.java
/**
 * 
 */
package ikuwo.comm.ui;

import ikuwo.comm.values.ValuesMgr;

import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Paint;
import java.awt.Shape;
import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JPanel;

/**
 * 皮肤面板
 */
public class CustSkinPanel extends JPanel {

	private static final long serialVersionUID = -1142694233560441425L;

	private Image skinImg;

	private int width, height;

	private boolean isDialog;

	/**
	 * 默认构造器
	 */
	public CustSkinPanel() {
	}

	/**
	 * 构造对话框面板
	 */
	public CustSkinPanel(boolean isDialog) {
		this.isDialog = isDialog;
	}

	/**
	 * 构造贴图或绘制面板
	 */
	public CustSkinPanel(String resName, int width, int height) {
		this.width = width;
		this.height = height;
		try {
			if (null != resName && !"".equals(resName)) {
				skinImg = ImageIO.read(this.getClass().getResource(ValuesMgr.SYS_VALUES.RESOURCES_PATH + resName));
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 创建图片面板
	 */
	public void createImagePanel(Graphics g) {
		Graphics2D g2d = (Graphics2D) g;

		if (0 != width) {
			g2d.drawImage(skinImg, 0, 0, width, height, null);
		} else {
			g2d.drawImage(skinImg, 0, 0, null);
		}
	}

	/**
	 * 创建色彩面板
	 */
	public void createColorPanel(Graphics g) {
		Graphics2D g2d = (Graphics2D) g;
		// Paint p = new GradientPaint(0.0f, 0.0f, new Color(255, 0, 51, 80),
		// 500,
		// 600, new Color(255, 204, 253, 255), true);
		Paint p = new GradientPaint(0.0f, 0.0f, new Color(0xF0FAFB), getWidth(), 0, new Color(0xAFDBF6), true);
		g2d.setPaint(p);

		g2d.fillRect(0, 0, getWidth(), getHeight());

		g2d.setColor(new Color(0x9FCFEB));

		Shape shape = null;

		width = 0 == width ? super.getWidth() : width;
		height = 0 == height ? super.getWidth() : height;
		// shape = new RoundRectangle2D.Double(0, 0, width - 1, height - 1,
		// 5.0D, 5.0D);// 绘制窗体边框
		shape = new Rectangle2D.Double(0, 0, width - 1, height - 2);// 绘制窗体边框
		g2d.draw(shape);
	}

	/**
	 * 绘制白面板
	 */
	public void createDialogPanel(Graphics g) {
		Graphics2D g2d = (Graphics2D) g;
		// Paint p = new GradientPaint(0.0f, 0.0f, new Color(255, 0, 51, 80),
		// 500,
		// 600, new Color(255, 204, 253, 255), true);
		Paint p = new GradientPaint(0.0f, 0.0f, new Color(0xF0FAFB), 0, getHeight(), new Color(0xF0FAFB), true);
		g2d.setPaint(p);

		g2d.fillRect(0, 0, getWidth(), getHeight());

		g2d.setColor(new Color(0x9FCFEB));

		Shape shape = null;

		width = 0 == width ? super.getWidth() : width;
		height = 0 == height ? super.getWidth() : height;
		// shape = new RoundRectangle2D.Double(0, 0, width - 1, height - 2,
		// 5.0D, 5.0D);// 绘制窗体边框
		shape = new Rectangle2D.Double(0, 0, width - 1, height - 2);// 绘制窗体边框
		g2d.draw(shape);
	}

	/**
	 * 复写渲染方法
	 */
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		if (isDialog) {
			createDialogPanel(g);
		} else {
			if (null != skinImg) {
				createImagePanel(g);
			} else {
				createColorPanel(g);
			}
		}
	}
}
最近下载更多
cxz2132132  LV11 2023年12月9日
xinxin23383  LV4 2023年11月28日
香菇肉饼汤  LV8 2023年11月28日
xp95323  LV14 2023年11月27日
初心不负丶方得始终  LV10 2023年11月27日
wyx065747  LV67 2022年5月7日
liys1234  LV9 2022年4月27日
微信网友_5852742079762432  LV6 2022年4月11日
一个好人520  LV10 2021年9月30日
Mayoubin2001  LV21 2021年6月10日
最近浏览更多
woldxy  LV12 4月1日
cxz2132132  LV11 2023年12月9日
xinxin23383  LV4 2023年11月28日
香菇肉饼汤  LV8 2023年11月28日
15817213218  LV12 2023年11月28日
fesfefe  LV13 2023年11月27日
初心不负丶方得始终  LV10 2023年11月27日
Eayon  LV19 2023年11月27日
Ji123455  LV8 2023年9月21日
zhaozhiwen123 2023年9月18日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友