// NumberFormatDemo.java: Demonstrate formatting numbers package chapter14; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; import java.util.*; import java.text.*; public class NumberFormatDemo extends JApplet implements ItemListener, ActionListener { // Combo box for selecting available locales JComboBox jcboLocale = new JComboBox(); // Text fields for interest rate, year, loan amount, JTextField jtfInterestRate = new JTextField(10); JTextField jtfNumOfYears = new JTextField(10); JTextField jtfLoanAmount = new JTextField(10); JTextField jtfFormattedInterestRate = new JTextField(10); JTextField jtfFormattedNumOfYears = new JTextField(10); JTextField jtfFormattedLoanAmount = new JTextField(10); // Text fields for monthly payment and total payment JTextField jtfTotalPayment = new JTextField(); JTextField jtfMonthlyPayment = new JTextField(); // Compute Mortgage button JButton jbtCompute = new JButton("Compute"); // Current locale Locale locale = Locale.getDefault(); // Declare locales to store available locales Locale locales[] = Calendar.getAvailableLocales(); /**Initialize the combo box*/ public void initializeComboBox() { // Add locale names to the combo box for (int i=0; i