aspose file tools*
The moose likes Game Development and the fly likes JPanel, is it possible to make it move automatically like a pacman ghost? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Game Development
Bookmark "JPanel, is it possible to make it move automatically like a pacman ghost?" Watch "JPanel, is it possible to make it move automatically like a pacman ghost?" New topic
Author

JPanel, is it possible to make it move automatically like a pacman ghost?

Martin Nilsson
Greenhorn

Joined: Dec 08, 2010
Posts: 1
greetings

I am fairly new at this and its for a project.

But we are trying to make a bomberman clone.
I am programming the basic Enemy who is to roam the map were ever he can.

But recently the map was changed from images to JPanels on a frame.

And i cant in the world figure out how to get the JPanel to act like my old image. Well i cant even get it to move at all.
Is it possible to get it to move automatically?


(If you need more code it can be provided, but i have not written it.)

This is how the Panel is added to the frame. But even if i can see the panel on the created map i am still unable to get it to move.

Well the question is, is it possible to move automatically like a roaming enemy and if so please, could anyone point me towards the right direction on either where to look or do?

//Kerrai
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2203
    
    7
1) Learn and use proper Java naming conventions. Where in any text book or tutorial have you ever seen a variable name start with a capital letter? Don't make up your own rules. Its hard to read your code becuase a capital letter implies you are referencing a class, not a variable.

2) Why are you setting the layout on the "enemyPanel". You don't add any components to it so there is no reason to play with the layout.

3) Why are you creating a custom component to draw an image. A JLabel already does this for you when you use the setIcon() method.

4) Why are you using setVisible( true ). All Swing components are visible by default (except top level containers, like JFrame, JDialog, etc.).

5) You add the component to the frame. The frame is the one that needs a null layout so you can manually position the component

6) You can manually change the location of a component by using enemyLabel.setLocation(...);
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JPanel, is it possible to make it move automatically like a pacman ghost?