Results 1 to 3 of 3
- 11-09-2011, 03:29 AM #1
Member
- Join Date
- Sep 2010
- Location
- Southwest Missouri
- Posts
- 97
- Rep Power
- 0
Problem with frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E)
When transcribing this code I receive the following error message: "The method setDefaultCloseOperation(int) is undefined for the type LoanCalculator" I do not understand why I am receiving this message or how to get rid of it. The error is on line 80.
Here is the code:
Java Code:import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.TitledBorder; //create LoanCalcualtor class that extends the JFrame class, thus making //the LoanCalclator class a subclass of JFrame. public class LoanCalculator extends Frame { //Create text fields for interest rate //year, loan amount, monthly payment, and total payment private JTextField jtfAnnualInterestRate = new JTextField(); private JTextField jtfNumberOfYears = new JTextField(); private JTextField jtfLoanAmount = new JTextField(); private JTextField jtfMonthlyPayment = new JTextField(); private JTextField jtfTotalPayment = new JTextField(); //create a compute payment button private JButton jbtComputeLoan = new JButton("Compute Payment"); //construct LoanCalculator() constructor public LoanCalculator() { //create p1 JPanel object to hold labels and text fields JPanel p1 = new JPanel(new GridLayout(5, 2)); //add labels and text fields to p1 panel p1.add(new JLabel("Annual Interest Rate")); p1.add(jtfAnnualInterestRate); p1.add(new JLabel("Number of Years")); p1.add(jtfNumberOfYears); p1.add(new JLabel("Loan Amount")); p1.add(jtfLoanAmount); p1.add(new JLabel("Monthly Payment")); p1.add(jtfMonthlyPayment); p1.add(new JLabel("Total Payment")); p1.add(jtfTotalPayment); p1.setBorder(new TitledBorder("Enter loan amount, interest rate, and year")); //create p2 JPanel object to hold button JPanel p2 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); //add button to p2 panel p2.add(jbtComputeLoan); //add panels to the frame add(p1, BorderLayout.CENTER); add(p2, BorderLayout.SOUTH); //register listener for button jbtComputeLoan.addActionListener(new ButtonListener()); } //create ButtonListener class to handle the compute payment button public class ButtonListener implements ActionListener { //create actionPerformed() method public void actionPerformed(ActionEvent e) { //Get the values from the text fields double interest = Double.parseDouble(jtfAnnualInterestRate.getText()); int year = Integer.parseInt(jtfNumberOfYears.getText()); double loanAmount = Double.parseDouble(jtfLoanAmount.getText()); //create a new loan object Loan loan = new Loan(interest, year, loanAmount); //display monthly payment and total payment jtfMonthlyPayment.setText(String.format("%.2f", loan.getMonthlyPayment())); jtfTotalPayment.setText(String.format("%.2f", loan.getTotalPayment())); } } public static void main(String [] args) { //create new frame object LoanCalculator frame = new LoanCalculator(); frame.pack(); frame.setTitle("Loan Calculator"); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
- 11-09-2011, 03:37 AM #2
Re: Problem with frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E)
Since LoanCalculator extends Frame, I want you to go to the Java API, look up the Frame class and show me where the setDefaultCloseOperation method is.
- 11-09-2011, 03:50 AM #3
Member
- Join Date
- Sep 2010
- Location
- Southwest Missouri
- Posts
- 97
- Rep Power
- 0
Similar Threads
-
Need help with setDefaultCloseOperation
By noneofthem in forum New To JavaReplies: 1Last Post: 02-23-2011, 12:03 PM -
Java slave Frame access to its owner main frame problem
By cagdaseckin in forum New To JavaReplies: 0Last Post: 12-10-2010, 10:40 AM -
Using frame.pack() for resizing JFrame
By LianaN in forum AWT / SwingReplies: 0Last Post: 10-30-2010, 12:12 PM -
Frame problem
By nikunj in forum AWT / SwingReplies: 3Last Post: 08-09-2010, 02:01 PM -
JFrame - Output and Input in Frame - menu choice and simple Calculator
By sambo731 in forum AWT / SwingReplies: 3Last Post: 08-07-2010, 05:28 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks