how do I get my buttons to have functionality? the window is set up the way I want it. however, when the user clicks on the calculate button I want it to perform a mathmatical function and then display the results in the payment field.
Please Help
here is my program:
import javax.swing.*;
import java.awt.*;
class PosMortg1 extends JFrame {
PosMortg1() {
super("Calculate a Mortgage Payment?");
setSize(370, 270);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container pane = getContentPane();
FlowLayout flow = new FlowLayout(FlowLayout.RIGHT);
pane.setLayout(flow);
JPanel row1 = new JPanel();
JLabel amountLabel = new JLabel("How much are you Borrowing?");
row1.add(amountLabel);
JTextField amount = new JTextField(14);
row1.add(amount);
pane.add(row1);
JPanel row2 = new JPanel();
JLabel percentLabel = new JLabel("Enter Percent Rate:");
row2.add(percentLabel);
JTextField percent = new JTextField(14);
row2.add(percent);
pane.add(row2);
JPanel row3 = new JPanel();
JLabel yearsLabel = new JLabel("How Many Years?");
row3.add(yearsLabel);
JTextField years = new JTextField(14);
row3.add(years);
pane.add(row3);
JPanel row4 = new JPanel();
JButton calculate = new JButton("Calculate");
row4.add(calculate);
pane.add(row4);
JPanel row5 = new JPanel();
JLabel paymentLabel = new JLabel("Monthly Payments");
row5.add(paymentLabel);
JTextArea payment = new JTextArea(4, 14);
payment.setLineWrap(true);
payment.setWrapStyleWord(true);
JScrollPane scroll = new JScrollPane(payment,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
row5.add(scroll);
pane.add(row5);
setContentPane(pane);
setVisible(true);
}
public static void main(
String[] arguments) {
PosMortg1 mortgage = new PosMortg1();
}
}
