Thanks that thread helped and my JButtons are functional accept for my compute button. I'm trying to call the calculateScores()-method in the my Judging class so it will total all the scores minus the min and max. Both classes are below. Please Help as this has been very frustrating pinpointing my error. Everything compiles it just doesn't run correctly.
GUI class:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class GUI extends JFrame implements ActionListener
{
private final int FRAME_WIDTH = 775;
private final int FRAME_HEIGHT = 300;
private final int X_ORIGIN = 100;
private final int Y_ORIGIN = 400;
private JTextField [] judges=new JTextField[8];
private JLabel [] labels;
JButton btnReset, btnCompute;
private String coName;
private JTextField contestant, scr;
private JLabel label;
double score_a, scores[], sc1;
Judging judging=new Judging(8, "contestant");
public GUI()
{
super("Judging");
setLayout(new FlowLayout());
setSize(FRAME_WIDTH,FRAME_HEIGHT);
setLocation(X_ORIGIN,Y_ORIGIN);
label = new JLabel("Name of Contestant", JLabel.CENTER);
contestant = new JTextField(18);
contestant.setEditable(true);
contestant.setBackground(Color.white);
add(label);
add(contestant);
JLabel [] labels = new JLabel[8];
for(int i = 0;i < judges.length;i++)
{
labels[i] = new JLabel("judge" +(i+1), JLabel.LEFT);
judges[i] = new JTextField(3);
labels[i].setVerticalAlignment(JLabel.TOP);
judges[i].setBackground(Color.white);
judges[i].setForeground(Color.black);
judges[i].addActionListener(this);
judges[i].setEditable(true);
add(labels[i]);
add(judges[i]);
}
btnCompute = new JButton("Compute Score");
btnCompute.setBackground(Color.black);
btnCompute.setForeground(Color.white);
btnCompute.addActionListener(this);
add(btnCompute);
label = new JLabel("Contestant's Score", JLabel.LEFT);
label.setVerticalAlignment(JLabel.TOP);
scr = new JTextField(10);
scr.setEditable(false);
scr.setBackground(Color.white);
add(scr);
add(label);
label = new JLabel("Reset Scores for Next Contestant", JLabel.LEFT);
btnReset = new JButton("Reset");
btnReset.setBackground(Color.gray);
btnReset.setForeground(Color.red);
btnReset.addActionListener(this);
add(btnReset);
}
public void setScores(double [] scores)
{
this.scores = scores;
}
public double [] getScores()
{
return scores;
}
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
double total= judging.calculateScore();
if (source == btnCompute)
{
for (int i = 0; i < judges.length; ++i)
{
judges[i].setEditable(true);
}
}
else if (source == btnReset)
{
for (int i = 0; i < judges.length; ++i)
{
judges[i].setText("");
}
contestant.setText("");
for (int i = 0; i < judges.length; ++i)
{
judges[i].setEditable(true);
}
contestant.setEditable(true);
}
}
}
Judging Class
import java.util.*;
public class Judging
{
private double [] scores;
private double total;
private int n;
private String contestant;
public Judging(int n, String contestant)
{
this.n = n;
this.contestant = contestant;
scores = new double[n];
total = 0;
}
public void getData(Scanner console)
{
boolean ok;
if (n > scores.length)
{
System.out.println("The size of the array does not equal the "+
"scores asked for");
System.exit(0);
}
for(int i=0;i<n;i++)
{
do
{
System.out.print("Enter the score for the judge number "+(i+1)+": ");
scores [i]= console.nextDouble();
if (scores[i] < 1 || scores[i] > 10)
System.out.println("Sorry! The score must be between 1 and 10");
}
while (scores[i] < 1 || scores[i] > 10);
}
console.nextLine();
}
public double calculateScore()
{
int largest, smallest;
if (n > scores.length)
{
System.out.println("The size of the array does not equal the "+
"scores asked for");
System.exit(0);
}
if (n < 3)
{
System.out.println("There must be at least 3 scores");
return 0;
}
largest = findMax();
smallest = findMin();
total = 0;
for(int i = 0; i < n; ++i)
total += scores[i];
total -= (scores[smallest] + scores[largest]);
return total;
}
public double getTotal()
{
return total;
}
public double [] getScores()
{
return scores;
}
public String getContestant()
{
return contestant;
}
public void setContestant(String newContestant)
{
contestant = newContestant;
}
public void setScores(double [] scores)
{
this.scores = scores;
}
private int findMin()
{
if (n <= 0 || n > scores.length)
{
System.out.println("You have sent the wrong"+
" value for the number of elements in the array for"+
" findMin. -1 is being returned");
return - 1;
}
if (n < 0 || 0 > scores.length)
{
System.out.println("You have sent the "+
"wrong value for the starting element to search in "+
"the array for findMin. -1 is being returned");
return - 1;
}
int minIndex = 0;
double minValue = scores[0];
for(int i = 0 +1; i < n; ++i)
if (scores[i] < minValue)
{
minValue = scores[i];
minIndex = i;
}
return minIndex;
}
private int findMax()
{
if (n <= 0 || n > scores.length)
{
System.out.println("You have sent the wrong"+
" value for the number of elements in the array for"+
" findMax. -1 is being returned");
return - 1;
}
if (n < 0 || n > scores.length)
{
System.out.println("You have sent the "+
"wrong value for the starting element to search in "+
"the array for findMax. -1 is being returned");
return - 1;
}
int maxIndex = n-1;
double maxValue = scores[n-1];
for(int i = n-1; i > 0; --i)
if (scores[i] > maxValue)
{
maxValue = scores[i];
maxIndex = i;
}
return maxIndex;
}
}