/*rgbWhite1.java
 *1999/4/1
 *Suzuki,Tetsuo
 */


import java.applet.Applet;
import java.awt.*;
import java.lang.Math;

public class rgbWhite1 extends Applet{
	Scrollbar h;
    Choice ch1,ch2,ch3;
	Color c1,c2,c3,c4,c5,c6;
	int i,j,n,a,b,k,m;
	Point pt=new Point(50,50);
	Dimension d;
	public void init(){
		d=size();
		n=7;
		a=1;
		b=2;
		c1=new Color(255,255,0);
        c2=new Color(0,255,255);
		c3=new Color(255,0,255);
	
		setBackground(Color.black);
        setLayout(new BorderLayout());//ボーダーレイアウトに
        Panel p1 = new Panel();//パネル作製
		Panel p2 = new Panel();
        p1.setLayout(new FlowLayout());
        p1.add(ch1=new Choice());//部品をパネルに貼り付け
			ch1.addItem("c1:yellow");
			ch1.addItem("c1:cyan");
			ch1.addItem("c1:magenta");
        	ch1.addItem("c1:red");
			ch1.addItem("c1:green");
			ch1.addItem("c1:blue");
			
        p1.add(ch2=new Choice());
			ch2.addItem("c2:cyan");
			ch2.addItem("c2:yellow");
			ch2.addItem("c2:magenta");
        	ch2.addItem("c2:red");
			ch2.addItem("c2:green");
			ch2.addItem("c2:blue");
			
        p1.add(ch3=new Choice());
			ch3.addItem("c3:magenta");
			ch3.addItem("c3:yellow");
			ch3.addItem("c3:cyan");
        	ch3.addItem("c3:red");
			ch3.addItem("c3:green");
            ch3.addItem("c3:blue");
			ch3.addItem("c3:white");
		
        add("South", p1);//パネルを貼り付け
        p2.setLayout(new GridLayout(8,1));
				
        p2.add(new Button("1"));//部品をパネルに貼り付け
		p2.add(new Button("2"));
 		p2.add(new Button("3"));
		p2.add(new Button("4"));
		p2.add(new Button("5"));
 		p2.add(new Button("6"));
		p2.add(new Button("7"));
		p2.add(new Button("8"));
        add("East", p2);//パネルを上に貼り付け
		
	//	add("East",h=new Scrollbar(Scrollbar.VERTICAL,0,0,0,7));
	}
	public void paint (Graphics g){
		m=(int)(Math.pow(2,n));
		for(i=0;i<128/m;i++){
	      for(j=0;j<128/m;j++){
			
			
		g.setColor(c1);
		g.fillRect(pt.x+(int)((i%3)*a*m)+(int)(j*3*a*m),pt.y+(int)(i*b*m),a*m,b*m);
	    g.setColor(c2);
		g.fillRect(pt.x+(int)(((i+1)%3)*a*m)+(int)(j*3*a*m),pt.y+(int)(i*b*m),a*m,b*m);  
		
        g.setColor(c3);
		g.fillRect(pt.x+(int)(((i+2)%3)*a*m)+(int)(j*3*a*m),pt.y+(int)(i*b*m), a*m,b*m);
			}
		}
	}

    public boolean action(Event e,Object o){
		if(e.target instanceof Choice ){
			Choice ch1=(Choice)e.target;
							
		
		if("c1:red".equals (ch1.getSelectedItem()) )
			c1=new Color(250,0,0);
		if("c1:green".equals(ch1.getSelectedItem()) )
				c1=new Color(0,255,0);
		if("c1:blue".equals(ch1.getSelectedItem()) )
				c1=new Color(0,0,255);
		if("c1:yellow".equals(ch1.getSelectedItem()) )
				c1=new Color(255,255,0);
		if("c1:cyan".equals(ch1.getSelectedItem()) )
				c1=new Color(0,255,255);
		if("c1:magenta".equals(ch1.getSelectedItem()) )
				c1=new Color(255,0,255);
			Choice ch2=(Choice)e.target;
		if("c2:red".equals(ch2.getSelectedItem()) )
				c2=new Color(255,0,0);
		if("c2:green".equals(ch2.getSelectedItem()) )
				c2=new Color(0,255,0);
		if("c2:blue".equals(ch2.getSelectedItem()) )
				c2=new Color(0,0,255);
		if("c2:yellow".equals(ch2.getSelectedItem()) )
				c2=new Color(255,255,0);
		if("c2:cyan".equals(ch2.getSelectedItem()) )
				c2=new Color(0,255,255);
		if("c2:magenta".equals(ch2.getSelectedItem()) )
				c2=new Color(255,0,255);
			Choice ch3=(Choice)e.target;
		if("c3:red".equals(ch3.getSelectedItem()) )
				c3=new Color(255,0,0);
		if("c3:green".equals(ch3.getSelectedItem()) )
				c3=new Color(0,255,0);
		if("c3:blue".equals(ch3.getSelectedItem()) )
				c3=new Color(0,0,255);
		if("c3:yellow".equals(ch3.getSelectedItem()) )
				c3=new Color(255,255,0);
		if("c3:cyan".equals(ch3.getSelectedItem()) )
				c3=new Color(0,255,255);
		if("c3:magenta".equals(ch3.getSelectedItem()) )
				c3=new Color(255,0,255);
		if("c3:white".equals(ch3.getSelectedItem()) )
				c3=new Color(255,255,255);
			
		repaint();
		}
		if(e.target instanceof Button ){
			if("1".equals(o))
			n=7;
			if("2".equals(o))
			n=6;
			if("3".equals(o))
			n=5;
			if("4".equals(o))
			n=4;
			if("5".equals(o))
			n=3;
			if("6".equals(o))
			n=2;
			if("7".equals(o))
			n=1;
			if("8".equals(o))
			n=0;
			repaint();
			}
		return true;

	}
/*	public boolean handleEvent(Event e){
		if(e.target instanceof Scrollbar){
		n=(int)(Math.pow(2,h.getValue()));
		
		repaint();
		}
		return true;
		
	}*/
}