home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-09-06 | 7.3 KB | 234 lines |
- /*
- A basic extension of the java.awt.Frame class
- */
-
- import java.awt.*;
-
- import symantec.itools.awt.KeyPressManagerPanel;
- public class LoanCalcFrame extends Frame {
-
- void Frame1_WindowClosing(java.awt.event.WindowEvent event)
- {
- hide(); // hide the Frame
- }
-
- public LoanCalcFrame()
- {
- // This code is automatically generated by Visual Cafe when you add
- // components to the visual environment. It instantiates and initializes
- // the components. To modify the code, only use code syntax that matches
- // what Visual Cafe can generate, or Visual Cafe may be unable to back
- // parse your Java file into its visual environment.
- //{{INIT_CONTROLS
- GridBagLayout gridBagLayout;
- gridBagLayout = new GridBagLayout();
- setLayout(gridBagLayout);
- setVisible(false);
- setSize(insets().left + insets().right + 419,insets().top + insets().bottom + 165);
- PrincipleLabel = new java.awt.Label("Principle =");
- PrincipleLabel.setBounds(insets().left + 65,insets().top + 9,72,23);
- GridBagConstraints gbc;
- gbc = new GridBagConstraints();
- gbc.gridx = 0;
- gbc.gridy = 0;
- gbc.weightx = 1.0;
- gbc.weighty = 1.0;
- gbc.fill = GridBagConstraints.NONE;
- gbc.insets = new Insets(0,0,0,0);
- ((GridBagLayout)getLayout()).setConstraints(PrincipleLabel, gbc);
- add(PrincipleLabel);
- InterestLabel = new java.awt.Label("Interest =");
- InterestLabel.setBounds(insets().left + 69,insets().top + 50,65,23);
- gbc = new GridBagConstraints();
- gbc.gridx = 0;
- gbc.gridy = 1;
- gbc.weightx = 1.0;
- gbc.weighty = 1.0;
- gbc.fill = GridBagConstraints.NONE;
- gbc.insets = new Insets(0,0,0,0);
- ((GridBagLayout)getLayout()).setConstraints(InterestLabel, gbc);
- add(InterestLabel);
- LengthLabel = new java.awt.Label("Length of loan(years) =");
- LengthLabel.setBounds(insets().left + 31,insets().top + 91,140,23);
- gbc = new GridBagConstraints();
- gbc.gridx = 0;
- gbc.gridy = 2;
- gbc.weightx = 1.0;
- gbc.weighty = 1.0;
- gbc.fill = GridBagConstraints.NONE;
- gbc.insets = new Insets(0,0,0,0);
- ((GridBagLayout)getLayout()).setConstraints(LengthLabel, gbc);
- add(LengthLabel);
- PaymentsLabel = new java.awt.Label("Monthly payments =");
- PaymentsLabel.setBounds(insets().left + 40,insets().top + 132,122,23);
- gbc = new GridBagConstraints();
- gbc.gridx = 0;
- gbc.gridy = 3;
- gbc.weightx = 1.0;
- gbc.weighty = 1.0;
- gbc.fill = GridBagConstraints.NONE;
- gbc.insets = new Insets(0,0,0,0);
- ((GridBagLayout)getLayout()).setConstraints(PaymentsLabel, gbc);
- add(PaymentsLabel);
- PrincipleTextField = new java.awt.TextField(15);
- PrincipleTextField.setBounds(insets().left + 234,insets().top + 9,24,23);
- gbc = new GridBagConstraints();
- gbc.gridx = 1;
- gbc.gridy = 0;
- gbc.weightx = 1.0;
- gbc.weighty = 1.0;
- gbc.fill = GridBagConstraints.NONE;
- gbc.insets = new Insets(0,0,0,0);
- ((GridBagLayout)getLayout()).setConstraints(PrincipleTextField, gbc);
- add(PrincipleTextField);
- InterestTextField = new java.awt.TextField(15);
- InterestTextField.setBounds(insets().left + 234,insets().top + 50,24,23);
- gbc = new GridBagConstraints();
- gbc.gridx = 1;
- gbc.gridy = 1;
- gbc.weightx = 1.0;
- gbc.weighty = 1.0;
- gbc.fill = GridBagConstraints.NONE;
- gbc.insets = new Insets(0,0,0,0);
- ((GridBagLayout)getLayout()).setConstraints(InterestTextField, gbc);
- add(InterestTextField);
- LengthTextField = new java.awt.TextField(15);
- LengthTextField.setBounds(insets().left + 234,insets().top + 91,24,23);
- gbc = new GridBagConstraints();
- gbc.gridx = 1;
- gbc.gridy = 2;
- gbc.weightx = 1.0;
- gbc.weighty = 1.0;
- gbc.fill = GridBagConstraints.NONE;
- gbc.insets = new Insets(0,0,0,0);
- ((GridBagLayout)getLayout()).setConstraints(LengthTextField, gbc);
- add(LengthTextField);
- PaymentsTextField = new java.awt.TextField(15);
- PaymentsTextField.setEditable(false);
- PaymentsTextField.setBounds(insets().left + 234,insets().top + 132,24,23);
- PaymentsTextField.setBackground(new Color(12632256));
- gbc = new GridBagConstraints();
- gbc.gridx = 1;
- gbc.gridy = 3;
- gbc.weightx = 1.0;
- gbc.weighty = 1.0;
- gbc.fill = GridBagConstraints.NONE;
- gbc.insets = new Insets(0,0,0,0);
- ((GridBagLayout)getLayout()).setConstraints(PaymentsTextField, gbc);
- add(PaymentsTextField);
- CalcButton = new java.awt.Button();
- CalcButton.setActionCommand("button");
- CalcButton.setLabel("Calculate");
- CalcButton.setBounds(insets().left + 321,insets().top + 70,66,23);
- gbc = new GridBagConstraints();
- gbc.gridx = 2;
- gbc.gridy = 0;
- gbc.gridheight = 4;
- gbc.weightx = 1.0;
- gbc.weighty = 1.0;
- gbc.fill = GridBagConstraints.NONE;
- gbc.insets = new Insets(0,0,0,0);
- ((GridBagLayout)getLayout()).setConstraints(CalcButton, gbc);
- add(CalcButton);
- setTitle("Loan Calculation");
- //}}
-
- //{{INIT_MENUS
- //}}
-
- //{{REGISTER_LISTENERS
- Window lWindow = new Window();
- addWindowListener(lWindow);
- Action lAction = new Action();
- CalcButton.addActionListener(lAction);
- //}}
- }
-
- public LoanCalcFrame(String title)
- {
- this();
- setTitle(title);
- }
-
- public synchronized void show()
- {
- move(50, 50);
- super.show();
- }
-
- public void addNotify()
- {
- super.addNotify();
-
- if (fComponentsAdjusted)
- return;
-
- // Adjust components according to the insets
- setSize(insets().left + insets().right + getSize().width, insets().top + insets().bottom + getSize().height);
- Component components[] = getComponents();
- for (int i = 0; i < components.length; i++)
- {
- Point p = components[i].getLocation();
- p.translate(insets().left, insets().top);
- components[i].setLocation(p);
- }
- fComponentsAdjusted = true;
- }
-
- boolean fComponentsAdjusted = false;
-
- //{{DECLARE_CONTROLS
- java.awt.Label PrincipleLabel;
- java.awt.Label InterestLabel;
- java.awt.Label LengthLabel;
- java.awt.Label PaymentsLabel;
- java.awt.TextField PrincipleTextField;
- java.awt.TextField InterestTextField;
- java.awt.TextField LengthTextField;
- java.awt.TextField PaymentsTextField;
- java.awt.Button CalcButton;
- //}}
-
- //{{DECLARE_MENUS
- //}}
-
- class Window extends java.awt.event.WindowAdapter
- {
- public void windowClosing(java.awt.event.WindowEvent event)
- {
- Object object = event.getSource();
- if (object == LoanCalcFrame.this)
- Frame1_WindowClosing(event);
- }
- }
-
- class Action implements java.awt.event.ActionListener
- {
- public void actionPerformed(java.awt.event.ActionEvent event)
- {
- Object object = event.getSource();
- if (object == CalcButton)
- CalcButton_Action(event);
- }
- }
-
- void CalcButton_Action(java.awt.event.ActionEvent event)
- {
- double Principal, InterestRate, LengthLoan, MonthlyPay, IntDec, NumMonths;
-
- try {
- Principal = ( Double.valueOf(PrincipleTextField.getText() ) ).doubleValue();
- InterestRate = ( Double.valueOf(InterestTextField.getText()) ).doubleValue();
- LengthLoan = ( Double.valueOf(LengthTextField.getText() ) ).doubleValue();
- } catch (NumberFormatException e) {return;}
-
- if (Principal < 0 || InterestRate < 0 || LengthLoan < 0) return;
-
- IntDec = InterestRate / (12.0 * 100.0);
- NumMonths = LengthLoan * 12.0;
- MonthlyPay = Principal * (IntDec / (1.0 - Math.pow((1.0 + IntDec), -NumMonths)));
-
- PaymentsTextField.setText(String.valueOf(MonthlyPay));
- }
- }
-