Link to home
Start Free TrialLog in
Avatar of spoilerbalto
spoilerbalto

asked on

uses or overrides a deprecated API.

What does this error mean? What am I doing wrong?
It complies, but it will not run.

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.text.NumberFormat;
import java.text.DecimalFormat;
import java.math.*;
import java.io.*;
import javax.swing.JOptionPane;


public class GUIMortgageCalculator43 extends JFrame implements ActionListener
{

                  //adding RadioButtons
     JPanel row_a1 = new JPanel();
     JRadioButton opt1 = new JRadioButton ("Manual Input", true);
     JRadioButton opt2 = new JRadioButton ("Menu Selections", false);

             //content Buttons, Panels, Labels, and TextFields

     JPanel row_a = new JPanel();
     JLabel amntLabel = new JLabel();

     JTextField loanField = new JTextField(11);
     JLabel loan2Label = new JLabel ();
     JPanel row_b = new JPanel();

     JPanel row_b1 = new JPanel();
             JLabel termLabel = new JLabel ();  //term
             JTextField termField = new JTextField(4);

             JPanel row_b2 = new JPanel();
             JLabel int_entryLabel = new JLabel ();  //interest
             JTextField int_entryField = new JTextField(3);

     JComboBox options = new JComboBox();
     JLabel optionsLabel = new JLabel();

     JPanel row_c = new JPanel();
     JButton calButton = new JButton();
     JButton resetButton = new JButton();
     JButton endButton = new JButton();

     JPanel row_d = new JPanel();
     JLabel paymtLabel = new JLabel();
     JTextField paymtField = new JTextField(8);

     JPanel row_e = new JPanel();
     JLabel outputLabel = new JLabel();

     JPanel row_f = new JPanel();
     JTextArea opField = new JTextArea(5, 55);


     JScrollPane scrollPane = new JScrollPane(opField,
               ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
               ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

          ButtonGroup radioSelect = new ButtonGroup();

//setting of GUI layout
     public GUIMortgageCalculator43() {

                              //main GUI Dimensions
          super(" Adam Bradley's GUI Mortgage Calculator");
          setSize(800, 450);
          new GridLayout(6, 1, 10, 10);
          FlowLayout flowCenter = new FlowLayout(FlowLayout.CENTER);
          FlowLayout flow = new FlowLayout(FlowLayout.LEFT);

          Container pane = getContentPane();
          pane.setLayout(flow);


          setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
          setVisible(true);

                              //setting actionListeners for Fields and Buttons
          loanField.addActionListener(this);
          termField.addActionListener(this);
          int_entryField.addActionListener(this);
          options.addActionListener(this);
          calButton.addActionListener(this);
          resetButton.addActionListener(this);
          endButton.addActionListener(this);
          opt1.addActionListener(this);
          opt2.addActionListener(this);


                              //layout for mortgage amount entry
                              row_a.setLayout(flow);
          amntLabel.setText("Enter Loan Amount:");
          row_a.add(amntLabel);
          row_a.add(loanField);
          pane.add(row_a);

          row_a1.setLayout(flow);
                              radioSelect.add(opt1);
          radioSelect.add(opt2);
          row_a1.add(opt1);
          row_a1.add(opt2);
          pane.add(row_a1);


                              //layout for options
          options.addItem("7 years at 5.35%");
          options.addItem("15 years at 5.5%");
          options.addItem("30 years at 5.75%");
          options.setEnabled(false);

          row_b.setLayout(flow);
          row_b.add(options);
          pane.add(row_b);

          row_b1.setLayout(flow);
          termLabel.setText("Term in Years");
          row_b1.add(termLabel);
          row_b1.add(termField);
          pane.add(row_b1);

          row_b2.setLayout(flow);
          int_entryLabel.setText("Interest %");
          row_b2.add(int_entryLabel);
          row_b2.add(int_entryField);
          pane.add(row_b2);


                              //layout for buttons to calculate, Reset, and End
                              row_c.setLayout(flow);
          calButton.setText("Calculate");
          calButton.setBackground(Color.blue);
          row_c.add(calButton);
          resetButton.setText("Reset");
          resetButton.setBackground(Color.blue);
          row_c.add(resetButton);
          endButton.setText("End");
          endButton.setBackground(Color.blue);
          row_c.add(endButton);
          pane.add(row_c);

                              //layout for section that shows the monthly payment amount
          row_d.setLayout(flow);
          paymtLabel.setText("Monthly Payment Amount:");
          row_d.add(paymtLabel);
          row_d.add(paymtField);
          pane.add(row_d);

                              //layout for loan amoritzation table
          row_e.setLayout(flow);
          outputLabel.setText("Loan Payment Table");
          row_e.add(outputLabel);
          pane.add(row_e);

          row_f.setLayout(flowCenter);
          opField.setLineWrap(true);
          opField.setWrapStyleWord(true);
          opField.setEditable(true);
          row_f.add(scrollPane);
          pane.add(row_f);


     }


//adding actionEvents for Buttons
     public void actionPerformed(ActionEvent event) {

          Object source = event.getSource();

          if (source == calButton) {
               startCalculations();

          }
          if (source == resetButton) {
               reset();

          }
          if (source == endButton) {
               end();

          }
          if (source == opt1){

              options.setEnabled(false);
                   termField.setEnabled(true);
              termField.setEditable(true);
              int_entryField.setEnabled(true);
              int_entryField.setEditable(true);
              }

              if (source == opt2){

              options.setEnabled(true);
              termField.setEnabled(false);
              termField.setEditable(false);
              int_entryField.setEnabled(false);
              int_entryField.setEditable(false);
              }

         }
//formulas for monthly payment
     void startCalculations() {

          Thread thisThread = Thread.currentThread();
          NumberFormat currency = NumberFormat.getCurrencyInstance();

          double amt = 0;   //amount of loan
          double trm = 0;   //variable for term of loan
          double intrst = 0;  //variable for interest amount of loan
          double moIn = 0;  //variable for monthly payment for formula
          double moTrm = 0; //variable for monthly term for formula
          double prin = 0;  // variable for principle
          double paymt = 0;  //variable for payment
          double newPrin = amt;
          boolean Exception = false;


          try {
               amt = Double.parseDouble(loanField.getText());
          } catch (NumberFormatException e) {
               JOptionPane.showMessageDialog(null, "Please Do Not Use Commas",
                         "Message Dialog", JOptionPane.PLAIN_MESSAGE);
               loanField.setText(null);

          }

          if (opt2.isSelected())
          {
              if(options.getSelectedIndex() == 0)
              {
          trm=7;
          intrst=5.35;
          }
              else if(options.getSelectedIndex() ==1)
              {
                    trm=15;
                    intrst=5.5;
              }
              else
              {
                    trm=30;
                                    intrst=5.75;
                              }
                              }
                              else
                              {
         try
                    {
                   trm = Double.parseDouble(termField.getText());
                    }
                    catch (NumberFormatException e)
                    {
                    JOptionPane.showMessageDialog(this,"Enter amounts greater than zero","Please enter new amount",JOptionPane.ERROR_MESSAGE);
                    Exception=true;
                    termField.setText(null);
              }
              try
              {
                    intrst= Double.parseDouble(int_entryField.getText());
              }
              catch (NumberFormatException e)
              {
                    JOptionPane.showMessageDialog(this,"Enter amount greater than zero and with no % sign","Please enter new amount",JOptionPane.ERROR_MESSAGE);
                    Exception=true;
                    int_entryField.setText(null);
              }
        }


//output for Loan Payment Table
          if (amt >0) {
               amt = Double.parseDouble(loanField.getText());
               moIn = (intrst / 12) / 100;
               moTrm = trm * 12;
               paymt = amt * (moIn / (1 - java.lang.Math.pow((1 + moIn), (-moTrm))));

               paymtField.setText("" + currency.format(paymt));

               opField.append("Payment#");
               opField.append("            ");
               opField.append("Payment Amount");
               opField.append("           ");
               opField.append("Interest");
               opField.append("           ");
               opField.append("Principle Reduction");
               opField.append("           ");
               opField.append("Remaining Balance");
               opField.append("      \n");




               for (int i = 1; i <= moTrm; i++) {
                double newIn = moIn * amt;
                double reduct = paymt - newIn;
                newPrin = amt - reduct;
                amt = newPrin;



                    opField.append("    " + i);
                    opField.append("                         " + currency.format(paymt));
                    opField.append("                      " + currency.format(newIn));
                    opField.append("                    " + currency.format(reduct));
                    opField.append("                    " + currency.format(newPrin) + "\n");




                      if((amt <= 0 || trm <= 0 || intrst <= 0) && (Exception == false))
                      {
               JOptionPane.showMessageDialog(null, "Please Enter Positive Numbers Only.",
                         "Message Dialog", JOptionPane.PLAIN_MESSAGE);
               if(amt <= 0)
               loanField.setText(null);
          }}}
        }


// resets GUI for another calculation
 void reset () {

          loanField.setText(null);
          paymtField.setText(null);
                              opField.setText(null);
                              termField.setText(null);
                              int_entryField.setText(null);
     }

// ends GUI and exits program
void end() {
          System.exit(0);
}


//main method to close program
public static void main(String args[]) {
          GUIMortgageCalculator43 d1= new GUIMortgageCalculator43();
          d1.show();
            }
  }
Avatar of Mick Barry
Mick Barry
Flag of Australia image

just means your using methods that *may* disappear in the future, but still work.
Shouldn't be causing a problem, its just a warning.

ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial