//Abby Walker //homework5 //March 14, 2000 //a java applet that allows the user to type in a text field that changes color import java.applet.*; import java.awt.*; import java.awt.event.*; public class LetterBox extends Applet { //this class handles all of the button and there placements Panel center, ButtonPanel; LetterField myLetterField; public void init() { BorderLayout bl = new BorderLayout(); ButtonPanel = new Panel(); ButtonPanel.setLayout(bl); myLetterField = new LetterField(); this.setLayout(new BorderLayout()); this.add("North", myLetterField); //adds the letterField to north this.add("Center", ButtonPanel); //center contains all letter buttons //and boarder buttons // add to north BorderButton northButton = new BorderButton("red", Color.red, this); ButtonPanel.add("North", northButton); // add to east BorderButton eastButton = new BorderButton("green", Color.green, this); ButtonPanel.add("East", eastButton); // add to south BorderButton southButton = new BorderButton("blue", Color.blue, this); ButtonPanel.add("South", southButton); // add to west BorderButton westButton = new BorderButton("yellow", Color.yellow, this); ButtonPanel.add("West", westButton); // add a panel in the middle and use a different layout center = new Panel(); ButtonPanel.add("Center", center); GridLayout gr = new GridLayout(6,5); center.setLayout(gr); // creating 26 center buttons for (char c = 'A'; c <= 'Z'; c++) { center.add(new CenterButton(String.valueOf(c),this)); } // for center.add(new ClearButton(this)); //creates a button that clears the //letter field } // init() Component [] GetPanelContents() { //this function gets all the components in the panel return center.getComponents(); }//GetPanelConents int NumComponents() { //holds the total number of components in the panel return center.getComponentCount(); }//NumComponents } // class LetterBox class BorderButton extends Button implements ActionListener { //BorderButton handles the outside buttons and changes //the colors of the center buttons LetterBox theBox; Color buttonColor; BorderButton(String s, Color newColor, LetterBox newBox) { super(s); buttonColor=newColor; theBox=newBox; this.setBackground(newColor); Font f = new Font("TimesRoman", Font.BOLD, 14); this.addActionListener(this); }//BorderButton public void actionPerformed(ActionEvent event) { //required by actionListener Component centerButtonArray[]; centerButtonArray=theBox.GetPanelContents(); //changes button and text field colors for(int i=0; i