Java The Complete Reference, Seventh Edition

(Greg DeLong) #1
// Find the remaining balance on a loan.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.*;
/*
<applet code="RemBal" width=340 height=260>
</applet>
*/

public class RemBal extends JApplet
implements ActionListener {

JTextField orgPText, paymentText, remBalText,
rateText, numPayText;
JButton doIt;

double orgPrincipal; // original principal
double intRate; // interest rate
double payment; // amount of each payment
double numPayments; // number of payments made

/* Number of payments per year. You could
allow this value to be set by the user. */
final int payPerYear = 12;

NumberFormat nf;

public void init() {
try {
SwingUtilities.invokeAndWait(new Runnable () {
public void run() {
makeGUI(); // initialize the GUI
}
});
} catch(Exception exc) {
System.out.println("Can't create because of "+ exc);

956 Part IV: Applying Java


FIGURE 32-6

TheRemBal
applet
Free download pdf