import java.awt.*;

public class AwtComponentDemo {
    public static void main(String[] args) {
	// Create the main window with a title.
	Frame myFrame = new Frame("Awt Component Demo");

	// Setup the layout to hold up to 8 components each displayed on a row
	myFrame.setLayout(new GridLayout(8,1));

	// Button
	Button button = new Button("Test");

	// Canvas
	MyCanvas canvas = new MyCanvas();
	canvas.setSize(300,40);

	// Checkbox and CheckboxGroup
	Panel checkPanel = new Panel();
	CheckboxGroup pizzaGroup = new CheckboxGroup();
	Checkbox cbLarge = new Checkbox("Large Pan Pizza", pizzaGroup, false); 
	Checkbox cbMedium = new Checkbox("Medium Pan Pizza", pizzaGroup, true); 
	Checkbox cbSmall = new Checkbox("Small Pan Pizza", false);
	checkPanel.add(cbLarge); 
	checkPanel.add(cbMedium); 
	checkPanel.add(cbSmall);
	
	// Choice
	Choice pizzaChoice = new Choice(); 
	pizzaChoice.add("-- Select Size --"); 
	pizzaChoice.add("Large Pan Pizza"); 
	pizzaChoice.add("Medium Pan Pizza"); 
	pizzaChoice.add("Small Pan Pizza"); 
	pizzaChoice.select("-- Select Size --"); 

	// Label
	Label label = new Label("TEST LABEL!", Label.CENTER); 

	// List
	String[] toppings = {"Pineapple", "Pepperoni", "Black Olives", "Mushroom"};
	List toppingList = new List(toppings.length-1, false);
	for ( int i=0; i<toppings.length; i++ )
	    toppingList.add(toppings[i]);

	// TextField
	TextField textField = new TextField(18);
	textField.setFont(new Font("Serif", Font.PLAIN, 12)); 
	textField.setText("Go ahead and type!");

	// TextArea
	TextArea textArea = new TextArea(2,10);
	textArea.setFont(new Font("Monospaced", Font.PLAIN, 18)); 
	textArea.setText("Mono\n12345678");
	//textArea.setEditable(false); 


	// create a DemoItem object for each component and add it to this frame
	DemoItem buttonDemo = new DemoItem("Button:", button); 
	myFrame.add(buttonDemo);
	DemoItem canvasDemo = new DemoItem("Canvas:", canvas);
	myFrame.add(canvasDemo);
	DemoItem checkDemo = new DemoItem("Checkbox:", checkPanel);
	myFrame.add(checkDemo);
	DemoItem choiceDemo = new DemoItem("Choice:", pizzaChoice);
	myFrame.add(choiceDemo); 
	DemoItem labelDemo = new DemoItem("Label:", label);
	myFrame.add(labelDemo);
	DemoItem listDemo = new DemoItem("List:", toppingList);
	myFrame.add(listDemo);
	DemoItem TextFieldDemo = new DemoItem("TextField:", textField);
	myFrame.add(TextFieldDemo);
	DemoItem TextAreaDemo = new DemoItem("TextArea", textArea);
	myFrame.add(TextAreaDemo);

	myFrame.pack();
	myFrame.setVisible(true);
    }
}


/** DemoItem class is a Panel that contains a Label and a Component pair,
    to be displayed side-by-side. 
 */
class DemoItem extends Panel {
    Component comp; 
    Label label; 
    
    public DemoItem(String label, Component c) {
	comp = c;
	this.label = new Label(label);
	
	setLayout(new FlowLayout(FlowLayout.LEFT));
	add(label);
	add(comp);
    }
}

class MyCanvas extends Canvas {
    @Override
    public void paint(Graphics g) {
	setBackground(Color.green);

	int x = 100, y = 15;
	for(int i = 0; i < 4; i++)
	    for(int j = 0; j < 4; j++)
		g.drawString("Canvas forever!", (i * x + (j * y)), j * y);
    }
}
