Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A question about OO and static classes/methods 1

Status
Not open for further replies.

pipk

Programmer
Feb 20, 2001
455
GB
I have a question about static.

I have an application which consists of many JRadioButtons which allow the user to choose between the representation of various values on screen (it is a scuba dive logging system) - and so we have feet to metres and vice versa, psi to bar and vv, celcius to fahrenheit and vv etc etc etc.

I have created a class that handles my item events and intend to put all the conversion methods in this class, but am unsure how to implement it so that all objects that need these methods can access them.
can i make my item listener class static, or does it need to be public, or do i just make the methods static? etc etc.

any advice is always greedily absorbed and helpful to me regardless of whether it is the best way. Cheers for your time.

pipk
 
Hi pipk,

What I think you should do is declare your methods as public and static. So it would be something like:-

public class itemEventHandler ...
{
...
public static double FeetToMetre(..)
{
}
}

So within your item event handler class itself, you can just call FeetToMetre(). If you are calling this method from other classes, just call itemEventHandler.FeetToMetre(). Perhaps there are better methods but this is what I can think of.

Regards,
Leon If you need additional help, you can email to me at zaoliang@hotmail.com I don't guaranty that I will be able to solve your problems but I will try my best :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top