Use image instead. A Sprite. You could create a class button that basically contains the x,y axis of the button in the screen, it's size. You can twist the class adding a list of images this button can have, methods for positioning, etc...

Create a png file for the button ( bitmap, jpg, gif, whatever ). Use a BufferedImage to save that png on memory and then draw it on the screen using the drawImage method of your Graphics object in the x,y position.

Using mouse action listeners, you can get x,y output of a mousePressed event and then check if the button X postion plus its Width intersects X you got from mousePressed, same thing to Y axis of the button and its Height. And do whatever action you need.

If you want to use Swing buttons, you can still give them images. Just override the paintComponent method of JButton. Or, since he seems to be using AWT, I think he would have to override the paint method of Button.

I went completely overboard and created my own "widgets" that are equivalent to components in most ways. The reason I went to all that trouble was because I wanted to make image buttons that stretched appropriately when the window was resized. This wasn't too hard, but the layout I had created didn't work too well with normal Swing components. So I wound up doing a couple more widgets.

By that point, it was always as easy to do "one more thing" as it was to go back. And then my 6-month project took over a year to complete (just finishing up now).

I like the result, but it probably wasn't worth that much effort. Plain AWT/Swing image buttons are much easier to implement.

I plan to eventually make my widget library (such as it is) available on my website. Some people might find it useful. It runs on top of Swing, but my widgets generally have a much smaller memory footprint than Swing components. On the other hand, they aren't as configurable. And I've only implemented so many different kinds of widgets.

ok all goes well. now im creating a character select screen. the characters i draw here i would like to implement in game play and other panels. what would be the best way to create these? put them in their own classs? method? maybe put each character on a transparent panel?

any thoughts? suggestions?

also why is actionlistener a parameter?

Read http://fivedots.coe.psu.ac.th/~ad/jg/. Also, purchase the whole book, Killer Game Programming in Java. Also, purchase Developing Games in Java. These two books will teach you all about sprites. They have nothing to do with Awt or Swing.

ActionListener is a parameter just so that you can get it from your main class into the TitlePanel class. You have to send some kind of information from one class to the other.

so in effect you can make anything act as a button? create my sprite and then when the mouse is over its coordinates and clicked the applet takes action? in terms of animation it would be better to draw my characters rather than make them a png file right?

ok how about this. the only animations the character will need is to move arms and legs. so could i create a gif image of the character minus say his arm and then when i needed to move the arm i could just draw it? or would that look funny?

ok how about this. the only animations the character will need is to move arms and legs. so could i create a gif image of the character minus say his arm and then when i needed to move the arm i could just draw it? or would that look funny?

No. Just create complete frames of animation. You need to keep it simple at this point.

so far i created a class with bufferedimage methods for each character. the buffered image background is transparent and the character is all that shows up. so let me make sure im thinking this through correctly. during gameplay i want the characters to appear like they are walking only if a direction arrow(left or right) is pushed. this can just be a loop of sorts right? like while the key is pushed loop through the animation frames?

so in effect you can make anything act as a button? create my sprite and then when the mouse is over its coordinates and clicked the applet takes action? in terms of animation it would be better to draw my characters rather than make them a png file right?

No, you don't want to make your sprites be buttons.

There's nothing wrong with getting your characters from a .png file. Typically, that's what you would do because an artist would be the one doing the art.

ok how about this. the only animations the character will need is to move arms and legs. so could i create a gif image of the character minus say his arm and then when i needed to move the arm i could just draw it? or would that look funny?

In theory, you could. I read something about this once, though I don't have the URL any more. It's just not something people normally do. Have the artist draw several frames so that you have animations.

You really need to read one of the books I mentioned or a tutorial or something. Most of your questions are about things that you should learn from reading these books.

fletcher you said i dont want my sprites to be buttons why is that? i didnt mean make them actual buttons but on the character select screen i want the user to click on the character they want to use. so far i have drawn the characters and then used mousemotionlistener and mouselistener so that when the user clicks in the coordinates of the character the applet shows the next panel or whatever. the animation doesnt occur until in the game is there anything wrong with my method so far?

fletcher you said i dont want my sprites to be buttons why is that? i didnt mean make them actual buttons but on the character select screen i want the user to click on the character they want to use. so far i have drawn the characters and then used mousemotionlistener and mouselistener so that when the user clicks in the coordinates of the character the applet shows the next panel or whatever. the animation doesnt occur until in the game is there anything wrong with my method so far?

fletcher you said i dont want my sprites to be buttons why is that? i didnt mean make them actual buttons but on the character select screen i want the user to click on the character they want to use. so far i have drawn the characters and then used mousemotionlistener and mouselistener so that when the user clicks in the coordinates of the character the applet shows the next panel or whatever. the animation doesnt occur until in the game is there anything wrong with my method so far?

is there any way to make an awt button push when enter is pressed? basically is there an equivalent to setDefaultButton(..); in awt not swing. also is there any way to make the cursor start in the text field? as is now the user has to click on the text field to start typing.

also.....i am having the user enter a user name. whats the best way to check and make sure they did this. i am using string.length(); right now but if they just enter spaces length() returns a value.how do i get around this?

ok given that shouldn't this work? and the problem isnt that the loop continues forever. it wont work at all with the key thing. the animation will work if i just put x++ in the run method but i dont want it to run forever just run when the keys are pressed.

You forgot the addKeyListener(this). You need to do things differently though.

1. If you are doing drawing in paint, do only drawing. Do not do any game logic or loading of resources.2. All the resources you are going to use for a level should be loaded ahead of time.3. Having said #1 above, you should use active rendering anyway.4. Use the thread you created and use it as a game loop.5. Use double buffering to stop flickering.

Search on 3, 4 and 5 to find out how to use them Make sure you put Java in your search to get Java specific examples. I modified your code to get you started.

ok here is what i have double buffering and all. when the left or right keys are pushed the character moves...done. when the up or down keys are pushed the character should raise or lower his arm....as in aiming a gun. is the easiest way to do this with an array of images as i have now? if so what is a good program to use to make my sprites?

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org