Hi guys, i am writing a GUI program that will take a tutor minutes and earings and create an average earnings. My problem is instead of it using what we type in the fields E.g 200 mins and 50 dollars earnt and displaying the average. It shows the default fields. Please see attached code
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Tutorhelp extends JFrame
{
private JPanel panel;
private JLabel TutorTimeLabel;
private JTextField timeField;
private JLabel TutorWageLabel;
private JTextField wageField;
private JTextArea textArea;
private JButton enterButton;
private JButton runReportsButton;
private JButton quitButton;
final int WINDOW_WIDTH = 500;
final int WINDOW_HEIGHT = 600;
double [] tutorMin = new double [2];
double [] tutorWage = new double [2];
public Tutorhelp()
{
setTitle("Tutor Earnings");
setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
buildPanel();
add(panel);
setVisible(true);
}
private void buildPanel()
{
TutorTimeLabel = new JLabel("Tutor Time");
timeField = new JTextField(10);
TutorWageLabel = new JLabel ("Tutor Earnings");
wageField = new JTextField(10);
textArea = new JTextArea(25,50);
enterButton = new JButton("Enter");
enterButton.addActionListener(new EnterButtonListener());
runReportsButton = new JButton("Run Reports");
runReportsButton.addActionListener(new runReportsButtonListener());
quitButton = new JButton("Quit");
quitButton.addActionListener(new quitButtonListener());
panel = new JPanel();
panel.add(TutorTimeLabel);
panel.add(timeField);
panel.add(TutorWageLabel);
panel.add(wageField);
panel.add(textArea);
panel.add(enterButton);
panel.add(runReportsButton);
panel.add(quitButton);
}
private class EnterButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
int count = 0;
double num1 = 0;
double num2 = 0;
double m = Double.parseDouble(timeField.getText());
double w = Double.parseDouble(wageField.getText());
num1 = m ;
num2 = w ;
if (num1 <=0)
{
JOptionPane.showMessageDialog(null, "Please enter a time larger than 0", "Error",
JOptionPane.ERROR_MESSAGE);
}else if (num1 > 240)
{
JOptionPane.showMessageDialog(null, "You have worked to man mintues this week", "Error",
JOptionPane.ERROR_MESSAGE);
}else{
}
for(double i = 0; i< 3; i++)
{
}
if(num2 < 0)
{
JOptionPane.showMessageDialog(null, "Please enter a wage", "Error",
JOptionPane.ERROR_MESSAGE);
}
for(int i = 0; i < 3; i++)
{
for(count = 1; count <=3; count++){
}
tutorMin[0] = m;
tutorWage[1] = w;
timeField.setText("");
wageField.setText("");
wageField.requestFocus();
timeField.requestFocus();
}
}
}
private class runReportsButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
double average = 0;
double num1 = 0.00;
double num2 = 0.00;
double totalMin = 0.0;
double totalEarnings = 0.0;
final double MIN_WAGE = 7.25;
double totalWage = 0.0;
String wage = "";
for (int i = 0; i < tutorMin.length; i++)
{
totalMin += i;
}
for (int j = 0; j < tutorWage.length; j++)
{
totalEarnings +=j;
}
for (int j = 0; j < tutorWage.length; j++)
{
totalWage +=j;
average = totalEarnings;
}
if (average > MIN_WAGE)
{
wage = "Above Minimum Wage";
}else if ((average < MIN_WAGE)&&(average > MIN_WAGE))
{
wage = "Equal to Minimum Wage";
}else if (average < MIN_WAGE)
{
wage = "Below Minimum Wage";
}
String a = "Total mintues are " +totalMin +"\n";
a+=("Average Earnings are:" + average + "\n");
a+=("Minimum wage is: " +wage + "\n");
textArea.setText(a);
}}
private class quitButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
public static void main (String[] args)
{
Tutorhelp th = new Tutorhelp();
}
}