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

📄 coloreditor.java

📁 j2ee关于BEANS的多个例子
💻 JAVA
字号:
import java.beans.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class ColorEditor extends JPanel implements AdjustmentListener,PropertyEditor //extends PropertyEditorSupport 
{
//	JPanel pan;
	JLabel red,green,blue;
	JScrollBar rsb,gsb,bsb;
	Color col;
	
	public ColorEditor()
	{
		red=new JLabel("红:");
		green=new JLabel("绿:");
		blue=new JLabel("蓝:");
		rsb=new JScrollBar(rsb.HORIZONTAL,0,100,0,255);
		gsb=new JScrollBar(rsb.HORIZONTAL,0,100,0,255);
		bsb=new JScrollBar(rsb.HORIZONTAL,0,100,0,255);
//		pan=new JPanel();
		add(red);
		add(rsb);
		add(green);
		add(gsb);
		add(blue);
		add(bsb);
		rsb.addAdjustmentListener(this);
		gsb.addAdjustmentListener(this);
		bsb.addAdjustmentListener(this);
	}
	public void adjustmentValueChanged(AdjustmentEvent e) 
	{
//		System.out.println("Before Adjusted :"+col);
//		System.out.println("R:"+rsb.getValue()+ "    G:" + gsb.getValue() + "     B:" + bsb.getValue());
		this.col=new Color(rsb.getValue(),gsb.getValue(),bsb.getValue());
//		System.out.println("Adjusted :"+col);
		//col=Color.red;
	}
	
 	public boolean isPaintable()
 	{
 		return true;
 	}
 	public boolean supportsCustomEditor()
 	{
 		return true;
 	}
 	public Object getValue()
 	{
 		System.out.println("Get Value: " + col);
 		return this.col;
 	}
 	public void setValue(Object value)
 	{
 		System.out.println("Set Value:" + value);
 		this.col=(Color)value;
 		rsb.setValue(this.col.getRed());
 		gsb.setValue(this.col.getGreen());
 		bsb.setValue(this.col.getBlue());
 	}
 	public Component getCustomEditor()
 	{
 		return this;
 	}
//	public void addPropertyChangeListener(PropertyChangeListener listener)
//	{}
	public String getAsText()  
	{return null;}
	public String getJavaInitializationString()  
	{return null;}
	public String[] getTags() 
	{
		return null;
	}
	public void paintValue(Graphics gfx, Rectangle box) 
	{}
//	public void removePropertyChangeListener(PropertyChangeListener listener)  
//	{}
	public void setAsText(String text) throws IllegalArgumentException
	{}
}

⌨️ 快捷键说明

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