aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How do you animate current shapes using buttons in Java Applets? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How do you animate current shapes using buttons in Java Applets?" Watch "How do you animate current shapes using buttons in Java Applets?" New topic
Author

How do you animate current shapes using buttons in Java Applets?

Bobby Dillan
Greenhorn

Joined: Mar 20, 2013
Posts: 5
To start off I want to create a program that animates shapes using buttons. The
user selects a shape and the shape is outputted onto the screen. Now if the user
wants to animate the shape he will press the 'Animate shape' button. However I dont
know how to link the shape the user just selected with the animate button.


Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2177
    
    7
1. You are mixing AWT and Swing. I suggest you learn how to use Swing
2. Extend JApplet, not Applet
3. Custom painting is done by creating a JPanel and overriding its paintComponent() method. The first line should be super.paintComponent() to clear the panel so you don't leave the old drawing behind as you animate the shape. Then the panel is added to the applet
4. The Timer should be started when you click the button, not in the paintComponent() method.
5. Your have not set up your Timer correctly. The Timer code should be responsible for setting the new "X" coordinate to paint your shape, not the painting code.
6. You case logic is wrong. You already select which shape to paint in the case code. No need for the second "if statement".
7. You should not have repaint() logic in the painting code.
Bobby Dillan
Greenhorn

Joined: Mar 20, 2013
Posts: 5
Thankyou Rob. I revised my code and removed the unnecessary paint codes.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do you animate current shapes using buttons in Java Applets?