I just need serious help! Please!
ok well.... i need to code a program that has about 5 different GUI's and each in a different class, and there is a claass where all the details of the Database for coustomer details is stored in an array but now i need each GUI to access the array and use it but i dont know how to use the BanksArray class in a different class without re-creating it. and iv tried almost everthing i know and nothing works
[415 byte] By [
Torcheda] at [2007-11-27 2:37:12]

> ...i dont know how to use the BanksArray class in> a different class without re-creating it.Passing the BanksArray object into the different class as a class variable in the constructor.Message was edited by: SeanJ@
> > ...i dont know how to use the BanksArray class in
> > a different class without re-creating it.
>
> Passing the BanksArray object into the different
> class as a class variable in the constructor.
>
> Message was edited by:
> SeanJ@
I'ts better to implement BanksArray using the Singleton Pattern..
public class BanksArray {
private static BanksArray instance = null;
private BanksArray () {}
public static BanksArray getInstance() {
if (instance==null) return new BanksArray()
else return instance;
}
}
> I'ts better to implement BanksArray using the> Singleton Pattern..Why is it better?
mlka at 2007-7-12 2:57:10 >

My edit was to remove a reference to making it static. I didn't think it would work (and in the way I meant it, it probably wouldn't have), but I didn't know to use it in that context. Thanks.
can i ask you a favour... if you have msn can i add you and send u my project and can you kinda go throught it with me and help.. because i understand like nothing anymore
> can i ask you a favour... if you have msn can i add
> you and send u my project and can you kinda go
> throught it with me and help.. because i understand
> like nothing anymore
That's really the kind of request you need to make to your tutor or to your classmates. There's nothing wrong with working through a problem with tutors and colleagues but once you start down that path on tech forums... you just start relying on it and you don't progress.
ok i understand that but its difficult because i can get my problem into words properly and theres no one else around to help me... so i kinda dont have a choice
Okay. Firstly, slow down. Take a few breaths and step back.
Right, now you've done that, describe your goal. Don't talk about classes or objects, just describe what it is you need to model. For instance, don't tell me about your int array, tell me you have a list of numbers.
Keep it simple. Each sentence on a new line. That means we have a better chance of understanding what you want.
> > > ...i dont know how to use the BanksArray class
> in
> > > a different class without re-creating it.
> >
> > Passing the BanksArray object into the different
> > class as a class variable in the constructor.
> >
> > Message was edited by:
> > SeanJ@
>
> I'ts better to implement BanksArray using the
> Singleton Pattern..
> > public class BanksArray {
>
> rivate static BanksArray instance = null;
>
>private BanksArray () {}
>public static BanksArray getInstance() {
>if (instance==null) return new BanksArray()
>else return instance;
> }
> }
>
Just to point out, in case anyone is intending to copy and paste, the singleton code above doesn't work as intended.
If the instance is null, assign a new BanksArray to the instance and then return the instance.
ok
1) a gui opens with 4 buttons to choose the bank (we got that)
2) a screen opens with textfield for account number and passwordfield for pincode, then an enter button that would that the account number and pincode and check it with the details in the array, where we kinda stuck.
3) another gui where they can withdraw, deposit and see thier details
Okay, so I think you've been given the answer, pretty much.
Load up your account/pin data into your List (you might want to use a List as it's dynamic and more flexible than an Array).
Make that List available as a Singleton more or less as the code above suggests.
In each class that needs to access that List, just put a call in to MyList.getInstance(). You'll be given THE instance of your data structure and each class will be querying against the same data.
> Just to point out, in case anyone is intending to
> copy and paste, the singleton code above doesn't work
> as intended.
>
> If the instance is null, assign a new BanksArray to
> the instance and then return the instance.
it's right :) i made this mistake (it was time to left work hehe)
> I'ts better to implement BanksArray using the
> Singleton Pattern..
mlk, it's better to use this pattern rather than pass the class over the creator because all GUIs have access the same banksarray so there will be a unique instance of it.. if you pass it to all creators, you've to repeat the assignation, but you don't need to have a reference to the array but only access its methods. Singleton classes allows you to know there will be a unique instance of it so it's what you want (design patterns are made to be used).
Torched you've got now. good luck!