|
Programmer
Join Date: Jan 2008
Posts: 53
Rep Power: 1 
|
Java Error Messages
I received an error. I have posted a pic of the errors that I am receiving. Can someone please have a look at this and show me what I am doing wrong? Here is the code and then the pic.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class StaffingProgram extends JFrame
{
private JLabel resultAL, resultBL, resultCL, outputAL, outputBL, outputCL;
private JTextField resultATF, resultBTF, resultCTF, outputATF, outputBTF, outputCTF;
private JButton calculateB, exitB;
private CalculateButtonHandler cbHandler;
private ExitButtonHandler ebHandler;
private static final int WIDTH = 900;
private static final int HEIGHT = 600;
public StaffingProgram()
{
resultAL = new JLabel("Please enter the number of employees presently on duty at location A: ",
SwingConstants.RIGHT);
resultBL = new JLabel("Please enter the number of employees presently on duty at location B: ",
SwingConstants.RIGHT);
resultCL = new JLabel("Please enter the number of employees presently on duty at location C: ",
SwingConstants.RIGHT);
outputAL = new JLabel("Number of employees under or over for location A: ",
SwingConstants.RIGHT);
outputBL = new JLabel("Number of employees under or over for location B: ",
SwingConstants.RIGHT);
outputCL = new JLabel("Number of employees under or over for location C: ",
SwingConstants.RIGHT);
resultATF = new JTextField(10);
resultBTF = new JTextField(10);
resultCTF = new JTextField(10);
outputATF = new JTextField(10);
outputBTF = new JTextField(10);
outputCTF = new JTextField(10);
calculateB = new JButton("Calculate");
cbHandler = new CalculateButtonHandler();
calculateB.addActionListener(cbHandler);
exitB = new JButton("Exit");
ebHandler = new ExitButtonHandler();
exitB.addActionListener(ebHandler);
setTitle("Staffing Level Calculations");
Container pane = getContentPane();
pane.setLayout(new GridLayout(7, 2));
pane.add(resultAL);
pane.add(resultATF);
pane.add(resultBL);
pane.add(resultBTF);
pane.add(resultCL);
pane.add(resultCTF);
pane.add(outputAL);
pane.add(outputATF);
pane.add(outputBL);
pane.add(outputBTF);
pane.add(outputCL);
pane.add(outputCTF);
pane.add(calculateB);
pane.add(exitB);
setSize(WIDTH, HEIGHT);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
private class CalculateButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
double resulta, resultb, resultc;
resulta = Double.parseDouble(resultATF.getText());
resultb = Double.parseDouble(resultBTF.getText());
resultc = Double.parseDouble(resultCTF.getText());
try
{
if (resulta > 5)
{resulta = resulta - 5;
outputATF.setText("You are overstaffed by " + resulta);}
if (resulta < 5)
{resulta = 5 - resulta;
outputATF.setText("You are understaffed by " + resulta);}
if (resulta == 5)
{outputATF.setText("Your staffing is sufficient");}
else
{
throw new TheException(); //calls
}
if (resultb > 8)
{resultb = resultb - 8;
outputBTF.setText("You are overstaffed by " + resultb);
if (resultb < 8)
resultb = 8 - resultb;
outputBTF.setText("You are understaffed by " + resultb);
if (resultb == 8)
outputBTF.setText("Your staffing is sufficient");
else
{
throw new TheException(); //calls
}
if (resultc > 10)
{resultc = resultc - 10;
outputCTF.setText("You are overstaffed by " + resultc);}
if (resultc < 10)
{resultc = 10 - resultc;
outputCTF.setText("You are understaffed by " + resultc);}
if (resultc == 10)
{outputCTF.setText("Your staffing is sufficient");}
else
{
throw new TheException(); //calls
}
}
}
catch (TheException e)
{
System.out.println("Illegal input caught, please enter a number");
}
System.out.println();
System.out.println("Program Ending!");
}
}
}
private class ExitButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
public static void main(String[] args) throws IOException
{
StaffingProgram rectObject = new StaffingProgram();
}
}
|