⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 colorpane.java

📁 时空图计算和编辑程序
💻 JAVA
字号:
package my_cpt;
import super_cpt.*;

import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
public class ColorPane extends SuperPane implements AdjustmentListener,ActionListener{

	/**
	 * 颜色面板
	 */
	public Scrollbar[] scroll=new Scrollbar[4];
	public Label lbl[]=new Label[4];
	public MyCanvas cvs=new MyCanvas();
	public SuperBtn okbtn=new SuperBtn("确定");
	public SuperBtn nobtn=new SuperBtn("取消");
	private Color mycolor=new Color(128,128,128,127);
	public ColorPane()
	{
		super("颜色选择面板");
		setSize(220,100);
		setLayout(null);
		add(cvs);
		
		cvs.setBounds(10,25,58,58);
		String str[]={"R","G","B","A"};
		//初始化Scroll
		int x=cvs.getX()+cvs.getWidth()+2,y=cvs.getY()+1;
		for(int i=0;i<scroll.length;i++)
		{
			//int orientation, int value, int visible, int minimum, int maximum
			scroll[i]=new Scrollbar(Scrollbar.HORIZONTAL,128,5,0,255);
			scroll[i].addAdjustmentListener(this);
			scroll[i].setBounds(x+14,y+i*15,128,12);
			add(scroll[i]);
			lbl[i]=new Label(str[i]);
			add(lbl[i]);
			lbl[i].setBounds(x,scroll[i].getY(),12,12);
			lbl[i].setForeground(Color.GRAY);
		}
		add(okbtn);
		add(nobtn);
		okbtn.setBounds(getWidth()/2-30,81,30,16);
		nobtn.setBounds(getWidth()/2,81,30,16);
		okbtn.addActionListener(this);
		nobtn.addActionListener(this);
		Direction=2;
		HidenSide=RIGHT;
	}
	public void paint(Graphics g)
	{
		if(backimage==null)initBackImage();
		g.drawImage(backimage,0,0,this);
		super.paint(g);
	}
	public Color forecolor=null;
	public boolean bool=true;
	public void actionPerformed(ActionEvent e)
	{//
		if(e.getSource()==okbtn)
		{//确认
			bool=true;
		}
		if(e.getSource()==nobtn)
		{//取消
			bool=false;
		}
		if(iexcuter!=null)
			iexcuter.Confirm(this,RIGHT,false);
	}
	public void adjustmentValueChanged(AdjustmentEvent e)
	{
		int [] para=new int[4];
		for(int i=0;i<para.length;i++)
		{
			para[i]=scroll[i].getValue();
		}
		setColor(new Color(para[0],para[1],para[2],para[3]));
	}
	public void setColor(Color color)
	{
		mycolor=color;
		scroll[0].setValue(color.getRed());
		scroll[1].setValue(color.getGreen());
		scroll[2].setValue(color.getBlue());
		scroll[3].setValue(color.getAlpha());
		cvs.repaint();
	}
	public Color getColor(){return bool?mycolor:forecolor;}
	public class MyCanvas extends Canvas{
		
		public BufferedImage myimg=null;
		public BufferedImage myimg2=null;
		public Graphics2D myg2=null;
		
		public void initImage()
		{
			int w=getWidth(),h=getHeight();
			myimg=this.getGraphicsConfiguration().createCompatibleImage(w,h);
			Graphics2D g2=myimg.createGraphics();
			g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
			g2.setColor(Color.WHITE);
			g2.fillRect(0,0,w,h);
			int mx=w/5+1,my=h/5+1;
			for(int i=0;i<mx;i++)
				for(int j=0;j<my;j++)
				{
					if((i+j)%2==0){
						g2.setColor(Color.GRAY);
						g2.fillRect(i*5,j*5,5,5);
					}
				}
			range=w/2-5;
			g2.dispose();
		}
		public int range=0;
		public void update(Graphics g)
		{//
			
			int w=getWidth(),h=getHeight();
			if(myimg2==null || myg2==null)
			{
				myimg2=this.getGraphicsConfiguration().createCompatibleImage(w,h);
				myg2=myimg2.createGraphics();
				myg2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
			}
			myg2.setColor(Color.WHITE);
			myg2.fillRect(0,0,w,h);
			if(myimg==null)
				initImage();
			myg2.drawImage(myimg,0,0,this);
			//绘制中央
			myg2.setColor(mycolor);
			myg2.fillOval(w/2-range,h/2-range,range*2,range*2);
			//
			myg2.setColor(Color.GRAY);
			myg2.drawRect(0,0,getWidth()-1,getHeight()-1);
			paint(g);			
		}
		public void paint(Graphics g)
		{
			if(myimg2==null)
			{
				repaint();
			}
			g.drawImage(myimg2,0,0,this);
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -