UI(JAVA)错误日志

	/**
	 * @ 绘制背景图片
	 * @param x :从(x, y)开始绘制图片
	 * @param y :从(x, y)开始绘制图片
	 * @param imgURL :图片链接
	 * @param simOpacity :设置图片类似透明度(0.0f --- 1.0f)
	 * @return Jpanel
	 */
	/*
	public static JPanel setImgBackground(final int x, final int y, final float simOpacity, final URL imgURL)
	{
		JPanel j = new JPanel()// 设置登陆窗体背景图片,即重写paintComponent方法(不是paint方法,避免遮挡)
		{
			private static final long	serialVersionUID	= 1L;

			@Override
			public void paintComponent(Graphics g)
			{
				// TODO Auto-generated method stub
				ImageIcon iconField = new ImageIcon(imgURL);
				Image imgField = iconField.getImage();
				
				AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, simOpacity);
				Graphics2D g2d = (Graphics2D) g;
				g2d.setComposite(ac);
				g2d.drawImage(imgField, 0, 0, imgField.getWidth(null), imgField.getHeight(null), this);

				g.drawImage(imgField, x, y, null);
			}
		};
		return j;
	}
	*/
	public static class setImgBackground extends JPanel//继承Jpanel
	{
		/**
		 * 
		 */
		private static final long	serialVersionUID	= 1L;
		private URL	imgURL;
		private float	simOpacity;
		private int	x;
		private int	y;

		public setImgBackground(int x, int y, float simOpacity, URL imgURL)//构造方法初始化变量
		{
			this.x = x;
			this.y = y;
			this.simOpacity = simOpacity;
			this.imgURL = imgURL;
		}
		
		@Override
		public void paintComponent(Graphics g)//重写父类方法
		{
			// TODO Auto-generated method stub
			ImageIcon iconField = new ImageIcon(imgURL);
			Image imgField = iconField.getImage();
			
			AlphaComposite ac = AlphaComposite.getInstance(
					AlphaComposite.SRC_OVER, simOpacity);
			Graphics2D g2d = (Graphics2D) g;
			g2d.setComposite(ac);
			g2d.drawImage(imgField, 0, 0, imgField.getWidth(null), imgField.getHeight(null), this);

			g.drawImage(imgField, x, y, null);
		}
	}
用上面的成员方法(即注释掉的部分),不能创建一个新的带背景的JPanel。需要用下面的类。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值