Advertisement
Guest User

LoanCalculatorFrame2

a guest
Aug 8th, 2012
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.18 KB | None | 0 0
  1. class LoanCalculatorPanel extends JPanel implements ActionListener
  2. {
  3.     private JTextField loanAmountField,
  4.                        numberOfYearsField,
  5.                        yearlyInterestField,
  6.                        monthlyPaymentField;
  7.     private JLabel loanAmountText,
  8.                    yearlyInterestRateText,
  9.                    numberOfYearsText,
  10.                    monthlyPaymentText,
  11.                    none,
  12.                    calculate;
  13.     private JButton calculateButton,
  14.                     exitButton;
  15.     private JRadioButton loanAmountButton,
  16.                          monthlyPaymentButton;
  17.    
  18.     public LoanCalculatorPanel()
  19.     {
  20.         JPanel displayPanel = new JPanel();
  21.         displayPanel.setLayout(new GridBagLayout()); //GridLayout (0,2,10,10)
  22.         GridBagConstraints c = new GridBagConstraints();
  23.        
  24.         loanAmountText = new JLabel("Loan Amount: ");
  25.         c.weightx = 1;
  26.         c.weighty = 1;
  27.         c.insets = new Insets(10, 10, 10, 10);
  28.         c.gridx = 0;
  29.         c.gridy = 0;
  30.         displayPanel.add(loanAmountText, c);
  31.        
  32.         loanAmountField = new JTextField(15);
  33.         c.gridx = 1;
  34.         c.gridy = 0;
  35.         c.fill = GridBagConstraints.HORIZONTAL;
  36.         c.weightx = 0.5;
  37.         displayPanel.add(loanAmountField, c);
  38.                  
  39.         yearlyInterestRateText = new JLabel("Yearly Interest Rate: ");
  40.         c.gridx = 0;
  41.         c.gridy = 1;
  42.         displayPanel.add(yearlyInterestRateText, c);
  43.        
  44.         yearlyInterestField = new JTextField(15);
  45.         c.gridx = 1;
  46.         c.gridy = 1;
  47.         c.fill = GridBagConstraints.HORIZONTAL;
  48.         //c.weightx = 0.5;
  49.         displayPanel.add(yearlyInterestField, c);
  50.                      
  51.         numberOfYearsText = new JLabel("Number of Years: ");
  52.         c.gridx = 0;
  53.         c.gridy = 2;
  54.         displayPanel.add(numberOfYearsText, c);
  55.        
  56.         numberOfYearsField = new JTextField(15);
  57.         c.gridx = 1;
  58.         c.gridy = 2;
  59.         c.fill = GridBagConstraints.HORIZONTAL;
  60.         //c.weightx = 0.5;
  61.         displayPanel.add(numberOfYearsField, c);
  62.                
  63.         monthlyPaymentText = new JLabel("Monthly Payment: ");
  64.         c.gridx = 0;
  65.         c.gridy = 3;
  66.         displayPanel.add(monthlyPaymentText, c);
  67.        
  68.         monthlyPaymentField = new JTextField(15);
  69.         c.gridx = 1;
  70.         c.gridy = 3;
  71.         c.fill = GridBagConstraints.HORIZONTAL;
  72.         //c.weightx = 0.5;
  73.         displayPanel.add(monthlyPaymentField, c);
  74.        
  75.        
  76.         JPanel calculatePanel = new JPanel();
  77.         calculatePanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
  78.        
  79.         calculateButton = new JButton("Calculate");
  80.         calculateButton.addActionListener(this);
  81.         calculatePanel.add(calculateButton);
  82.        
  83.         exitButton = new JButton("Exit");
  84.         exitButton.addActionListener(this);
  85.         calculatePanel.add(exitButton);
  86.        
  87.         JPanel monthlyPaymentPanel = new JPanel();
  88.         monthlyPaymentPanel.setLayout(new GridBagLayout()); //GridLayout(0, 2, 10, 10));
  89.  
  90.         monthlyPaymentPanel.setBorder(BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED, java.awt.Color.white, java.awt.Color.lightGray));
  91.  
  92.         calculate = new JLabel ("Calculate:");
  93.         c.insets = new Insets(10, 10, 10, 10);
  94.         c.gridx = 0;
  95.         c.gridy = 0;
  96.         c.ipadx = 5;
  97.         c.ipady = 5;
  98.         monthlyPaymentPanel.add(calculate, c);
  99.        
  100.        
  101.         monthlyPaymentButton = new JRadioButton("Monthly Payment");
  102.         monthlyPaymentButton.addActionListener(this);
  103.         c.gridx = 0;
  104.         c.gridy = 1;
  105.         monthlyPaymentPanel.add(monthlyPaymentButton, c);
  106.                      
  107.         loanAmountButton = new JRadioButton("Loan Amount");
  108.         loanAmountButton.addActionListener(this);
  109.         c.gridx = 1;
  110.         c.gridy = 1;
  111.         monthlyPaymentPanel.add(loanAmountButton, c);
  112.        
  113.         this.setLayout(new BorderLayout(10, 10));
  114.         this.add(displayPanel, BorderLayout.CENTER);
  115.         this.add(calculatePanel, BorderLayout.SOUTH);
  116.         this.add(monthlyPaymentPanel, BorderLayout.NORTH);      
  117.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement