Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 3rd, 2013, 02:57 PM
anson920520 anson920520 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 12 anson920520 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 27 m 32 sec
Reputation Power: 0
Research and questions about Handling User Interaction

I currently need to finish a task for my project which needs me to create a Create a display component to show Select pet shop name and total number of Pets in that shop.

For this tasks i created a several components,
I had a function call "getPetsInPetShop" to do what i mention

Code:
       public static ArrayList<Pet> getPetsInPetShop(Petshop TotalPets)
    {
        // this should go through all pets and return only those whose
        // pet shop name is the same as the parameter...
        
        //new arrylist to store information about pets
        ArrayList<Pet> result = new ArrayList<Pet>();
        
        //loop thought the csv file 
        for (Pet p : pet)
        {
            //if the user input a petshop name that can be found in the csv file
            if (p.getShop().equals(TotalPets.getName()))
            {
                //return thouse pet p
                result.add(p);
            }
        }
        //Here is the output
        return result;
    }
    


I assume this can allow me to loop how many pets i got inside the csv files, but i realize i may need one more function to turn it in number, but i don't know how to make a function to calculate it.

On the other hand this is my code to pass the function when the program run. This is mousevent function, when the user click on it , a new panel will appear for them to input information.

Code:
 public class SelectPetShopControl implements MouseListener{
    
    

    @Override
    public void mouseClicked(MouseEvent e) 
    {
         JLabel clicked = (JLabel)e.getSource();
         String PetShopName, TotalPets;
         SelectPetShopPanel spsp = (SelectPetShopPanel)clicked.getParent();
         PetShopName = JOptionPane.showInputDialog("Enter a pet shop name");
         if(PetShopName != null){      
  TotalPets = ApplicationModel.getPetsInPetShop(TotalPets);
              spsp.setPetshop("Pet Shop Nmae: "+PetShopName);
              spsp.setTotalPets("Total: "+TotalPets);
         }
    }


Everything in here is right expect "TotalPets = ApplicationModel.getPetsInPetShop(TotalPets);"
The error message in here is incompatible types.

I had look at some example and try to fix it by myself,
but i realize i don't have enough technology to finish it.

Many thanks

Reply With Quote
  #2  
Old January 3rd, 2013, 04:32 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: Eastern Florida
Posts: 2,952 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 34 m 5 sec
Reputation Power: 345
Quote:
error message in here is incompatible types.

Is the data type of the variable to the left of the = the same as the data type returned by the method to the right of the =? They must be compatible.
What are the two types? Can you change one to match the other?

Reply With Quote
  #3  
Old January 4th, 2013, 05:16 AM
anson920520 anson920520 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 12 anson920520 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 27 m 32 sec
Reputation Power: 0
Quote:
Originally Posted by NormR
Is the data type of the variable to the left of the = the same as the data type returned by the method to the right of the =? They must be compatible.
What are the two types? Can you change one to match the other?


how can i change one to match the other?
Please look at my code once more i had fix something

Reply With Quote
  #4  
Old January 4th, 2013, 06:15 AM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: Eastern Florida
Posts: 2,952 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 34 m 5 sec
Reputation Power: 345
Quote:
i had fix something

What did you fix or change? Are there still errors? If so, please post the full text of the error messages.

Reply With Quote
  #5  
Old January 4th, 2013, 06:18 AM
anson920520 anson920520 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 12 anson920520 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 27 m 32 sec
Reputation Power: 0
Quote:
Originally Posted by NormR
What did you fix or change? Are there still errors? If so, please post the full text of the error messages.


this error message still appear inside my MouseEvent
Code:
 public void mouseClicked(MouseEvent e) 
    {
         JLabel clicked = (JLabel)e.getSource();
         String PetShopName, TotalPets;
         SelectPetShopPanel spsp = (SelectPetShopPanel)clicked.getParent();
         PetShopName = JOptionPane.showInputDialog("Enter a pet shop name");
         if(PetShopName != null){      
              TotalPets = ApplicationModel.getPetsInPetShop(TotalPets);
              spsp.setPetshop("Pet Shop Nmae: "+PetShopName);
              spsp.setTotalPets("Total: "+TotalPets);
         }
}


The error message is "method getPetsInPetShop in class ApplicationModel cannot be applied to given types;
required: Petshop
found: String
reason: actual argument String cannot be converted to Petshop by method invocation conversion

variable TotalPets might not have been initialized"

Reply With Quote
  #6  
Old January 4th, 2013, 06:44 AM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: Eastern Florida
Posts: 2,952 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 34 m 5 sec
Reputation Power: 345
Quote:
String cannot be converted to Petshop

Where is the ^ that the compiler uses to point to the location of the error?
You have left that off of the posted error message.
Here is a sample compiler error message:
Code:
TestSorts.java:138: cannot find symbol
symbol  : variable var
location: class TestSorts
         var = 2;
         ^

Notice the ^ in the above sample.

What datatype does the getPetsInPetShop() method take for an arg?
What data type is TotalPets?
The compiler says that they are different and not compatible.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Research and questions about Handling User Interaction

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap