Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2009
    Posts
    26
    Rep Power
    0

    Default 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 10:55 AM.

  2. #2
    Join Date
    Nov 2009
    Posts
    26
    Rep Power
    0

    Default

    wow i just noticed the problem in my for loop lmao


    still doesn't work though
    Last edited by helpisontheway; 12-15-2009 at 10:31 AM.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    28

    Default

    Duplicate post. Answers are in other thread: http://www.java-forums.org/advanced-...el-button.html. I'm locking this one. OP, please avoid multiposting the same question more than once. Thank you for your cooperation.

Similar Threads

  1. need help about animation ?
    By h9h in forum Java 2D
    Replies: 1
    Last Post: 10-30-2009, 12:41 PM
  2. Animation failure...
    By lordbob75 in forum New To Java
    Replies: 10
    Last Post: 05-11-2009, 02:06 AM
  3. GUI Animation
    By serfster in forum New To Java
    Replies: 2
    Last Post: 06-11-2008, 03:37 AM
  4. Text Animation
    By rossomandop@acm.org in forum AWT / Swing
    Replies: 4
    Last Post: 05-30-2008, 03:34 AM
  5. GridLayout with animation?
    By tojas in forum AWT / Swing
    Replies: 3
    Last Post: 11-12-2007, 11:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •