I am new to Java and I am having trouble knowing if my array is populating when I click the enter button and printing out the data into the text area when I click the run reports button. When I put data in the text boxes the boxes are being reset for new data entry but when I press the run reports I get nothing. Any advice is greatly appreciated. Here is my code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Scanner;
public class TutorHelp extends JFrame
{
private JPanel panel; //reference to the panel
private JLabel TutorTimeLabel; //tutoring time label
private JTextField timeField; //tutoring time text field
private JLabel TutorWageLabel; //tutoring wage label
private JTextField wageField; //tutoring wage text field
private JTextArea textArea; // tutoring text area
private JButton enterButton; // Enter button
private JButton runReportsButton; // run reports button
private JButton quitButton; // quit button
final int WINDOW_WIDTH = 500; //window width
final int WINDOW_HEIGHT = 600; // window height
double [] tutorMin = new double [2];
double [] tutorWage = new double [2];
public TutorHelp()
{
setTitle("Tutor Earnings"); // Window title
setSize(WINDOW_WIDTH, WINDOW_HEIGHT);// Window size
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // SET DEFAULT CLOSE OPERATION
buildPanel(); //build the panel
add(panel); // add to the panel
setVisible(true); // makes the window visible
}
private void buildPanel()
{
TutorTimeLabel = new JLabel("Tutor Time"); //Tutoring label
timeField = new JTextField(10); // time text field
TutorWageLabel = new JLabel("Tutor Earnings"); // tutor wage label
wageField = new JTextField(10); //wage text field
textArea = new JTextArea(25,50); // window text area
enterButton = new JButton("Enter"); // create an enter button
enterButton.addActionListener(new EnterButtonListener()); // add a enter button action listener
runReportsButton = new JButton("Run Reports"); //create a run reports button
runReportsButton.addActionListener(new runReportsButtonListener()); // add a run reports action listener
quitButton = new JButton("Quit"); // create a quit button
quitButton.addActionListener(new quitButtonListener()); // add a quit button action listener
panel = new JPanel(); //create a panel
panel.add(TutorTimeLabel); // add tutor time label
panel.add(timeField); // add time field
panel.add(TutorWageLabel); // add tutor time label
panel.add(wageField); // add wage field
panel.add(textArea); // add text area
panel.add(enterButton); // add enter button
panel.add(runReportsButton); // add the run reports button
panel.add(quitButton); // add a quit button
}
private class EnterButtonListener implements ActionListener // enter button class listener
{
public void actionPerformed(ActionEvent e) // action event
{
int count = 0; // counter variable
double num1 = 0; // time array variable
double num2 =0; // wage array variable
double m = Double.parseDouble(timeField.getText()); // get input from the time text field
double w = Double.parseDouble(wageField.getText()); // get input from the wage text field
num1 = m ; // parse the input from the time field
num2 = w ; // parse the input from the wage field
if (num1 <= 0) // error check for tutor time
{
JOptionPane.showMessageDialog(null, "Please enter a time larger than 0", "Error", JOptionPane.ERROR_MESSAGE); // error message if you enter the wrong number
}else if (num1 > 240)
{
JOptionPane.showMessageDialog(null, "You have worked to many minutes this week", "Error", JOptionPane.ERROR_MESSAGE); // error if you work to many minutes
}else{
}
for(double i = 0; i< 3; i++) //loop for num1
{
}
if(num2 < 0)
{
JOptionPane.showMessageDialog(null, "Please enter a wage", "Error", JOptionPane.ERROR_MESSAGE); //error message for the wage field
}
for(int i = 0; i < 3; i++)
{
for(count = 1; count <=3; count++){ //counter for the enter button
}
tutorMin[0] = m;
tutorWage[1]= w;
timeField.setText("");
wageField.setText("");
wageField.requestFocus();
timeField.requestFocus();
}
}
}
private class runReportsButtonListener implements ActionListener // enter run reports class listener
{
public void actionPerformed(ActionEvent e)
{
double average = 0 ; // run reports variables
Double num1 = 0.0d;
Double num2 = 0.0d;
Double totalMin = 0.0d;
double totalEarnings = 0.0d;
final double MIN_WAGE = 7.25;
Double totalWage = 0.0d;
String wage = "";
for (int i = 0; i < tutorMin.length; i++) //loop to total the minutes
{
totalMin += i;
}
for (int j = 0; j < tutorWage.length; j++) //loop to total the earnings
{
totalEarnings += j;
}
for (int j = 0; j < tutorWage.length; j++) // loop to find average wage
{
totalWage += j;
average = totalEarnings / 60;
}
if (average > MIN_WAGE) // statement to find if above average wage
{
wage = "Above Minimum Wage";
}else if ((average < MIN_WAGE)&&(average > MIN_WAGE)) // statement to find if equal to average wage
{
wage = "Equal to Minimum Wage";
}else if (average < MIN_WAGE) // statement to find if below average wage
{
wage = "Below Minimum Wage";
}
textArea.append("Total minutes are: " +totalMin+"\n"); // prints out data
textArea.append("Average Earnings are: " +average+"\n");
textArea.append("Minimum wage is: " +wage+"\n" );
textArea.setText("");
}}
private class quitButtonListener implements ActionListener // quit button class listener
{
public void actionPerformed(ActionEvent e)
{
System.exit(0); // closes window
}
}
public static void main (String[] args) // the main
{
TutorHelp th = new TutorHelp();
}}