Need help with array list jpanel question!!! Plz help!!!
I wrote a program that takes a users input and posts the variables back to them. I got everything working except getting the data to post the array back on the screen. what am i doing wrong?
Code:
/**
* This java program will take either allow a user to input some questions wth solutions attached.
* The program can also allow a user to query the database and see the questions in the database along with the answers attached.
*
* @Mr. Willie Rainwater, Andre' R. Seals, & Elvino Taylor
* @December 4th, 2009
*/
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.io.File;
import javax.swing.border.*;
import java.util.ArrayList;
import java.util.Arrays;
public class AnswerBot extends JFrame
{
private JFrame botFrame;
JButton exitButton, okButton, queryButton;
ArrayList<String> questionArray = new ArrayList<String>();
ArrayList<String> solutionArray = new ArrayList<String>();
JTextField Q = new JTextField (60);
JTextField S = new JTextField (60);
ArrayList<String> pairArray = new ArrayList<String>();
JPanel viewPane=new JPanel();
/**
* Constructor for objects of class AnswerBot
*/
public AnswerBot()
{
botFrame = new JFrame("IT Answerbot");
makeFrame();
//instantiating listener object
ButtonListener bListener = new ButtonListener();
exitButton.addActionListener(bListener);
okButton.addActionListener(bListener);
}
private void makeFrame()
{
// main container
Container mainContainer = botFrame.getContentPane( );
mainContainer.setLayout(new BorderLayout());
// center containter to hold Capture and Display Panel
JPanel centerContainer = new JPanel ();
centerContainer.setLayout(new BorderLayout());
// put the exit button in the south
//mainContainer.add(new JButton("Exit"), BorderLayout.SOUTH);
// Capture Panel with BorderLayout
JPanel capturePane= new JPanel();
capturePane.setLayout(new BorderLayout());
//set the border with a title
capturePane.setBorder(new TitledBorder(new EtchedBorder(), "Bot Pane"));
// make a top panel to hold name, surname, and occupation with GridLayout
JPanel topPane = new JPanel();
topPane.setLayout(new GridLayout(3,1));
// make three panels with FlowLayout
JPanel questionPane = new JPanel();
questionPane.setLayout(new FlowLayout(FlowLayout.LEFT));
JPanel solutionPane = new JPanel();
solutionPane.setLayout(new FlowLayout(FlowLayout.LEFT));
JPanel jobPane = new JPanel();
jobPane.setLayout(new FlowLayout(FlowLayout.LEFT));
//put the label "Question:" and textField into the name panel
questionPane.add(new JLabel("Question:"));
//questionPane.add(new JTextField("", 60));
questionPane.add(Q);
//put the label "Solution:" and textField into the surname panel
solutionPane.add(new JLabel("Solution:"));
//checkPane.add(new JTextField("", 60));
solutionPane.add(S);
//put the three panels into top panel
topPane.add(questionPane);
topPane.add(solutionPane);
//put the top panel into the Capture panel
capturePane.add(topPane, BorderLayout.NORTH);
// make a button panel for the Ok and Cancel buttons
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new FlowLayout());
okButton = new JButton("Ok");
exitButton = new JButton("Exit");
buttonPane.add(okButton);
buttonPane.add(exitButton);
//put the action button panel into Capture panel
capturePane.add(buttonPane, BorderLayout.SOUTH);
//put the Capture panel into center panel
centerContainer.add(capturePane, BorderLayout.CENTER);
// Display Panel with GridLayout
JPanel displayPane= new JPanel();
displayPane.setLayout(new FlowLayout());
//set the border with a title
displayPane.setBorder(new TitledBorder(new EtchedBorder(), "Query saved Question/Solutions Pane"));
capturePane.add(viewPane, BorderLayout.CENTER);
viewPane.setBorder(new TitledBorder(new EtchedBorder(), "View Query Question/Solution Pane"));
JPanel labelPane = new JPanel();
displayPane.setLayout(new FlowLayout());
JButton queryButton = new JButton("Query");
displayPane.add(queryButton);
// put 2 labels in the label panels
labelPane.add(new JLabel("Question: "));
labelPane.add(new JLabel("Solution: "));
//put the Display panel into center panel
centerContainer.add(displayPane, BorderLayout.SOUTH);
////put the center panel into main container to display
mainContainer.add(centerContainer, BorderLayout.CENTER);
botFrame.setSize(800,600);
botFrame.setVisible(true);
}
class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent buttonEvent)
{
if (buttonEvent.getSource() == okButton)
{
questionArray.add(Q.toString());
Q.setText(" ");
solutionArray.add(S.toString());
S.setText(" ");
}
//action to be performed when a helpTopics event
if (buttonEvent.getSource() == exitButton)
{
System.exit(0);
}
if (buttonEvent.getSource() == queryButton)
{
int i;
System.out.print("Your question is: ");
System.out.print(questionArray.get(Q));
}
}
}
}