?
Solved

Table model

Posted on 2005-05-14
11
Medium Priority
?
239 Views
Last Modified: 2010-03-31
In my HospitalGUI.java I hava a JTable tablePatient,
as well as a patientDefaultModel pdm.

In my patientDefaultModel.java, under my getValueAt(),
I have the following code:

case 4:
return p.getmedicalFacility();

and in my HospitalGUI.java I have the following code:


if(ae.getSource()==deleMF)
{
     int num;
     MedicalFacility mf = null;
                    
     for(int i=0;i<hs.getPatients().size() && mf==null;i++)
     {
       mf = (MedicalFacility) tablePatient.getValueAt(i,4);
     }
....................

which wont work, because

case 4:
return p.getmedicalFacility();

returns a string and not an MedicalFacility object.

How do I solve the problem?.

You can download the code from:

www.mutaiyas.com/db/GUI.zip

Your help is kindly appreciated.

Regards

Eugene

0
Comment
Question by:eugene007
  • 6
  • 5
11 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 14002557
You need to store MedicalFacility objects in your model if you want to retrieve such objects from the model
0
 

Author Comment

by:eugene007
ID: 14002580
How is it done im my case?.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 360 total points
ID: 14002706
>>
return p.getmedicalFacility();

returns a string and not an MedicalFacility object.
>>

It seems to me to return MedicalFacility, which is correct.

Incidentally it should be called

getMedicalFacility();

and your class and interface names should begin with a capital letter
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:eugene007
ID: 14002762
I guess this return p.getmedicalFacility(); invokes the toString() in my MedicalFacility.java.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 14002769
No, not according to the code. What is the actual error you're getting? Stack trace please
0
 

Author Comment

by:eugene007
ID: 14005031
I found the solution:

              if(ae.getSource()==deleMF)
              {
                     int num;
                     MedicalFacility mf = null;
                     boolean equality=false;

                     num = tableMF.getSelectedRow();
                                             
                     if(num>=0)
                     {
                         mf = (MedicalFacility) hs.getmedicalFacilities().get(num);
                        
                         for(int i=0;i<hs.getPatients().size() && equality==false;i++)
                         {
                                MedicalFacility p = (MedicalFacility) tablePatient.getValueAt(i,4);
                            
                             if(p.getName().equalsIgnoreCase(mf.getName()))
                             {
                                    equality = true;
                             }                             
                         }
                        
                         if(equality==false)
                         {                         
                               if(mf instanceof Hospital)
                               {
                                      num = ((Hospital)mf).getProcedures().size();
                                   
                                      if(num>0)
                                      {
                                          String name = mf.getName();
                                            
                                          int value = JOptionPane.showConfirmDialog(null,"There are " + num + " procedures for " + name + ".\n Do you want to delete?","Delete Hospital",JOptionPane.YES_NO_OPTION);
                                   
                                          if(value == JOptionPane.YES_OPTION)
                                          {
                                               hs.removeMedicalFacility(mf);
                                               mfdm.fireTableDataChanged();
                                                
                                               prdm = new procedureDefaultModel(null);
                                               tableProcedure.setModel(prdm);
                                       prdm.fireTableDataChanged();  
                                          }
                                      }
                                      else
                                      {
                                          hs.removeMedicalFacility(mf);
                                          mfdm.fireTableDataChanged();
                                      }
                               }
                               else
                               {
                                      hs.removeMedicalFacility(mf);
                                      mfdm.fireTableDataChanged();
                               }
                            }
                            else
                            {
                               JOptionPane.showMessageDialog(null,"The Medical Facility cannot be deleted.","Error",JOptionPane.ERROR_MESSAGE);
                            }
                     }
                     else
                     {
                            JOptionPane.showMessageDialog(null,"Select a Medical Facility","Error",JOptionPane.ERROR_MESSAGE);
                     }                        
              }

The code above can be found in HospitalGUI.java

Is there anyway for me to improve the code above?.

Your can download the latest code from:

www.mutaiyas.com/db/GUI.zip

Regards

Eugene
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 14005036
>>I found the solution:

I'm not with you? - you've just used the line that earlier you said would not work, which i said *would*:

>>MedicalFacility p = (MedicalFacility) tablePatient.getValueAt(i,4);
0
 

Author Comment

by:eugene007
ID: 14005058
and the critical part is this:

if(p.getName().equalsIgnoreCase(mf.getName()))
{
        equality = true;
}  

because if a patient is tied up to a medical facility, this means that I wont allow the deletion of the medical facility. To check the quality, I have to compare. Im sorry if my question which I posted was not clear.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 14005064
This time i'll let this go, but please don't post 'thinking aloud' type questions like this, as you're just wasting peoples' time
0
 

Author Comment

by:eugene007
ID: 14005109
You did your part and the points is yours.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 14005113
OK thanks ;-)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month9 days, 12 hours left to enroll

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question