File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes How should i best implement this? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How should i best implement this?" Watch "How should i best implement this?" New topic

How should i best implement this?

David McGratton

Joined: Jul 28, 2011
Posts: 5
Hi all,

This first post contains no code, just what i want to do and asking the best way to do this. I am familiar with swing however i havent used it much.
Future posts will be my code to be approved or critised.

It involves using timers within a game.

1) An item (eg loaf_of_bread) is on the screen
2) Player picks up item, item disappears , a timer is started eg 30 seconds.
3) After 30 seconds, the timer is destroyed and the item is remade and displayed.

My thoughts are, to create an "itemManager" class containing an array of "item". The player picking up the item calls "addItemToManager(variables go here)".
The item is added to itemManager array which initiates a timer which is used to regenerate the item on the screen, based on the variables.

I am after the most effecient method to do this.

Thankyou for reading the post,

Kindest Regards.
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Then the best thing would be for you to list all the methods you have identified so far, and to evaluate each of them in terms of whatever "efficiency" means to you. You could post them here if you would like discussion about that process.
David McGratton

Joined: Jul 28, 2011
Posts: 5
Hi Paul,

This is what i have so far for me to be advised on.

Kindest Regards
Rob Spoor

Joined: Oct 27, 2005
Posts: 20271

When you need a timer in Swing, javax.swing.Timer is usually the way to go.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: How should i best implement this?
jQuery in Action, 3rd edition