JAVA Problem Graphical Interface-Lost Help?


One Response to “JAVA Problem Graphical Interface-Lost Help?”

  1. codrguy says:

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;

    import javax.swing.*;
    import java.text.*;
    import java.awt.Dimension;

    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTextArea;
    import javax.swing.SwingUtilities;

    public class MortgageCalculator extends JFrame implements ActionListener{
    private NumberFormat currency;
    JFormattedTextField loanamount = new JFormattedTextField() ;
    JFormattedTextField term= new JFormattedTextField();
    JFormattedTextField interestrate= new JFormattedTextField();
    JTextArea outputText;
    private void jbInit() {
    JPanel contentPane = (JPanel) getContentPane();
    contentPane.setLayout(new FlowLayout());
    setSize(new Dimension(400, 300));
    setTitle(“This is the first frame”);
    loanamount.setColumns(5);
    term.setColumns(5);
    interestrate.setColumns(5);
    currency = NumberFormat.getCurrencyInstance();
    JLabel lblterm = new JLabel(“Term of loan: “);
    JLabel lblrate = new JLabel(“Rate: “);
    JLabel lblamount = new JLabel(“Amount: “);
    JButton btnCalculate = new JButton(“Calculate”);
    JButton btnReset = new JButton(“Reset”);
    JButton btnEnd = new JButton(“End”);
    btnCalculate.setActionCommand(“calculate”);
    btnReset.setActionCommand(“reset”);
    btnEnd.setActionCommand(“end”);
    btnCalculate.addActionListener(this);
    btnReset.addActionListener(this);
    btnEnd.addActionListener(this);
    String defaultOutputMessage = “Please enter the amount of the loan” +
    ” the length of the loan, and the selected interest rate. Click on Calculate” +
    ” when done.”;
    outputText = new JTextArea(defaultOutputMessage);
    outputText.setColumns(35);
    outputText.setRows(5);
    outputText.setLineWrap(true);
    outputText.setEditable(false);
    outputText.setWrapStyleWord(true);
    add(lblterm);
    add(term);
    add(lblrate);
    add(interestrate);
    add(lblamount);
    add(loanamount);
    add(btnCalculate);
    add(btnReset);
    add(btnEnd);
    add(outputText);
    setVisible(true);
    }

    public void actionPerformed(ActionEvent e) {
    if (“calculate”.equals(e.getActionCommand())) {
    calculate();
    }
    else if (“reset”.equals(e.getActionCommand())) {
    term.setText(“”);
    interestrate.setText(“”);
    loanamount.setText(“”);
    }
    else
    {
    System.exit(0);
    }

    }

    public static void main(String[] args){
    //variables that are to be used and the information in the program.

    MortgageCalculator test = new MortgageCalculator();
    test.jbInit();
    }

    // (Main) method that will display all of the output.

    // Define the variables to be used
    private void calculate()
    {
    double loan = Double.parseDouble(loanamount.getText());
    int termlength = Integer.parseInt(term.getText());
    double rate = Double.parseDouble(interestrate.getText());
    double Payment = calculatePayment(loan, termlength,rate/100);
    outputText.setText(“Mortgage Payment is ” + currency.format(Payment));

    }

    // Used to calculate the amound in the payment based on the principle, the term and the interest rate.
    public static double calculatePayment(double principle, int term, double rate)
    {
    //Returns the amount of the mortgage and does all the fancy work for the user behind the scenes in the meanwhile exiting quietly.
    return(principle * Math.pow(1+(rate/12), term) * rate/12) / (Math.pow(1 + rate/12, term) – 1);
    }
    }

Leave a Reply

*


Celebrity Sex Tapes | Kim Kardashian Sex Tape