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.VERTIC AL_SCROLLB AR_ALWAYS,
ScrollPaneConstants.HORIZO NTAL_SCROL LBAR_AS_NE EDED);
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.CENT ER);
FlowLayout flow = new FlowLayout(FlowLayout.LEFT );
Container pane = getContentPane();
pane.setLayout(flow);
setDefaultCloseOperation(W indowConst ants.EXIT_ ON_CLOSE);
setVisible(true);
//setting actionListeners for Fields and Buttons
loanField.addActionListene r(this);
termField.addActionListene r(this);
int_entryField.addActionLi stener(thi s);
options.addActionListener( this);
calButton.addActionListene r(this);
resetButton.addActionListe ner(this);
endButton.addActionListene r(this);
opt1.addActionListener(thi s);
opt2.addActionListener(thi s);
//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("In terest %");
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("Calcula te");
calButton.setBackground(Co lor.blue);
row_c.add(calButton);
resetButton.setText("Reset ");
resetButton.setBackground( Color.blue );
row_c.add(resetButton);
endButton.setText("End");
endButton.setBackground(Co lor.blue);
row_c.add(endButton);
pane.add(row_c);
//layout for section that shows the monthly payment amount
row_d.setLayout(flow);
paymtLabel.setText("Monthl y 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(t rue);
opField.setEditable(true);
row_f.add(scrollPane);
pane.add(row_f);
}
//adding actionEvents for Buttons
public void actionPerformed(ActionEven t 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(fals e);
int_entryField.setEnabled( false);
int_entryField.setEditable (false);
}
}
//formulas for monthly payment
void startCalculations() {
Thread thisThread = Thread.currentThread();
NumberFormat currency = NumberFormat.getCurrencyIn stance();
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(loanFie ld.getText ());
} catch (NumberFormatException e) {
JOptionPane.showMessageDia log(null, "Please Do Not Use Commas",
"Message Dialog", JOptionPane.PLAIN_MESSAGE) ;
loanField.setText(null);
}
if (opt2.isSelected())
{
if(options.getSelectedInde x() == 0)
{
trm=7;
intrst=5.35;
}
else if(options.getSelectedInde x() ==1)
{
trm=15;
intrst=5.5;
}
else
{
trm=30;
intrst=5.75;
}
}
else
{
try
{
trm = Double.parseDouble(termFie ld.getText ());
}
catch (NumberFormatException e)
{
JOptionPane.showMessageDia log(this," Enter amounts greater than zero","Please enter new amount",JOptionPane.ERROR_ MESSAGE);
Exception=true;
termField.setText(null);
}
try
{
intrst= Double.parseDouble(int_ent ryField.ge tText());
}
catch (NumberFormatException e)
{
JOptionPane.showMessageDia log(this," Enter amount greater than zero and with no % sign","Please enter new amount",JOptionPane.ERROR_ MESSAGE);
Exception=true;
int_entryField.setText(nul l);
}
}
//output for Loan Payment Table
if (amt >0) {
amt = Double.parseDouble(loanFie ld.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.showMessageDia log(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(nul l);
}
// 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();
}
}
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.VERTIC
ScrollPaneConstants.HORIZO
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.CENT
FlowLayout flow = new FlowLayout(FlowLayout.LEFT
Container pane = getContentPane();
pane.setLayout(flow);
setDefaultCloseOperation(W
setVisible(true);
//setting actionListeners for Fields and Buttons
loanField.addActionListene
termField.addActionListene
int_entryField.addActionLi
options.addActionListener(
calButton.addActionListene
resetButton.addActionListe
endButton.addActionListene
opt1.addActionListener(thi
opt2.addActionListener(thi
//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("In
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("Calcula
calButton.setBackground(Co
row_c.add(calButton);
resetButton.setText("Reset
resetButton.setBackground(
row_c.add(resetButton);
endButton.setText("End");
endButton.setBackground(Co
row_c.add(endButton);
pane.add(row_c);
//layout for section that shows the monthly payment amount
row_d.setLayout(flow);
paymtLabel.setText("Monthl
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(t
opField.setEditable(true);
row_f.add(scrollPane);
pane.add(row_f);
}
//adding actionEvents for Buttons
public void actionPerformed(ActionEven
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(
int_entryField.setEditable
}
if (source == opt2){
options.setEnabled(true);
termField.setEnabled(false
termField.setEditable(fals
int_entryField.setEnabled(
int_entryField.setEditable
}
}
//formulas for monthly payment
void startCalculations() {
Thread thisThread = Thread.currentThread();
NumberFormat currency = NumberFormat.getCurrencyIn
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(loanFie
} catch (NumberFormatException e) {
JOptionPane.showMessageDia
"Message Dialog", JOptionPane.PLAIN_MESSAGE)
loanField.setText(null);
}
if (opt2.isSelected())
{
if(options.getSelectedInde
{
trm=7;
intrst=5.35;
}
else if(options.getSelectedInde
{
trm=15;
intrst=5.5;
}
else
{
trm=30;
intrst=5.75;
}
}
else
{
try
{
trm = Double.parseDouble(termFie
}
catch (NumberFormatException e)
{
JOptionPane.showMessageDia
Exception=true;
termField.setText(null);
}
try
{
intrst= Double.parseDouble(int_ent
}
catch (NumberFormatException e)
{
JOptionPane.showMessageDia
Exception=true;
int_entryField.setText(nul
}
}
//output for Loan Payment Table
if (amt >0) {
amt = Double.parseDouble(loanFie
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.showMessageDia
"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(nul
}
// 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();
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
one more link:
http://javaboutique.internet.com/articles/ITJ/qanda/q23.html
http://javaboutique.internet.com/articles/ITJ/qanda/q23.html
Shouldn't be causing a problem, its just a warning.