Novis java student needs help I am in a begining Java class and I cant figure something out. I am trying to add actionlistener to my program so that the buttons will do something. The reading is vague and I dont understand it very well. I have spent hours trying to figure this out. Can someone plese help. I have attached the code below.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MortgageDriver extends JFrame implements ActionListener{
public void actionPerformed(ActionEvent event);{
}
// set up row 1
JPanel row1 = new JPanel();
ButtonGroup option = new ButtonGroup();
JLabel yearsLable = new JLabel("How many years of Mortgage: ", JLabel.RIGHT);
JButton byears7 = new JButton("7");
JButton byears15 = new JButton("15");
JButton byears30 = new JButton("30");
// set up row 2
JPanel row2 = new JPanel();
JLabel lyears7 = new JLabel(" The intrest rate for 7 year loan is: .??? ", JLabel.CENTER);
JLabel lyears15 = new JLabel(" The intrest rate for 15 year loan is: .??? ", JLabel.CENTER);
JLabel lyears30 = new JLabel(" The intrest rate for 30 year loan is: .??? ", JLabel.CENTER);
// set up row 3
JPanel row3 = new JPanel();
JLabel lamount = new JLabel("Amount of Loan: ", JLabel.RIGHT);
JTextField namount = new JTextField();
// set up row 4
JPanel row4 = new JPanel();
ButtonGroup option4 = new ButtonGroup();
JButton calcmortg = new JButton("Calculate Mortgage");
// set up row 5
JPanel row5 = new JPanel();
ButtonGroup option5 = new ButtonGroup();
JButton exit = new JButton("Exit");
public MortgageDriver() {
super("Mortgage Calculator");
setSize(750, 270);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GridLayout layout = new GridLayout(5, 1, 10, 10);
Container pane = getContentPane();
pane.setLayout(layout);
FlowLayout layout1 = new FlowLayout(FlowLayout.CENTER,
10, 10);
option.add(byears7);
option.add(byears15);
option.add(byears30);
row1.setLayout(layout1);
row1.add(yearsLable);
row1.add(byears7);
row1.add(byears15);
row1.add(byears30);
pane.add(row1);
FlowLayout layout2 = new FlowLayout(FlowLayout.CENTER,
10, 10);
row2.setLayout(layout2);
row2.add(lyears7);
row2.add(lyears15);
row2.add(lyears30);
pane.add(row2);
GridLayout layout3 = new GridLayout(0, 7);
row3.setLayout(layout3);
row3.add(lamount);
row3.add(namount);
pane.add(row3);
FlowLayout layout4 = new FlowLayout(FlowLayout.CENTER,
10, 10);
row4.setLayout(layout4);
option4.add(calcmortg);
row4.add(calcmortg);
pane.add(row4);
FlowLayout layout5 = new FlowLayout(FlowLayout.CENTER,
10, 10);
row5.setLayout(layout5);
option5.add(exit);
row5.add(exit);
pane.add(row5);
setContentPane(pane);
setVisible(true);
}
public static void main(String[] arguments) {
MortgageDriver md = new MortgageDriver();
}
} |