import java.awt.*; import java.applet.*; import java.awt.event.*; import java.text.DecimalFormat; import java.net.*; public class lab9 extends Applet implements ActionListener { private TextField TF1, TF2, TF3, TF4, TF5, tf; private Button compute, clear, go; private Label L1, L2, L3, L4, L5; private URL site; public void init() { setLayout(new FlowLayout()); add(L1 = new Label("Loan Amount")); add(TF1 = new TextField(10)); add(L2 = new Label("Years")); add(TF2 = new TextField(10)); add(L3 = new Label("Yearly Interest Rate")); add(TF3 = new TextField(10)); add(L4 = new Label("Total Amount")); add(TF4 = new TextField(10)); add(L5 = new Label("Monthly Payment")); add(TF5 = new TextField(10)); add(compute = new Button("Compute")); add(clear = new Button("Clear")); add(tf = new TextField("http://members.fortunecity.com/blackscrol", 50)); add(go = new Button("GO")); go.addActionListener(this); // TF5.setEditable(false); // TF4.setEditable(false); compute.addActionListener(this); clear.addActionListener(this); TF3.addActionListener(this); } public void Compute() throws NegativeNumberException, DivideByZeroException { double Amt, Rate, Years, mr, mp; int m; Amt = Double.valueOf(TF1.getText().trim()).doubleValue(); Years = Integer.valueOf(TF2.getText().trim()).intValue(); Rate = Double.valueOf(TF3.getText().trim()).doubleValue(); if((Amt == 0)||(Rate == 0)||(Years == 0)) { throw new DivideByZeroException(); } if((Amt < 0)||(Rate < 0)||(Years < 0)) { throw new NegativeNumberException(); } m = (int) Years*12; mr = (Rate/12)*.01; TF4.setText("$" + Double.toString((mp = (Amt * mr)/(1 - (Math.pow((1/(1+mr)),m)))))); TF5.setText("$" + Double.toString((mp*m))); } public void clearAll() { TF1.setText(" "); TF2.setText(" "); TF3.setText(" "); TF4.setText(" "); TF5.setText(" "); } public void actionPerformed(ActionEvent ae) { Object src = ae.html try { if(src instanceof Button) { if(src == go) { AppletContext con = getAppletContext(); site = new URL(getDocumentBase(), tf.getText()); con.showDocument(site); } if(src == compute) { Compute(); } if(src == clear) { clearAll(); } } if(src instanceof TextField) { if(src == TF3) { Compute(); } } } catch(NumberFormatException x) { TF5.setText("Listen! No letters Asshole"); } catch(NegativeNumberException y) { TF5.setText("no negative numbers"); } catch(DivideByZeroException z) { TF5.setText("You cannot enter zero"); } catch(Exception e) { showStatus("the error is" + e); } } } class DivideByZeroException extends Exception { } class NegativeNumberException extends Exception { }
Do this next