tags:

views:

34

answers:

2

Hi as we know ,we can add one icon to the button

jButton1.setIcon(Icon c);

can we add a rotating image to the button?(text 3d) if yes,please help me with a simple code.thanks

+1  A: 

The steps you'll need to follow broadly speaking are:

  • Prepare each animation frame as a separate image either programmatically or by pre-loading a number of images into memory.
  • Subclass JButton and override paintComponent(Graphics) to apply a new Image to the JButton (the next animation frame).
  • Use javax.swing.Timer to fire an ActionEvent periodically (e.g. every 50ms), causing it to repaint the JButton.

Are you sure you want to do this though? It might make your UI look like it was written in the mid-80s.

Adamski
yes,I should do it!
Johanna
I need some code I didn't get the whole[:-(]
Johanna
Try using the above tips to try writing some code, and if you get stuck then paste the error and code snippet into a question and I'll try to help. Also, if you google for "JButton animation" you should find some useful information.
Adamski
A: 

I'm not sure if I'm just been capt. obvious... but... can't you just get an animated GIF and control the timing on that? It seems a lot easier than controlling the entire animation by generating the graphics and all.

jghost