GUI Help
Iv'e made a non GUI version of my Programme and I now making i into a GUI version. I am however stuck on how to implement my search method, as its different from adding and displaying things in my array.
Below is my code
GUI
publicclass SearchPrisonersDialogextends JDialogimplements ActionListener
{
private JButton ok;
private JButton cancel ;
private JTextField id;
public SearchPrisonersDialog(String sTitle, JFrame owner)
{
super (owner, sTitle,true);
setLayout(new FlowLayout());
setSize(400,250);
add (new JLabel("Enter Prisoner ID to search for:"));
id =new JTextField(10) ;
add (id);
ok =new JButton("Search");
ok.addActionListener(this);
add(ok);
cancel =new JButton("Cancel");
cancel.addActionListener(this);
add(cancel);
}
public Prisoner getPrisoner()
{
return thePrisoner ;
}
publicvoid actionPerformed(ActionEvent e)
{
if (e.getSource() == ok)
{
(id.getText());//Errors not a statement
HMESSEX.SearchPrisonersFOR(id);
}
elseif (e.getSource() == cancel)
{
// data entry cancelled
id =null;
}
dispose();
}
}
GUI
elseif (e.getSource() == SearchPrisoner)
{
SearchPrisonersDialog dlg =new SearchPrisonersDialog("Search for Prisoner Dialog",this);
dlg.setVisible(true);
Prisoner id = dlg.getPrisoner();
if ( id !=null)
{
displayArea.setText ( p.toString() );
HMEssex.SearchPrisoners(id);
}
else
displayArea.setText("No Prisoner Searched for" );
}
GUI
publicvoid SearchPrisonersFOR(JTextArea displayArea)
{
for(Person nextPrisoner : thePersons)
{
if (nextPrisonerinstanceof Prisoner)
{
Prisoner p = (Prisoner) nextPrisoner;
{
if (p.getPrisonerID().equals(id))
{
displayArea.append("\n" + p);
}
}
}
}
}
Before converting for GUI
publicvoid SearchPrisoners(String id)//search for prisoner by ID
{
System.out.println("Prisoners:");
for (Person x: thePersons)
{
//System.out.println("Found person: " + x.toString());
if (xinstanceof Prisoner)
{
Prisoner p = (Prisoner) x;
{
if (p.getPrisonerID().equals(id))//Checks if there is a matching ID within the enetered
{
System.out.println(p.toString());//Prints Prisoners Details
}
else
{
System.out.println("Prisoner with wrong id: "+p.getPrisonerID());//Prints Id/s that did not match
}
}
}
}
}
Thankyou for all your help in advance any more code required to solve my problem just ask

