how to deal with awt and swing component in java .error is produced when i compare the swing component so what i do for solving it;

Recommended Answers

All 2 Replies

public class Person
{
    public String Name;
    public String SocialSecurityNumber;
    public String PhoneNumber;
 
    public Person(String name, String socialSecurityNumber, String phoneNumber)
    {
	Name = name;
	SocialSecurityNumber = socialSecurityNumber;
	PhoneNumber = phoneNumber;
    }
 
    @Override
    public boolean equals(Object compareObj)
    {
	if (this == compareObj) // Are they exactly the same instance?
           return true;
 
	if (compareObj == null) // Is the object being compared null?
	    return false;
 
	if (!(compareObj instanceof Person)) // Is the object being compared also a Person?
	    return false;
 
	Person comparePerson = (Person)compareObj; // Convert the object to a Person
 
	return this.SocialSecurityNumber.equals(comparePerson.SocialSecurityNumber); // Are they equal?
    }
 
    @Override
    public int hashCode()
    {
	int primeNumber = 31;
	return primeNumber + this.SocialSecurityNumber.hashCode();
    }
}

Hope this code may solve your problem

public class Person
{
    public String Name;
    public String SocialSecurityNumber;
    public String PhoneNumber;
 
    public Person(String name, String socialSecurityNumber, String phoneNumber)
    {
	Name = name;
	SocialSecurityNumber = socialSecurityNumber;
	PhoneNumber = phoneNumber;
    }
 
    @Override
    public boolean equals(Object compareObj)
    {
	if (this == compareObj) // Are they exactly the same instance?
           return true;
 
	if (compareObj == null) // Is the object being compared null?
	    return false;
 
	if (!(compareObj instanceof Person)) // Is the object being compared also a Person?
	    return false;
 
	Person comparePerson = (Person)compareObj; // Convert the object to a Person
 
	return this.SocialSecurityNumber.equals(comparePerson.SocialSecurityNumber); // Are they equal?
    }
 
    @Override
    public int hashCode()
    {
	int primeNumber = 31;
	return primeNumber + this.SocialSecurityNumber.hashCode();
    }
}

Hope this code may solve your problem

How could that solve his problem? Not to mention that you will get a NullPointerException with that code.

Dmith post the error that you get as well as relevant code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.