I'm getting errors, and I'm not sure why. Any help would be appreciated. I'm working on this program and when I put the ActionListener for the comboBox it blows up. I chose a topic from the comboBox that will pick a file to be read. When I comment out lines 127 to 130 it runs.
Any help is appreciated.
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.util.*;
public class Test extends JFrame {
public static final int WIDTH = 640;
public static final int HEIGHT = 500;
JPanel upper;
JPanel middle;
JPanel lower;
JTextArea questionArea;
JTextArea choicesArea[];
JTextArea choiceFields[];
JTextArea outputArea;
JButton choiceButtons[];
JButton nextButton;
final String[] typeOfTestPath = { "java.txt", "algebra.txt" };
final String[] typeOfTestList = { "Java", "Albegra" };
JComboBox typeOfTestBox;
final int NUM_OF_BUTTONS = 4;
String buttonLabels[] = { "A", "B", "C", "D" };
int typeOfTest;
// Multiple choice variables
int numCurrentQuestion;
int numQuestions;
int score;
int maxScore;
boolean questionAnswered;
ShuffleVector questionList;
String testChoice;
// parser variables
Question q;
Answer a;
int value;
boolean shuffleAnswers;
int mode;
final int GLOBAL_MODE = 0;
final int QUESTION_MODE = 1;
final int ANSWER_MODE = 2;
Vector<String> fileDescriptions;
Vector<String> fileNames;
public Test() {
setSize(WIDTH, HEIGHT);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
int i;
getContentPane().setLayout(new BorderLayout());
getContentPane().add(upper = new JPanel(), BorderLayout.NORTH);
getContentPane().add(middle = new JPanel(), BorderLayout.CENTER);
upper.setLayout(new GridBagLayout());
upper.setLayout(new GridBagLayout());
upper.setBackground(Color.green);
middle.setBackground(Color.green);
// uppper third of JFrame
// getFiles();
addComponent(upper, new JLabel("Select category: "), 0, 0);
addComponent(upper, typeOfTestBox = new JComboBox(), 0, 1);
addComponent(upper, questionArea = new JTextArea(4, 50), 1, 0, 3, 3);
questionArea.setLineWrap(true);
questionArea.setWrapStyleWord(true);
questionArea.setEditable(false);
for (i = 0; i < typeOfTestList.length; i++) {
typeOfTestBox.addItem(typeOfTestList[i]);
}
// middle third of JFrame
choiceButtons = new JButton[NUM_OF_BUTTONS];
choiceFields = new JTextArea[NUM_OF_BUTTONS];
for (i = 0; i < NUM_OF_BUTTONS; i++) {
addComponent(middle,
choiceButtons[i] = new JButton(buttonLabels[i]), i, 0);
addComponent(middle, choiceFields[i] = new JTextArea(2, 50), i, 1,
2, 1);
choiceFields[i].setLineWrap(true);
choiceFields[i].setWrapStyleWord(true);
choiceFields[i].setEditable(false);
}
// lower third of JFrame
getContentPane().add(outputArea = new JTextArea(8, 40),
BorderLayout.SOUTH);
getContentPane().add(lower = new JPanel(), BorderLayout.SOUTH);
addComponent(lower, nextButton = new JButton("Next Question >>"), 0, 2);
outputArea.setBackground(Color.green);
outputArea.setLineWrap(true);
outputArea.setWrapStyleWord(true);
// questionArea.setEditable(false);
// get the questions
//getQuestions("");
//displayQuestion();
}
private void addComponent(JPanel p, Component c, int row, int column,
int width, int height) {
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = column;
gbc.gridy = row;
gbc.gridheight = height;
gbc.gridwidth = width;
p.add(c, gbc);
}
private void addComponent(JPanel p, Component c, int row, int column) {
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = column;
gbc.gridy = row;
p.add(c, gbc);
typeOfTestBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int j = typeOfTestBox.getSelectedIndex();
typeOfTest = j;
}});
/*
if (typeOfTestPath[j].length() == 0 && j > 0) {
return;
}
//getQuestions(typeOfTestPath[typeOfTest]);
//displayQuestion();
}
});*/
}
public static void main(String[] args) {
Test gui = new Test();
gui.setVisible(true);
}
}