Your browser does not support the HTML canvas tag.
Color



Home

//******************************************************************************
// project6.for.java:	Applet
//
//******************************************************************************
import java.applet.*;
import java.awt.*;
public class project6 extends Applet
{
	//String     sText; 
	boolean    bRed,
		   bGreen,
		   bBlue;
	
	Button     btnRed,
		   btnGreen,
		   btnBlue;
	
	Label      lblPrompt,
		   lblSpace1,
	           lblSpace2,
	           lblSpace3,
	           lblSpace4;
	
	TextField  txtData;

public project6()
{
// TODO: Add constructor code here
}

public String getAppletInfo()
{
	return "Name: project6\r\n" +
	       "Author: \r\n" +
	       "Created with Microsoft Visual J++ Version 6.0";
}

public void init()
{
	resize( 300, 300 );
	
	//sText     = "That's All Folks";
	
	bRed      = false;
	bGreen    = false;
	bBlue     = false;
	
	btnRed    = new Button("Red");
	btnGreen  = new Button("Green");
	btnBlue   = new Button("Blue");
	
	lblPrompt = new Label("Color");
	lblSpace1 = new Label("");
	lblSpace2 = new Label("");
	lblSpace3 = new Label("");
	lblSpace4 = new Label("");
	
	txtData   = new TextField ("Default Gray");
	
	setLayout   ( new GridLayout ( 3, 3 ) );
	
	//Top 3 in grid
	add(btnRed);
	add(btnGreen);
	add(btnBlue);
	
	//Middle 3 in grid
	add(lblSpace1);
	add(lblPrompt);
	add(lblSpace2);
	
	//Bottom 2 in grid, third will be blank so bg can show
	add(lblSpace3);
	add(txtData);
	//add(lblSpace4);
	
	
		

// TODO: Place additional initialization code here
}

public void paint(Graphics g)
{
	//g.drawString (sText, 100, 75);
	
	g.setColor ( new Color (50, 50, 50) );
	g.fillRect ( 0, 0, 350, 31 );
	
	g.setColor ( new Color (100, 100, 100) );
	g.fillRect ( 0, 0, 300, 300 );
		
	if (bRed)
	{
	g.setColor ( new Color (255, 100, 100) );
	g.fillRect ( 0, 0, 300, 300 );
	}
	if (bGreen)
	{
	g.setColor ( new Color (100, 255, 100) );
	g.fillRect ( 0, 0, 300, 300 );
	}
	if (bBlue)
	{
	g.setColor ( new Color (100, 100, 255) );
	g.fillRect ( 0, 0, 300, 300 );
	}
}

public void start()
{
// TODO: Place additional applet start code here
}

public void stop()
{
}

public boolean action ( Event e, Object o )
{
	if ( e.target.equals(btnRed) )
	{ txtData.setText("Red"); 
	  bRed    = true;
	  bGreen  = false;
	  bBlue   = false;
	} 
	
	if ( e.target.equals(btnGreen) )
		{ txtData.setText("Green");
	  bRed   = false;
	  bGreen = true;
	  bBlue  = false;
	}
	
	if ( e.target.equals(btnBlue) )
		{ txtData.setText("Blue");
	  bRed   = false;
	  bGreen = false;
	  bBlue  = true;
	 }
	
	repaint();
	
	return true;
}

}