奇幻图像总结--Slider控制颜色,三基色_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > 奇幻图像总结--Slider控制颜色,三基色

奇幻图像总结--Slider控制颜色,三基色

 2013/7/10 3:35:42  feng1990liu  程序员俱乐部  我要评论(0)
  • 摘要:核心,传递参数---构造方法不同的监听器相互间传递参数用到的方法,SLider中的setValue,设置初始值,getValue得到Slider当前数值显现SLider用法与加监听器packagenetjava;importjava.awt.FlowLayout;importjava.awt.Graphics;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JSlider
  • 标签:总结 ide

核心,传递参数---构造方法

? ? ? ? 不同的监听器相互间传递参数

? ? ? ? 用到的方法,SLider中的setValue,设置初始值,getValue得到Slider当前数值

? ? ? ?显现SLider用法与加监听器

class="java" name="code">package netjava;

import java.awt.FlowLayout;
import java.awt.Graphics;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JSlider;

public class Draw02 extends JFrame {
//	private JSlider sl;
	public static	void main(String[] args){
		Draw02 dr=new Draw02();
		dr.initUI();
	}
	//定义初始界面方法
	public void initUI(){
		JFrame jf=new JFrame();
		jf.setTitle("王板");
		JSlider sl01=new JSlider();
		sl01.setMaximum(255);
		sl01.setValue(0);
		JSlider sl02=new JSlider();
		sl02.setMaximum(255);
		sl02.setValue(0);
		JSlider sl03=new JSlider();
		sl03.setMaximum(255);
		sl03.setValue(100);
		jf.add(sl01);
		jf.add(sl02);
		jf.add(sl03);
		jf.setDefaultCloseOperation(3);
		jf.setLocation(100,100);
		jf.setSize(600,600);
		jf.setLayout(new FlowLayout());
		JButton bu=new JButton("技术");
		jf.add(bu);
		jf.setVisible(true);
		//在画板显示之后取得窗体的画布对象
		Graphics g=jf.getGraphics();
		//实例化处理累对象
		ButtonListener dl=new ButtonListener(sl01,sl02,sl03,g);
//		DrawListener dl=new DrawListener(g);
		//加监听器
	//	bu.addActionListener(dl);
//		Recur dl=new Recur(g);
		SliderListener sListener = new SliderListener(sl01,sl02,sl03,dl);
		sl01.addChangeListener(sListener);
		sl02.addChangeListener(sListener);
		sl03.addChangeListener(sListener);
		
		
		jf.addMouseListener(dl);
		
		
	}

}

package netjava;

import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class SliderListener implements ChangeListener {
	private JSlider sl01;
	private JSlider sl02;
	private JSlider sl03;
	private ButtonListener dl;
	private int value01;
	private int value02;
	private int value03;
	
	public SliderListener(JSlider sl01, JSlider sl02, JSlider sl03,ButtonListener dl) {
		this.sl01= sl01;
		this.sl02= sl02;
		this.sl03= sl03;
		this.dl = dl;
	}

	public void stateChanged(ChangeEvent e){
//		Draw02 draw=new Draw02(sl01);
//		int a=sl01.getValue();
//		int b=
		if(e.getSource()==this.sl01){
			
			 value01 =this.sl01.getValue(); 
			
			System.out.println("hahaa");
		}
		if(e.getSource()==this.sl02){
			 value02=this.sl02.getValue(); 
		}
		if(e.getSource()==this.sl03){
			 value03=this.sl03.getValue(); 
			 
		}
		dl.compute(value01, value02, value03);
		
	}

}
package netjava;

import java.awt.Color;
import java.awt.Graphics;
//import java.awt.event.ActionEvent;
//import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JSlider;

public class ButtonListener extends MouseAdapter /*implements ActionListener */{

	private Graphics g;
	double a=1,b=4,c=60;
	private JSlider sl01;
	private JSlider sl02;
	private JSlider sl03;
	 public void mouseClicked(MouseEvent e) {
		
		 compute(this.sl01.getValue(),this.sl02.getValue(),this.sl03.getValue());
		}
//	}
//	}
	 
	public ButtonListener(JSlider sl01, JSlider sl02, JSlider sl03,Graphics g){
		this.g=g;
		this.sl01= sl01;
		this.sl02= sl02;
		this.sl03= sl03;
		
	}
	public void compute(int value01,int value02,int value03){
		 double x=0.0;
		 double y = 0.0;
		for(int i=0;i<50000;i++){
//			int j=255;
//			while(j>0){
//			Color co=new Color(j,j,j);
//			g.setColor(co);
		
//			double x2=d*Math.sin(a*x)-Math.sin(b*y);
//			double y2=c*Math.cos(a*x)+Math.cos(b*y);
	
			double x2=y-Math.signum(x)*Math.sqrt(Math.abs(b*x-c));
			double y2=a-x;
			int x3=(int)(1*x2);
			int y3=(int)(1*y2);
			g.setColor(new Color(value01,value02,value03));
			g.drawLine(x3+600, y3+400, x3+600, y3+400);
			x=x2;
			y=y2;
	}
	
	}
}
	



?

上一篇: 总结构造器 下一篇: 类与对象
发表评论
用户名: 匿名