
// A class that constructs a panel that can be used to experiment with the
// behavior of the "charAt" method of the String class.
public class CharAtTester extends StringInput implements StringOpTester {

    // Field used to enter character position
    LabeledTextField position;
    
    public CharAtTester() {
        // Create and add "position" field;
        position = new LabeledTextField("Character Position",7);
        inputPanel.add(position);
    }
    
    // Perform "charAt" operation when requested
    public String doIt() {
        try {
            return "" + sourceField.getText().charAt(Integer.parseInt(position.getText()));
        } catch (Exception e) {
            return "Value specified for position is invalid or out of range";
        }
        
    }
    
    // Return the name of the method this class invokes
    public String toString() {
        return "charAt";
    }
}