home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-03-20 | 1.3 KB | 55 lines |
- import java.awt.*;
- import java.applet.*;
-
- public class ExceptionApplet5 extends Applet
- {
- TextField textField1, textField2;
- String displayStr;
- int array[];
-
- public void init()
- {
- textField1 = new TextField(15);
- add(textField1);
- textField2 = new TextField(15);
- add(textField2);
- displayStr = "";
- array = new int[100];
- }
-
- public void paint(Graphics g)
- {
- Font font = new Font("TimesRoman", Font.PLAIN, 18);
- g.setFont(font);
-
- g.drawString("Valid array indexes are 0 to 99", 15, 60);
- g.drawString(displayStr, 70, 130);
- }
-
- public boolean action(Event evt, Object arg)
- {
- String str1 = textField1.getText();
- String str2 = textField2.getText();
-
- try
- {
- int index = Integer.parseInt(str1);
- int value = Integer.parseInt(str2);
- array[index] = value;
- displayStr = "Value stored.";
- }
- catch (ArrayIndexOutOfBoundsException e)
- {
- displayStr = "Out of bounds";
- }
- catch (NumberFormatException e)
- {
- displayStr = "Bad format";
- }
-
- repaint();
- return true;
- }
- }
-
-