FileDocCategorySizeDatePackage
ExceptionDemo1.javaAPI DocExample1803Mon Apr 02 14:34:32 BST 2001None

ExceptionDemo1

public class ExceptionDemo1 extends Applet implements ActionListener

Fields Summary
private TextField
stringField
private TextField
resultField
private Label
resultLabel
private Label
stringLabel
Constructors Summary
Methods Summary
public voidactionPerformed(java.awt.event.ActionEvent event)

        if (event.getSource() == stringField) 
        {
            try 
            {
                int number = Integer.parseInt(stringField.getText());
                checkNum(number);
                resultField.setText("Squared value is " + number*number);
            }
            catch (NumberFormatException e) 
            {
                resultField.setText("Error in number : Retype");
            }
            
            catch (myException me)
            {
	            resultField.setText("negative number: retype ");
            }
        }// endif    
     
public voidcheckNum(int n)

     if (n < 0) throw new myException();
     
public voidinit()

        stringLabel = new Label("Type an integer: ");
        resultLabel = new Label("Answer: ");
        stringField = new TextField(20);
        resultField = new TextField(20);
        resultField.setEditable(false);

        add(stringLabel);
        add(stringField);
        stringField.addActionListener(this);
        add(resultLabel);
        add(resultField);