I have tried many things obviously not everything or it would work, but i need your help. i have run out of ideas on how to fix this. im programming a fishing database where users enter the data and over time it collects and shows them were the type of fish are at certain locations at certain months in the year. but the Search feature telling them there information isnt working. please help here is my code( please note this is my first time using this):
void createSearchTab ()
{
fishListSearch = createJList (fishArray);
locsListSearch = createJList (locationArray);
whenListSearch = new JList (monthArray);
westPanel.setLayout (new GridLayout (3, 2));
westPanel.add (new JLabel ("What fish do you want to Catch?"));
westPanel.add (new JScrollPane (fishListSearch));
westPanel.add (new JLabel ("Where did you catch it?"));
westPanel.add (new JScrollPane (locsListSearch));
westPanel.add (new JLabel ("What month is it?"));
westPanel.add (new JScrollPane (whenListSearch));
southPanel.setLayout (new FlowLayout ());
southPanel.add (searchData);
searchTab.add (titleOne, BorderLayout.PAGE_START);
searchTab.add (westPanel, BorderLayout.CENTER);
searchTab.add (southPanel, BorderLayout.SOUTH);
searchResults = new JPanel (new BorderLayout ());
searchResults.add (resultExit, BorderLayout.SOUTH);
resultExit.addActionListener (new ActionListener ()
{
public void actionPerformed (ActionEvent arg0)
{
tabbs.remove (searchResults);
}
}
);
searchData.addActionListener (new ActionListener ()
{
public void actionPerformed (ActionEvent arg0)
{
fish = fishArray.get (fishListSearch.getSelectedIndex ()).toString ();
month = monthArray [whenListSearch.getSelectedIndex ()];
location = locationArray.get (locsListSearch.getSelectionMode ()).toString ();
tabbs.addTab ("Search Results", searchResults);
while (catches.get (i) != null)
{
i = i + 1;
while (catches.get (i) != null)
{
i = i + 1;
while (catches.get (i) != null)
{
if (catches.get (i) == month)
{
if (catches.get (i - 1) == location)
{
if (catches.get (i - 2) == fish)
resultLabel.setText ("During the Month of " + catches.get (i) + " at " + catches.get (i - 1) + ", " + catches.get (i + 1) + " " + catches.get (i - 2) + " were caught.");
else
resultLabel.setText (catches.get (i + 1) + " " + catches.get (i - 2) + " were caught at " + catches.get (i + 1) + ".");
}
else
{
if (catches.get (i - 2) == fish)
resultLabel.setText ("During the Month of " + catches.get (i) + ", " + catches.get (i + 1) + " " + catches.get (i - 2) + " were caught.");
else
resultLabel.setText (catches.get (i + 1) + " " + catches.get (i - 2) + " were caught total.");
}
}
else
{
if (catches.get (i - 1) == location)
{
if (catches.get (i - 2) == fish)
resultLabel.setText ("During the Month of " + catches.get (i) + " at " + catches.get (i - 1) + ", " + catches.get (i + 1) + " fish were caught.");
else
resultLabel.setText (catches.get (i + 1) + " fish were caught at " + catches.get (i + 1) + ".");
}
else
{
if (catches.get (i - 2) == fish)
resultLabel.setText ("During the Month of " + catches.get (i) + ", " + catches.get (i + 1) + " fish " + " were caught.");
else
resultLabel.setText (catches.get (i + 1) + " fish were caught total.");
}
}
searchResults.add (resultLabel, BorderLayout.CENTER);
if (catches.get (i) == null)
break;
}
if (catches.get (i) == null)
break;
}
if (catches.get (i) == null)
break;
}
}
}
);
}
public static void readCaught () throws IOException
{
String line;
BufferedReader input;
input = new BufferedReader (new FileReader ("caught.txt"));
line = input.readLine ();
while (line != null)
{
int i = 0;
String fields[] = line.split (",");
CatchRecord caught = new CatchRecord ();
caught.fish = fields [0];
caught.location = fields [1];
caught.month = fields [3];
caught.count = Integer.parseInt (fields [2]);
catches.add (i, caught);
line = input.readLine ();
++i;
}
}
public static void writeCaught () throws IOException
{
PrintWriter output;
int randomCount = 0;
output = new PrintWriter (new FileWriter ("caught.txt", true));
output.print (fish + "," + location + "," + month.length () + "," + count + "\n");
output.close ();
}