//***************************************************************************** // ColorTextFieldHandler.java // // Summer 2000 // // Geetika Tewari, Christie Rice & Victoria Manfredi // // // Used to listen to one of the textboxs. // //***************************************************************************** import java.awt.*; import java.awt.event.*; import java.lang.*; import java.io.*; import java.util.*; class ColorTextFieldHandler implements TextListener { ColorFrame cf; int number, numberPrev; String NumStr, prevNumStr;; String MinStr, MaxStr; // Strings for the upper and lower RGB bounds int index; // Index of the ScrollTextPanel //************************* // // constructor // //************************* public ColorTextFieldHandler (ColorFrame cff, int i) { cf = cff; index = i; number = 0; numberPrev =0; NumStr = new String ("100"); prevNumStr = new String ("100"); MinStr = new String ("0"); // Strings for the upper and lower MaxStr = new String ("255"); // RGB bounds }// end constructor //************************* // // textValueChanged // //************************* public void textValueChanged(TextEvent e) { NumStr = cf.cp.rgbp.STPanel[index].rgbTextField.getText(); // see whether the user only entered numbers try { number = Integer.parseInt(cf.cp.rgbp.STPanel[index].rgbTextField.getText()); }// end try catch (NumberFormatException numex) { // Use the old, valid numbers if an exception is encountered number = numberPrev; cf.cp.rgbp.STPanel[index].rgbTextField.setText(prevNumStr); } // end catch // make sure the number is an appropriate number if (number < 0) { number = 0; NumStr = MinStr; cf.cp.rgbp.STPanel[index].rgbTextField.setText(NumStr); } if (number > 255) { number = 255; NumStr = MaxStr; cf.cp.rgbp.STPanel[index].rgbTextField.setText(NumStr); } //Initialize the appropriate component of the currently selected color if(index == 0) cf.r = number; else if(index == 1) cf.g = number; else if(index == 2) cf.b = number; if (numberPrev != number) { // repaint current color box with new color cf.curc= new Color(cf.r, cf.g, cf.b); cf.cp.cbp.cc.repaint(); } // Get the current values for possible use later prevNumStr = NumStr; numberPrev = number; } // end textValueChanged } //end ColorTextFieldHandle