Animation problems

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kaka123
    New Member
    • Dec 2007
    • 8

    Animation problems

    im doing an applet and this is what i have so far

    [CODE=Java]import java.awt.*;
    import java.awt.event. *;
    import java.applet.*;
    import javax.swing.*;
    public class Applet1 extends JApplet
    {
    Thread t = new Thread();;
    int p1;
    int p2;
    int a=0;
    int b=50;
    int c=125;
    int d=115;
    int e=50;
    int f=300;
    int j=300;
    int h=325;
    int i=325;
    int ani=480;
    int [] x = {b+a,c+a,d+a,e+ a};
    int [] y = {f+a,j+a,h+a,i+ a};
    public void paint(Graphics g)
    {
    g.setColor(Colo r.black);
    g.fillRect(0,0, 500,300);
    g.setColor(Colo r.blue);
    g.fillRect(0,30 0,500,500);

    g.setColor(Colo r.white);
    for(int a=1;a<=342;a=a+ 2)
    {

    p1=1+(int) (Math.random()* 600);
    p2=1+(int) (Math.random()* 254);
    g.fillOval(p1,p 2,1,1);
    }
    g.fillOval(450, 30,25,25);
    {
    ani=ani-1;
    g.setColor(Colo r.gray);
    g.fillOval(ani, 70,60,40);
    g.fillOval(ani, 90,70,30);
    g.fillOval(ani-20,105,60,30);
    try{t.sleep(100 );} catch(Exception e){}
    g.setColor(Colo r.gray);
    g.fillOval(ani, 85,50,20);
    if(ani<500)repa int();
    }
    }
    }
    [/CODE]

    the one problem is is when i animate the cloud to move, it repaints the stars in the back round again using the math.random..

    what am i doing wrong? im pretty sure every thing is inside a bracket, and dont mind all my ints and the array that i havent used yet..just need to know about the animation
    Last edited by BigDaddyLH; Feb 26 '08, 04:51 PM. Reason: added code tags
  • jimhawkss
    New Member
    • Feb 2008
    • 10

    #2
    Heres two hints...
    1) Look at your Paint Method.
    2) Decide where your Math.Rand should be.

    Comment

    • BigDaddyLH
      Recognized Expert Top Contributor
      • Dec 2007
      • 1216

      #3
      Please enclose your posted code in [code] tags (See How to Ask a Question).

      This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

      Please use [code] tags in future.

      MODERATOR

      Comment

      Working...