-3

So I'm just new at java and gui and we have this project to make a java program that will compute for a certain thing with GUI. I'm having this error "Error not a statement in java" can some body help me? And is it possible lessen the space at the textfield to make it more elegant? Here's my code:

public class PHYSL_PROJ implements ActionListener
{
    private JFrame f;
    private JPanel p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13;
    private JLabel MASS_OF_CALORIMETER, MASS_OF_STIRRER, SPECIFIC_HEAT_OF_CALORIMETER, SPECIFIC_HEAT_OF_STIRRER, MASS_OF_CALORIMETER_AND_WATER, MASS_OF_WATER, INITIAL_TEMP_OF_WATER_CALORIMETER_AND_STIRRER, EQUILIBRIUM_TEMP, MASS_OF_WATER_CALORIMETER_AND_STEAM, MASS_OF_STEAM, COMPUTED_VALUE_OF_HEAT_OF_VAPORIZATION_OF_WATER, ACCEPTED_VALUE_OF_HEAT_OF_VAPORIZATION_OF_WATER, PERCENT_ERROR;
    private JButton COMPUTE, RESET;
    private JTextField MASS_OF_CALORIMETER_t, MASS_OF_STIRRER_t, SPECIFIC_HEAT_OF_CALORIMETER_t, SPECIFIC_HEAT_OF_STIRRER_t, MASS_OF_CALORIMETER_AND_WATER_t, MASS_OF_WATER_t, INITIAL_TEMP_OF_WATER_CALORIMETER_AND_STIRRER_t, EQUILIBRIUM_TEMP_t, MASS_OF_WATER_CALORIMETER_AND_STEAM_t, MASS_OF_STEAM_t, COMPUTED_VALUE_OF_HEAT_OF_VAPORIZATION_OF_WATER_t, ACCEPTED_VALUE_OF_HEAT_OF_VAPORIZATION_OF_WATER_t, PERCENT_ERROR_t;

    public PHYSL_PROJ()
    {
        f = new JFrame("Heat of Fusion Calculator");

        p0 = new JPanel();
        p1 = new JPanel();
        p2 = new JPanel();
        p3 = new JPanel();
        p4 = new JPanel();
        p5 = new JPanel();
        p6 = new JPanel();
        p7 = new JPanel();
        p8 = new JPanel();
        p9 = new JPanel();
        p10 = new JPanel();
        p11 = new JPanel();
        p12 = new JPanel();
        p13 = new JPanel();

        MASS_OF_CALORIMETER = new JLabel("Mass of calorimeter");
        MASS_OF_STIRRER = new JLabel("Mass of stirrer");
        SPECIFIC_HEAT_OF_CALORIMETER = new JLabel("Specific Heat of Calorimeter");
        SPECIFIC_HEAT_OF_STIRRER = new JLabel("Specific Heat of Stirrer");
        MASS_OF_CALORIMETER_AND_WATER = new JLabel("Mass of calorimeter and water");
        MASS_OF_WATER = new JLabel("Mass of water (Mw)");
        INITIAL_TEMP_OF_WATER_CALORIMETER_AND_STIRRER = new JLabel("Initial temperature of water, calorimeter and stirrer (T0)");
        EQUILIBRIUM_TEMP = new JLabel("Equilibrium temperature (Tf)");
        MASS_OF_WATER_CALORIMETER_AND_STEAM = new JLabel("Mass of water, calorimeter and condensed steam");
        MASS_OF_STEAM = new JLabel("Mass of steam (Mx)");
        COMPUTED_VALUE_OF_HEAT_OF_VAPORIZATION_OF_WATER = new JLabel("Computed value of heat of vaporization of water (Lv)");
        ACCEPTED_VALUE_OF_HEAT_OF_VAPORIZATION_OF_WATER = new JLabel("Accepted value of heat of vaporization of water (Lv)");
        PERCENT_ERROR =new JLabel("Percent error");

        MASS_OF_CALORIMETER_t = new JTextField("0.0", 5);
        MASS_OF_STIRRER_t = new JTextField("0.0", 5);
        SPECIFIC_HEAT_OF_CALORIMETER_t = new JTextField("0.430", 5);
        SPECIFIC_HEAT_OF_CALORIMETER_t.setEditable(false);
        SPECIFIC_HEAT_OF_STIRRER_t = new JTextField("0.118", 5);
        SPECIFIC_HEAT_OF_STIRRER_t.setEditable(false);
        MASS_OF_CALORIMETER_AND_WATER_t = new JTextField("0.0", 5);
        MASS_OF_WATER_t = new JTextField("0.0", 5);
        MASS_OF_WATER_t.setEditable(false);
        INITIAL_TEMP_OF_WATER_CALORIMETER_AND_STIRRER_t = new JTextField("0.0", 5);
        EQUILIBRIUM_TEMP_t = new JTextField("0.0", 5);
        MASS_OF_WATER_CALORIMETER_AND_STEAM_t = new JTextField("0.0", 5);
        MASS_OF_STEAM_t = new JTextField("0.0", 5);
        MASS_OF_STEAM_t.setEditable(false);
        COMPUTED_VALUE_OF_HEAT_OF_VAPORIZATION_OF_WATER_t = new JTextField("0.0", 5);
        COMPUTED_VALUE_OF_HEAT_OF_VAPORIZATION_OF_WATER_t.setEditable(false);
        ACCEPTED_VALUE_OF_HEAT_OF_VAPORIZATION_OF_WATER_t = new JTextField("540", 5);
        ACCEPTED_VALUE_OF_HEAT_OF_VAPORIZATION_OF_WATER_t.setEditable(false);
        PERCENT_ERROR_t = new JTextField("0.0%", 5);
        PERCENT_ERROR_t.setEditable(false);

        COMPUTE = new JButton("Compute");
        RESET = new JButton("Reset");
    }

    public void launchFrame()
    {
        p0.setLayout(new GridLayout(1,2));
        p1.setLayout(new GridLayout(1,2));
        p2.setLayout(new GridLayout(1,2));
        p3.setLayout(new GridLayout(1,2));
        p4.setLayout(new GridLayout(1,2));
        p5.setLayout(new GridLayout(1,2));
        p6.setLayout(new GridLayout(1,2));
        p7.setLayout(new GridLayout(1,2));
        p8.setLayout(new GridLayout(1,2));
        p9.setLayout(new GridLayout(1,2));
        p10.setLayout(new GridLayout(1,2));
        p11.setLayout(new GridLayout(1,2));
        p12.setLayout(new GridLayout(1,2));
        p13.setLayout(new GridLayout(1,2));

        p0.add(MASS_OF_CALORIMETER);
        p0.add(MASS_OF_CALORIMETER_t);
        p1.add(MASS_OF_STIRRER);
        p1.add(MASS_OF_STIRRER_t);
        p2.add(SPECIFIC_HEAT_OF_CALORIMETER);
        p2.add(SPECIFIC_HEAT_OF_CALORIMETER_t);
        p3.add(SPECIFIC_HEAT_OF_STIRRER);
        p3.add(SPECIFIC_HEAT_OF_STIRRER_t);
        p4.add(MASS_OF_CALORIMETER_AND_WATER);
        p4.add(MASS_OF_CALORIMETER_AND_WATER_t);
        p5.add(MASS_OF_WATER);
        p5.add(MASS_OF_WATER_t);
        p6.add(INITIAL_TEMP_OF_WATER_CALORIMETER_AND_STIRRER);
        p6.add(INITIAL_TEMP_OF_WATER_CALORIMETER_AND_STIRRER_t);
        p7.add(EQUILIBRIUM_TEMP);
        p7.add(EQUILIBRIUM_TEMP_t);
        p8.add(MASS_OF_WATER_CALORIMETER_AND_STEAM);
        p8.add(MASS_OF_WATER_CALORIMETER_AND_STEAM_t);
        p9.add(MASS_OF_STEAM);
        p9.add(MASS_OF_STEAM_t);
        p10.add(COMPUTED_VALUE_OF_HEAT_OF_VAPORIZATION_OF_WATER);
        p10.add(COMPUTED_VALUE_OF_HEAT_OF_VAPORIZATION_OF_WATER_t);
        p11.add(ACCEPTED_VALUE_OF_HEAT_OF_VAPORIZATION_OF_WATER);
        p11.add(ACCEPTED_VALUE_OF_HEAT_OF_VAPORIZATION_OF_WATER_t);
        p12.add(PERCENT_ERROR);
        p12.add(PERCENT_ERROR_t);
        p13.add(COMPUTE);
        p13.add(RESET);

        f.setLayout(new GridLayout(14,2));
        f.add(p0);
        f.add(p1);
        f.add(p2);
        f.add(p3);
        f.add(p4);
        f.add(p5);
        f.add(p6);
        f.add(p7);
        f.add(p8);
        f.add(p9);
        f.add(p10);
        f.add(p11);
        f.add(p12);
        f.add(p13);
        f.pack();
        f.setVisible(true);
        COMPUTE.addActionListener(this);
        RESET.addActionListener(this);
        f.addWindowListener(new MyCloseEventHandler()); 
    }

    public void actionPerformed(ActionEvent ae)
    {
        Object source = ae.getSource();
        double mass_of_calorimeter, mass_of_stirrer, specific_heat_of_calorimeter = 0.430, specific_heat_of_stirrer = 0.118, mass_of_calorimeter_and_water, mass_of_water = 0.0, initial_temp_of_water_calorimeter_and_stirrer, equilibrium_temp, mass_of_water_calorimeter_and_steam, mass_of_steam = 0.0, computed_value_of_heat_of_vaporization_of_water = 0.0, accepted_value_of_heat_of_vaporization_of_water = 540, heat_of_vaporization_percent_error = 0.0;

        if (MASS_OF_CALORIMETER_t.getText() != null && MASS_OF_STIRRER_t.getText() != null && SPECIFIC_HEAT_OF_CALORIMETER_t.getText() != null && SPECIFIC_HEAT_OF_STIRRER_t.getText() != null && MASS_OF_CALORIMETER_AND_WATER_t.getText() != null && MASS_OF_WATER_t.getText() != null && INITIAL_TEMP_OF_WATER_CALORIMETER_AND_STIRRER_t.getText() != null && EQUILIBRIUM_TEMP_t.getText() != null && MASS_OF_WATER_CALORIMETER_AND_STEAM_t.getText() != null && MASS_OF_STEAM_t.getText() != null && COMPUTED_VALUE_OF_HEAT_OF_VAPORIZATION_OF_WATER_t.getText() != null && ACCEPTED_VALUE_OF_HEAT_OF_VAPORIZATION_OF_WATER_t.getText() != null && PERCENT_ERROR_t.getText() != null)
        {
            mass_of_calorimeter = Double.parseDouble(MASS_OF_CALORIMETER_t.getText());
            mass_of_stirrer = Double.parseDouble(MASS_OF_STIRRER_t.getText());
            mass_of_calorimeter_and_water = Double.parseDouble(MASS_OF_CALORIMETER_AND_WATER_t.getText());
            initial_temp_of_water_calorimeter_and_stirrer = Double.parseDouble(INITIAL_TEMP_OF_WATER_CALORIMETER_AND_STIRRER_t.getText());
            equilibrium_temp = Double.parseDouble(EQUILIBRIUM_TEMP_t.getText());
            mass_of_water_calorimeter_and_steam = Double.parseDouble(MASS_OF_WATER_CALORIMETER_AND_STEAM_t.getText());

            if (source == COMPUTE)
            {
                mass_of_water = mass_of_calorimeter_and_water - mass_of_calorimeter;
                mass_of_steam = mass_of_water_calorimeter_and_steam - (mass_of_water - mass_of_calorimeter);
                computed_value_of_heat_of_vaporization_of_water = (((mass_of_water(1) + mass_of_calorimeter(0.430) + mass_of_stirrer(0.118))(equilibrium_temp - initial_temp_of_water_calorimeter_and_stirrer)) + ((mass_of_steam(1)(equilibrium_temp - 100))))/mass_of_steam;
                heat_of_vaporization_percent_error = ((accepted_value_of_heat_of_vaporization_of_water - computed_value_of_heat_of_vaporization_of_water)/accepted_value_of_heat_of_vaporization_of_water)*100;
            }
            else if (source == RESET)
            {
                MASS_OF_CALORIMETER_t.setText ("0.0");
                MASS_OF_STIRRER_t.setText ("0.0");
                SPECIFIC_HEAT_OF_CALORIMETER_t.setText ("0.430");
                SPECIFIC_HEAT_OF_STIRRER_t.setText ("0.118");
                MASS_OF_CALORIMETER_AND_WATER_t.setText ("0.0");
                MASS_OF_WATER_t.setText ("0.0");
                INITIAL_TEMP_OF_WATER_CALORIMETER_AND_STIRRER_t.setText ("0.0");
                EQUILIBRIUM_TEMP_t.setText ("0.0");
                MASS_OF_WATER_CALORIMETER_AND_STEAM_t.setText ("0.0");
                MASS_OF_STEAM_t.setText ("0.0");
                COMPUTED_VALUE_OF_HEAT_OF_VAPORIZATION_OF_WATER_t.setText ("0.0");
                ACCEPTED_VALUE_OF_HEAT_OF_VAPORIZATION_OF_WATER_t.setText ("540");
                PERCENT_ERROR_t.setText ("0.0");
            }
            else {}
                MASS_OF_WATER_t.setText("" + mass_of_water);
                MASS_OF_STEAM_t.setText("" + mass_of_steam);
                COMPUTED_VALUE_OF_HEAT_OF_VAPORIZATION_OF_WATER_t.setText("" + computed_value_of_heat_of_vaporization_of_water);
                ACCEPTED_VALUE_OF_HEAT_OF_VAPORIZATION_OF_WATER_t.setText("" + accepted_value_of_heat_of_vaporization_of_water);
                PERCENT_ERROR_t.setText("" + heat_of_vaporization_percent_error);
        }       
    }       

    private class MyCloseEventHandler extends WindowAdapter
    {
        public void windowClosing(WindowEvent ae)
        {
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }
    }

    public static void main(String args[])
    {
        PHYSL_PROJ sc = new PHYSL_PROJ();
        sc.launchFrame();
    }
}
mKorbel
  • 109,525
  • 20
  • 134
  • 319
Dex
  • 19
  • 3
  • What line is giving this error? That would surely be helpful, don't you think? – Kon Nov 10 '14 at 15:46
  • You do NOT need all those JPanels. Bad design right off the bat. – duffymo Nov 10 '14 at 15:46
  • 2
    This fragment smells: `else {}` – Frank van Puffelen Nov 10 '14 at 15:47
  • 1
    You remind me of soon-to-be ex-girlfriends when they say "we have a problem". Of course you want to say "what is the problem". Come on, be an angel, give us the line number. – Bathsheba Nov 10 '14 at 15:47
  • The line `computed_value_of_heat_of_vaporization_of_water = (((mass_of_water(1) + mass_of_calorimeter(0.430) + mass_of_stirrer(0.118))(equilibrium_temp - initial_temp_of_water_calorimeter_and_stirrer)) + ((mass_of_steam(1)(equilibrium_temp - 100))))/mass_of_steam;` says that the left-hand side must be a variable – BullyWiiPlaza Nov 10 '14 at 15:49

1 Answers1

3

What is the type of this variable?

MASS_OF_CALORIMETER = new JLabel("Mass of calorimeter");

(Hint: it doesn't have one as written.)

Should look like this:

JLabel MASS_OF_CALORIMETER = new JLabel("Mass of calorimeter");

This is a terrible idea. You don't need all those JPanels. One will do to hold all your labels and text boxes.

Learn and follow the Sun Java coding standards. All caps for static final class members. Class and variable names are camel case; class names start with capital letter; variables start with lower case. It'll make your code easier for other developers to read.

Develop a consistent style for brace placement, etc.

The single most important rule for software development is DRY: Don't Repeat Yourself. You'll go a long way following that.

duffymo
  • 305,152
  • 44
  • 369
  • 561