用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - java代码库

表格界面

2017-12-26 作者: 柯侧耳倾听者举报

[java]代码库

import java.beans.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*;
import javax.swing.plaf.LayerUI;
import java.awt.geom.Point2D;
class FirstLayerUI extends LayerUI<JComponent>
{
	public void paint(Graphics g, JComponent c)
	{
		super.paint(g, c);
		Graphics2D g2 = (Graphics2D) g.create();
		g2.setComposite(AlphaComposite.getInstance(
			AlphaComposite.SRC_OVER, .5f));
		g2.setPaint(new GradientPaint(0 , 0 , Color.RED
			, 0 , c.getHeight() , Color.BLUE));
		g2.fillRect(0, 0, c.getWidth(), c.getHeight());    
		g2.dispose();
	}
}
class BlurLayerUI extends LayerUI<JComponent>
{
	private BufferedImage screenBlurImage;
	private BufferedImageOp operation;
	public BlurLayerUI()
	{
		float ninth = 1.0f / 9.0f;
		float[] blurKernel = {
			ninth, ninth, ninth,
			ninth, ninth, ninth,
			ninth, ninth, ninth
		};
		operation = new ConvolveOp(
			new Kernel(3, 3, blurKernel),
			ConvolveOp.EDGE_NO_OP, null);
	}
	public void paint(Graphics g, JComponent c)
	{
		int w = c.getWidth();
		int h = c.getHeight();
		if (w == 0 || h == 0)
			return;
		if (screenBlurImage == null
			|| screenBlurImage.getWidth() != w
			|| screenBlurImage.getHeight() != h)
		{
			screenBlurImage = new BufferedImage(w
				, h , BufferedImage.TYPE_INT_RGB);
		}
		Graphics2D ig2 = screenBlurImage.createGraphics();
		ig2.setClip(g.getClip());
		super.paint(ig2, c);
		ig2.dispose();
		Graphics2D g2 = (Graphics2D)g;
		g2.drawImage(screenBlurImage, operation, 0, 0);
	}
}
class SpotlightLayerUI extends LayerUI<JComponent>
{
	private boolean active;
	private int cx, cy;

	public void installUI(JComponent c)
	{
		super.installUI(c);
		JLayer layer = (JLayer)c;
		layer.setLayerEventMask(AWTEvent.MOUSE_EVENT_MASK
			| AWTEvent.MOUSE_MOTION_EVENT_MASK);
	}
	public void uninstallUI(JComponent c)
	{
		JLayer layer = (JLayer)c;
		layer.setLayerEventMask(0);
		super.uninstallUI(c);
	}
	public void paint(Graphics g, JComponent c)
	{
		Graphics2D g2 = (Graphics2D)g.create();
		super.paint (g2, c);
		if (active)
		{
			Point2D center = new Point2D.Float(cx, cy);
			float radius = 72;
			float[] dist = {0.0f, 1.0f};
			Color[] colors = {Color.YELLOW , Color.BLACK};
			RadialGradientPaint p = new RadialGradientPaint(center
				, radius , dist , colors);
			g2.setPaint(p);
			g2.setComposite(AlphaComposite.getInstance(
				AlphaComposite.SRC_OVER, .6f));
			g2.fillRect(0, 0, c.getWidth(), c.getHeight());
		}
		g2.dispose();
	}
	public void processMouseEvent(MouseEvent e, JLayer layer)
	{
		if (e.getID() == MouseEvent.MOUSE_ENTERED)
			active = true;
		if (e.getID() == MouseEvent.MOUSE_EXITED)
			active = false;
		layer.repaint();
	}
	public void processMouseMotionEvent(MouseEvent e, JLayer layer)
	{
		Point p = SwingUtilities.convertPoint(
			e.getComponent(), e.getPoint(), layer);
		cx = p.x;
		cy = p.y;
		layer.repaint();
	}
}
public class JLayerTest
{
	public void init()
	{
		JFrame f = new JFrame("JLayer测试");
		JPanel p = new JPanel();
		ButtonGroup group = new ButtonGroup();
		JRadioButton radioButton;
		p.add(radioButton = new JRadioButton("网购购买", true));
		group.add(radioButton);
		p.add(radioButton = new JRadioButton("书店购买"));
		group.add(radioButton);
		p.add(radioButton = new JRadioButton("图书馆借阅"));
		group.add(radioButton);
		p.add(new JCheckBox("疯狂Java讲义"));
		p.add(new JCheckBox("疯狂Android讲义"));
		p.add(new JCheckBox("疯狂Ajax讲义"));
		p.add(new JCheckBox("轻量级Java EE企业应用"));
		JButton orderButton = new JButton("投票");
		p.add(orderButton);
		LayerUI<JComponent> layerUI = new SpotlightLayerUI();     
		JLayer<JComponent> layer = new JLayer<JComponent>(p, layerUI);
		f.add(layer);
		f.setSize(300, 170);
		f.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
		f.setVisible (true);
	}
	public static void main(String[] args)
	{
		new JLayerTest().init();
	}
}


网友评论    (发表评论)

共1 条评论 1/1页

发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...