1 // A test Applet to show how to use the AccountException class. 2 // This applet catches an exception thrown by the other class. 3 // Nancy McCracken 5/14/97 4 5 import java.awt.*; 6 7 public class AccountExceptionTest extends java.applet.Applet 8 { Font f = new Font("TimesRoman", Font.BOLD, 24); 9 10 AccountException kathy; // variable for instance of Account class 11 int x; // variables x and y control print placement 12 int y; 13 14 public void init() 15 { 16 // create a new instance of the Account class 17 kathy = new AccountException ("Kathy", 100.F ); 18 } 19 20 public void paint(Graphics g) 21 { String s; 22 g.setFont(f); 23 x = 25; y = 25; 24 print(g, "Kathy's initial balance is $" 25 + kathy.getbalance()); 26 27 try { 28 kathy.withdraw(523.F); 29 print(g, "Kathy tries to withdraw $523."); 30 } 31 catch(Exception e) 32 {print(g, e.getMessage());} 33 34 kathy.deposit(1500.F); 35 print(g, "Kathy deposits $1500."); 36 37 kathy.monthactivity(); 38 print(g, "After one month, Kathy's account has $" 39 + kathy.getbalance()); 40 } 41 42 public void print(Graphics g, String s) 43 { g.drawString (s, x, y); 44 y += 30; 45 } 46 }