no return- problem with actionlistener
I'm trying to write a program that calculates tax for user inputted income and filing status. i've wrote everything so that the compiler proceeds without error, but upon running the program, nothing is returned. i'm thinking it is a problem with my action listener. help?
Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class Trying extends JFrame implements ActionListener {
BufferedReader input = new BufferedReader (new InputStreamReader (System.in));
public JPanel content;
public JLabel income;
public JTextField field;
public JLabel status;
public JButton calculate;
public JLabel result;
public JTextField amount;
public JComboBox box;
double i;
int s;
String tax;
public Trying(){
content = new JPanel();
content.setLayout(new FlowLayout());
income = new JLabel("Enter Income:");
content.add(income);
field = new JTextField(20);
content.add(field);
status = new JLabel("Choose a filing status");
content.add(status);
String[] filing = {"Married", "Single", "Married filing separately", "Qualifying Widow or Widower", "Head of Household"};
box = new JComboBox(filing);
content.add(box);
calculate = new JButton("Calculate Tax");
content.add(calculate);
result = new JLabel("Your tax is:");
content.add(result);
amount = new JTextField(20);
content.add(amount);
amount.setText(this.calculate(i));
calculate.addActionListener(this);
setContentPane(content);
pack();
setTitle("Income Tax Calculator");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
}
public double single(double i)
{
if (i <= 6000)
return(.1*i);
else if (i <= 27950)
return((.1*6000) + (.15*(i-6000)));
else if (i <= 67700)
return((.1*6000) + (.15*(27950-6000)) + (.27*(i-27950)));
else if (i <= 141250)
return((.1*6000) + (.15*(27950-6000)) + (.27*(67700-27950)) + (.3*(i-67700)));
else if (i <= 307050)
return((.1*6000) + (.15*(27950-6000)) + (.27*(67700-27950)) + (.3*(141250-67700)) + (.35*(i-141250)));
else
return((.1*6000) + (.15*(27950-6000)) + (.27*(67700-27950)) + (.3*(141250-67700)) + (.35*(307050-141250)) + (.386*(i-307050)));
}
public double married(double i)
{
if (i <= 12000)
return(.1*i);
else if (i <= 46700)
return((.1*12000) + (.15*(i-12000)));
else if (i <= 112850)
return((.1*12000) + (.15*(46700-12000)) + (.27*(i-47600)));
else if (i <= 171950)
return((.1*12000) + (.15*(46700-12000)) + (.27*(112850-46700)) + (.3*(i-112850)));
else if (i <=307050 )
return((.1*12000) + (.15*(46700-12000)) + (.27*(112850-46700)) + (.3*(171950-112850)) + (.35*(i-307050)));
else
return((.1*12000) + (.15*(46700-12000)) + (.27*(112850-46700)) + (.3*(171950-112850)) + (.35*(307050-171950)) + (.389*(i-307050)));
}
public double fileseparate(double i)
{
if (i <= 6000)
return(.1*i);
else if (i <= 23350)
return((.1*6000) + (.15*(i-6000)));
else if (i <= 56425)
return((.1*6000) + (.15*(23350-6000)) + (.27*(i-23350)));
else if (i <= 85975)
return((.1*6000) + (.15*(23350-6000)) + (.27*(67700-23350)) + (.3*(i-56425)));
else if (i <= 153525)
return((.1*6000) + (.15*(23350-6000)) + (.27*(56425-23350)) + (.3*(85975-56425)) + (.35*(i-85975)));
else
return((.1*6000) + (.15*(23350-6000)) + (.27*(56425-23350)) + (.3*(85975-56425)) + (.35*(153525-85975)) + (.386*(i-153525)));
}
public double household(double i)
{
if (i <= 10000)
return(.1*i);
else if (i <= 37450)
return((.1*10000) + (.15*(i-10000)));
else if (i <= 96700)
return((.1*10000) + (.15*(37450-10000)) + (.27*(i-37450)));
else if (i <= 156600)
return((.1*10000) + (.15*(37450-10000)) + (.27*(96700-37450)) + (.3*(i-96700)));
else if (i <= 307050)
return((.1*10000) + (.15*(37450-10000)) + (.27*(96700-37450)) + (.3*(156600-96700)) + (.35*(i-156600)));
else
return((.1*10000) + (.15*(37450-10000)) + (.27*(96700-37450)) + (.3*(156600-96700)) + (.35*(307050-156600)) + (.386*(i-307050)));
}
public void actionPerformed(ActionEvent evt){
if (evt.getSource()== calculate)
{String income = field.getText();
i=Double.parseDouble(income);};
if (evt.getSource()==calculate)
{int status = box.getSelectedIndex();
s=status;};
if (evt.getSource() == calculate)
this.calculate(i);
}
public String calculate(double i){
if(s == 0)
return Double.toString(this.single(i));
else if (s == 1)
return Double.toString(this.married(i));
else if (s == 2)
return Double.toString(this.fileseparate(i));
else if (s == 3)
return Double.toString(this.fileseparate(i));
else if (s == 4)
return Double.toString(this.household(i));
else
return ("Error");
}
public static void main(String args[]) {
Trying trying = new Trying();
trying.setVisible(true);
}
}