Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class LoanCalculatorPanel extends JPanel implements ActionListener
- {
- private JTextField loanAmountField,
- numberOfYearsField,
- yearlyInterestField,
- monthlyPaymentField;
- private JLabel loanAmountText,
- yearlyInterestRateText,
- numberOfYearsText,
- monthlyPaymentText,
- none,
- calculate;
- private JButton calculateButton,
- exitButton;
- private JRadioButton loanAmountButton,
- monthlyPaymentButton;
- public LoanCalculatorPanel()
- {
- JPanel displayPanel = new JPanel();
- displayPanel.setLayout(new GridBagLayout()); //GridLayout (0,2,10,10)
- GridBagConstraints c = new GridBagConstraints();
- loanAmountText = new JLabel("Loan Amount: ");
- c.weightx = 1;
- c.weighty = 1;
- c.insets = new Insets(10, 10, 10, 10);
- c.gridx = 0;
- c.gridy = 0;
- displayPanel.add(loanAmountText, c);
- loanAmountField = new JTextField(15);
- c.gridx = 1;
- c.gridy = 0;
- c.fill = GridBagConstraints.HORIZONTAL;
- c.weightx = 0.5;
- displayPanel.add(loanAmountField, c);
- yearlyInterestRateText = new JLabel("Yearly Interest Rate: ");
- c.gridx = 0;
- c.gridy = 1;
- displayPanel.add(yearlyInterestRateText, c);
- yearlyInterestField = new JTextField(15);
- c.gridx = 1;
- c.gridy = 1;
- c.fill = GridBagConstraints.HORIZONTAL;
- //c.weightx = 0.5;
- displayPanel.add(yearlyInterestField, c);
- numberOfYearsText = new JLabel("Number of Years: ");
- c.gridx = 0;
- c.gridy = 2;
- displayPanel.add(numberOfYearsText, c);
- numberOfYearsField = new JTextField(15);
- c.gridx = 1;
- c.gridy = 2;
- c.fill = GridBagConstraints.HORIZONTAL;
- //c.weightx = 0.5;
- displayPanel.add(numberOfYearsField, c);
- monthlyPaymentText = new JLabel("Monthly Payment: ");
- c.gridx = 0;
- c.gridy = 3;
- displayPanel.add(monthlyPaymentText, c);
- monthlyPaymentField = new JTextField(15);
- c.gridx = 1;
- c.gridy = 3;
- c.fill = GridBagConstraints.HORIZONTAL;
- //c.weightx = 0.5;
- displayPanel.add(monthlyPaymentField, c);
- JPanel calculatePanel = new JPanel();
- calculatePanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
- calculateButton = new JButton("Calculate");
- calculateButton.addActionListener(this);
- calculatePanel.add(calculateButton);
- exitButton = new JButton("Exit");
- exitButton.addActionListener(this);
- calculatePanel.add(exitButton);
- JPanel monthlyPaymentPanel = new JPanel();
- monthlyPaymentPanel.setLayout(new GridBagLayout()); //GridLayout(0, 2, 10, 10));
- monthlyPaymentPanel.setBorder(BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED, java.awt.Color.white, java.awt.Color.lightGray));
- calculate = new JLabel ("Calculate:");
- c.insets = new Insets(10, 10, 10, 10);
- c.gridx = 0;
- c.gridy = 0;
- c.ipadx = 5;
- c.ipady = 5;
- monthlyPaymentPanel.add(calculate, c);
- monthlyPaymentButton = new JRadioButton("Monthly Payment");
- monthlyPaymentButton.addActionListener(this);
- c.gridx = 0;
- c.gridy = 1;
- monthlyPaymentPanel.add(monthlyPaymentButton, c);
- loanAmountButton = new JRadioButton("Loan Amount");
- loanAmountButton.addActionListener(this);
- c.gridx = 1;
- c.gridy = 1;
- monthlyPaymentPanel.add(loanAmountButton, c);
- this.setLayout(new BorderLayout(10, 10));
- this.add(displayPanel, BorderLayout.CENTER);
- this.add(calculatePanel, BorderLayout.SOUTH);
- this.add(monthlyPaymentPanel, BorderLayout.NORTH);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement