Reputation: 3
I'm working on a program that lets me search for teachers and students through a GUI.
So you all probably know the option when searching something on a website to filter just for some information rather than everything. To achieve that, I created a JMenuBar
and its corresponding JMenu
with multiple JCheckBoxMenuItem
s. If the name of a person is typed in, a method runs that checks if that person is in the system. If it is then another method is called that checks if JCheckBoxMenuItem
s are selected or not to either proceed with conventional search or filtered search. Instead of coding every single option, I put all JCheckBoxMenuItem
s in an ArrayList
. I created a new method that looped through this ArrayList
and checked if the JCheckBoxMenItem
on position i
isSelected()
and if so performing a certain action, but it seems like it doesn't even loop through the whole list and just stops even though something was selected. It should technically work but I guess something is missing that I'm not seeing. If I try to execute that method it never checks if a JCheckBoxMenuItem
is selected. I will post part of the code here and provide a link to my GitHub where you can find all the classes and the entire code : https://github.com/Gonzo-CR/Home-Projects/tree/master/project_SuchSystem
The class TestFrame
is the GUI with the explained code. Some variables and text is written in German, I hope this won't bring any problems with it. The off placed Menubar in the GUI needs to be pressed for starting the search.
public void einzelLehrerSuche()
{
model = (DefaultTableModel)table_Lehrer.getModel();
loescheLehrerTabelle();
String lehrername = tfSuchfeldLehrer.getText();
boolean lehrerGefunden = false;
if(lehrername.isEmpty() == false)
{
for(int i = 0; i < lehrerliste.size(); i++)
{
lehrer = lehrerliste.get(i);
if(lehrer.getName().equals(lehrername) || lehrer.getNachname().equals(lehrername))
{
if(checkAlleChbx(i) == true)
{
lehrerGefunden = true;
checkAlleChbx(i);
}
else
{
lehrerGefunden = true;
if(lehrer.isMehrereklassen() == true && lehrer.isMehrerefaecher() == true)
{
model.addRow(new Object [] {lehrer.getName(), lehrer.getNachname(), lehrer.getKuerzel(), lehrer.getKlasse_1().getBezeichnung(), lehrer.getKlasse_2().getBezeichnung(), lehrer.getFach().getBezeichnung(), lehrer.getFach2().getBezeichnung()});
}
else if(lehrer.isMehrereklassen() == true && lehrer.isMehrerefaecher() == false)
{
model.addRow(new Object [] {lehrer.getName(), lehrer.getNachname(), lehrer.getKuerzel(), lehrer.getKlasse_1().getBezeichnung(), lehrer.getKlasse_2().getBezeichnung(), lehrer.getFach().getBezeichnung(), " --- "});
}
else if(lehrer.isMehrereklassen() == false && lehrer.isMehrerefaecher() == true)
{
model.addRow(new Object [] {lehrer.getName(), lehrer.getNachname(), lehrer.getKuerzel(), lehrer.getKlasse_1().getBezeichnung(), " --- ", lehrer.getFach().getBezeichnung(), lehrer.getFach2().getBezeichnung()});
}
else
{
model.addRow(new Object [] {lehrer.getName(), lehrer.getNachname(), lehrer.getKuerzel(), lehrer.getKlasse_1().getBezeichnung(), " --- ", lehrer.getFach().getBezeichnung(), " --- "});
}
break;
}
break;
}
}
if(!lehrerGefunden)
{
JOptionPane.showMessageDialog(null, "Die gesuchte Person ist nicht im System!");
tfSuchfeldLehrer.setText("");
}
}
else
{
JOptionPane.showMessageDialog(null, "Geben Sie einen Namen in das Suchfeld ein!");
}
}
public boolean checkboxChecking(int i)
{
model = (DefaultTableModel)table_Lehrer.getModel();
loescheLehrerTabelle();
if(chbxKrzelAnzeigen.isSelected())
{
chbxKuerzelCheck(i);
}
else
{
return false;
}
return true;
}
public void chbxKuerzelCheck(int lehrerIndex)
{
lehrer = lehrerliste.get(lehrerIndex);
model.addRow(new Object [] {lehrer.getName(), lehrer.getNachname(),lehrer.getKuerzel(), " --- ", " --- ", " --- ", " --- "});
}
public boolean checkAlleChbx(int k)
{
ChbxGroup();
System.out.println(chbxListe.get(0).getText());
model = (DefaultTableModel)table_Lehrer.getModel();
loescheLehrerTabelle();
for(int i = 0; i < chbxListe.size(); i++)
{
System.out.println(chbxListe.size());
System.out.println(i);
System.out.println(chbxListe.get(i).getText());
model = (DefaultTableModel)table_Lehrer.getModel();
JCheckBoxMenuItem cbMI = chbxListe.get(i);
if(cbMI.isSelected())
{
String chbxname = cbMI.getText();
System.out.println(chbxname);
if(chbxname.equals("K\u00FCrzel Anzeigen"))
{
System.out.println("Kürzel gefunden");
chbxKuerzelCheck(k);
}
else
{
System.out.println("Didn't work!");
}
}
else
{
System.out.println("False angekommen");
return false;
}
}
System.out.println("True angekommen");
return true;
}
The method checkBoxChecking
is for individual checking of an checkbox but not used right now.
The method einzelLehrerSuche()
is the search algorithm linking to the method checkAlleChbx
where the problem is. I would highly appreciate your help.
Upvotes: 0
Views: 52