taxes.java
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class taxes{
public static void main(String argv[]) {
new Tax();
}
}
class Tax extends JFrame {
int compute(int wages, boolean married,
int children, boolean old, boolean blind,
boolean student, boolean citizen) {
double tax=0;
/********** incomplete pody ************/
return (int) tax;
}
JTextField name, address, ssn, married, children,
wages, old, blind, student, citizen, owe;
JPanel setFields(){
MyPanel panel = new MyPanel();
name = panel.add("name");
address = panel.add("address");
ssn =panel.add("social security number");
married = panel.add("check if married");
children =panel.add("number of children");
children.setHorizontalAlignment(JTextField.RIGHT);
wages =panel.add("income");
wages.setHorizontalAlignment(JTextField.RIGHT);
citizen =panel.add("check if US citizen");
old =panel.add("check if 65 or older");
blind =panel.add("check if blind");
student =panel.add("check if student");
owe = panel.add("amount you owe");
owe.setHorizontalAlignment(JTextField.RIGHT);
return panel;
}
Tax() {
super("Mini Bini Tax Form");
Quit wa = new Quit();
addWindowListener( wa );
Container c = getContentPane();
JPanel fields = setFields();
c.add(fields, BorderLayout.CENTER);
JPanel compute = new JPanel();
JButton b = new JButton("compute tax");
compute.add(b);
TaxListener listener = new TaxListener(this);
b.addActionListener(listener);
c.add(compute, BorderLayout.SOUTH);
pack();
setVisible(true);
}
void compute(){
int tax =
compute(
Integer.parseInt( wages.getText() ),
! "".equals( married.getText() ),
Integer.parseInt( children.getText() ),
! "".equals( old.getText() ),
! "".equals( blind.getText() ),
! "".equals( student.getText() ),
! "".equals( citizen.getText() )
);
owe.setText( "" + tax );
}
}
class MyPanel extends JPanel {
GridBagLayout gridbag;
static int i=0;
MyPanel() {
gridbag = new GridBagLayout();
this.setLayout(gridbag);
}
JTextField add(String s ){
GridBagConstraints c = new GridBagConstraints();
c.weightx = 0;
c.anchor = GridBagConstraints.WEST;
i++;
JLabel uidLabel = new JLabel(((i<10)? " ":"") + i + " "+s);
this.add(uidLabel);
gridbag.setConstraints(uidLabel, c);
c.weightx = 1;
c.gridwidth = GridBagConstraints.REMAINDER;
c.fill = GridBagConstraints.HORIZONTAL;
JTextField tf = new JTextField(10);
super.add(tf);
gridbag.setConstraints(tf, c);
return tf;
}
}
class TaxListener implements ActionListener {
Tax form;
TaxListener( Tax form ){ this.form = form; }
public void actionPerformed(ActionEvent e) {
form.compute();
}
}
class Quit extends WindowAdapter {
public void windowClosing(WindowEvent e) {
System.exit(0);
} }