Results 1 to 3 of 3
Thread: gui animation problems
- 12-15-2009, 08:12 AM #1
Member
- Join Date
- Nov 2009
- Posts
- 26
- Rep Power
- 0
gui animation problems
Hey. Thanks in advance
Synopsis:
I am reading a book.... It told me to try and animate an oval with what i know(come up with a concept, but i decided to write code).
I'm making an oval that moves diagonally with a JPanel. It compiles perfectly, but doesn't run quite as expected.
I want to say my logic is correct, so I must be doing it totally wrong then.
Java Code:import javax.swing.*; import java.awt.*; import java.awt.event.*; class AnimatedB extends JFrame { JFrame frame; Ken4Funny ken; JButton button; public static void main(String[] args) { AnimatedB animate = new AnimatedB(); animate.go(); } public void go() { frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ken = new Ken4Funny(); button = new JButton("animate"); button.addActionListener(new Ken4Funny()); frame.getContentPane().add(BorderLayout.SOUTH, button); frame.getContentPane().add(BorderLayout.CENTER, ken); frame.setSize(500,500); frame.setVisible(true); } class Ken4Funny extends JPanel implements ActionListener { int x = 20; int plusx = 5; int y = 50; int plusy = 5; public void paintComponent(Graphics g) { x += plusx; y += plusy; g.setColor(Color.orange); g.fillOval(x, y, 100, 100); } public void actionPerformed(ActionEvent event) { for(int xx = 0; xx <=20; xx++) { frame.repaint(); plusx += 5; plusy += 5; } } } }Last edited by helpisontheway; 12-15-2009 at 09:55 AM.
- 12-15-2009, 09:23 AM #2
Member
- Join Date
- Nov 2009
- Posts
- 26
- Rep Power
- 0
wow i just noticed the problem in my for loop lmao
still doesn't work thoughLast edited by helpisontheway; 12-15-2009 at 09:31 AM.
-
Duplicate post. Answers are in other thread: trying to animate jpanel with button. I'm locking this one. OP, please avoid multiposting the same question more than once. Thank you for your cooperation.
Similar Threads
-
need help about animation ?
By h9h in forum Java 2DReplies: 1Last Post: 10-30-2009, 11:41 AM -
Animation failure...
By lordbob75 in forum New To JavaReplies: 10Last Post: 05-11-2009, 02:06 AM -
GUI Animation
By serfster in forum New To JavaReplies: 2Last Post: 06-11-2008, 03:37 AM -
Text Animation
By rossomandop@acm.org in forum AWT / SwingReplies: 4Last Post: 05-30-2008, 03:34 AM -
GridLayout with animation?
By tojas in forum AWT / SwingReplies: 3Last Post: 11-12-2007, 10:16 PM


LinkBack URL
About LinkBacks

Bookmarks