This discussion is archived
1 Reply Latest reply: Aug 4, 2011 7:55 AM by morgalr RSS

what should i add to my project

880153 Newbie
Currently Being Moderated
import javax.swing.*;

import java.awt.*;
import java.awt.event.*;

public class TestBudgetCalculator extends BudgetCalculator implements ActionListener {
               private JButton jbSetMonthlySalary= new JButton("Set");
               private JLabel jlabelSalary = new JLabel("Monthly Salary");
               private JLabel jlabellimits = new JLabel("Spending Limits");
               private JLabel jlabelmyFood = new JLabel("Food");
               private JLabel jlabelmyEntertainment = new JLabel("Entertainment");
               private JLabel jlabelmyMisc = new JLabel("Misc");
               private JLabel jlabelmySavings = new JLabel("Savings");
               private JTextField jtextMonthlySalary = new JTextField("");
               private JTextField jtextmyFood = new JTextField("");
               private JTextField jtextmyEntertainment = new JTextField("");
               private JTextField jtextmyMisc = new JTextField("");
               private JTextField jtextmySavings = new JTextField("");

               public TestBudgetCalculator(){
                    BorderLayout b = new BorderLayout();
                    setLayout(b) ;

                    JPanel p = new JPanel();
                    JPanel p1 = new JPanel();
                    JPanel p2 = new JPanel();
                    JPanel p3 = new JPanel();
                    
                    p1.setLayout(new GridLayout(1,2));
                    p2.setLayout(new GridLayout(4,1));
                    p3.setLayout(new GridLayout(1,2));
                    
                    p1.add(jlabelSalary);
                    p1.add(jlabellimits);
                    
                    p2.add(jlabelmyFood);
                    p2.add(jtextmyFood);
                    p2.add(jlabelmyEntertainment);
                    p2.add(jtextmyEntertainment);
                    p2.add(jlabelmyMisc);
                    p2.add(jtextmyMisc);
                    p2.add(jlabelmySavings);
                    p2.add(jtextmySavings );
                    
                    p3.add(jtextMonthlySalary);
                    p3.add(jbSetMonthlySalary);
                    p3.add(p2);
                    
          
                    
                    add(p1, BorderLayout.NORTH);
                    add(p3, BorderLayout.CENTER);
                    
                    jbSetMonthlySalary.addActionListener(this);
               }
                    public static void main(String[] args){
                         TestBudgetCalculator frame = new TestBudgetCalculator();
                         frame.setTitle("BudgetCalculator");
                         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                         frame.setSize(300,300);
                         frame.setVisible(true);
                         
                         
                    }
                    
                    public void actionPerformed(ActionEvent e) {
                         if (e.getSource()==jbSetMonthlySalary){
                         double MSalary = Double.parseDouble(jtextMonthlySalary.getText());
                         BudgetCalculator setmysalary = new BudgetCalculator();
                         setmysalary.setsalary(MSalary);
                         setmysalary.food(MSalary);
                         BudgetCalculator salary = new BudgetCalculator();
                    
                         }
                    
                         
                    }
                    
there is still one more class file that i haven't added here.this is the test class. im suppose to input my salary to calculate food,entertainment,misc and savings. what codes should i add? to make the calculation?

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points