473,699 Members | 3,143 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Animation problems

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

Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import java.applet.*;
  4. import javax.swing.*;
  5. public class Applet1 extends JApplet
  6. {
  7.  Thread t = new Thread();;
  8. int p1;
  9. int p2;
  10. int a=0;
  11. int b=50; 
  12. int c=125;
  13. int d=115;
  14. int e=50;
  15. int f=300;
  16. int j=300;
  17. int h=325;
  18. int i=325;
  19. int ani=480;
  20. int [] x = {b+a,c+a,d+a,e+a};
  21. int [] y = {f+a,j+a,h+a,i+a};
  22. public void paint(Graphics g)
  23. {
  24. g.setColor(Color.black);
  25. g.fillRect(0,0,500,300);
  26. g.setColor(Color.blue);
  27. g.fillRect(0,300,500,500);
  28.  
  29. g.setColor(Color.white);
  30. for(int a=1;a<=342;a=a+2)
  31. {
  32.  
  33.  p1=1+(int) (Math.random()*600);
  34. p2=1+(int) (Math.random()*254);
  35. g.fillOval(p1,p2,1,1);
  36. }
  37. g.fillOval(450,30,25,25);
  38. {
  39. ani=ani-1;
  40. g.setColor(Color.gray);
  41. g.fillOval(ani,70,60,40);
  42. g.fillOval(ani,90,70,30);
  43. g.fillOval(ani-20,105,60,30);
  44. try{t.sleep(100);} catch(Exception e){}
  45. g.setColor(Color.gray);
  46. g.fillOval(ani,85,50,20);
  47. if(ani<500)repaint();
  48. }
  49. }
  50. }
  51.  
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
Feb 26 '08 #1
2 943
jimhawkss
11 New Member
Heres two hints...
1) Look at your Paint Method.
2) Decide where your Math.Rand should be.
Feb 26 '08 #2
BigDaddyLH
1,216 Recognized Expert Top Contributor
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
Feb 26 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1314
by: Simena Dinas | last post by:
KToon: 2D Animation Toolkit KToon is a 2D Animation Toolkit designed by animators (Toonka Films) for animators, focused to the Cartoon's industry. This project is covered by the GPL License using G++, OpenGL and QT as programming resources from KDevelop as the development platform. One year later of production, it is a pleasure for Toonka Films announces to the Free Software community the release of the KToon
5
3447
by: Brian Angliss | last post by:
I'm relatively new to scripting in JavaScript, so I'm not too surprised I'm having difficulty scripting up an animation effect for my personal site. What I'm trying to do is the following: When I go onMouseOver on a button in a nav bar, I want that button to switch to a different image while at the same time another blank image changes as an animation to an associated image. When I go onMouseOut, the bar image reverts back to the...
11
3759
by: Eugene | last post by:
Setting backcolor for the animation control does not take effect. The BackStyle property is set to cc2BackstyleTransparent. No matter what BackColor property is set to, in run time the backcolor is always SystemColors.Control.
6
2395
by: Darren | last post by:
X-No-Archive Hi all, Can anyone help me with structuring the data in a small tool I have to build? I'm trying to work out if there's a design pattern or data structure that would remove some of the dependencies. I am designing an animation tool.
3
2082
by: James | last post by:
Hello, I'm new to c# and have created an animation which draws directly to the window, it uses the code below which all works. I would like to know if this is the 'correct' way to do it - or would an experienced c# programmer do it another way? This part defines the screen and the graphics pad I'm drawing to: Graphics screen = CreateGraphics(); Graphics drawpadg = Graphics.FromImage(drawpad);
2
5771
by: rdemyan via AccessMonster.com | last post by:
My application has a lot of complicated SQL statements, calculations, processing that takes time. I've created a custom form to act like a messagebox. It has 10 small rectangles on it that change color sequentially to let the user know that processing is occurring. This 'animation' occurs via the form timer event. However, I'm having trouble getting the animation to occur for all types of processing events. It appears that I have to...
1
1822
by: jsavagedesign | last post by:
This is a project I have been working on lately and I keep running into problems. The idea is to be able to attaching an animation to a movie clip and call it later. Or multiple animation at once. example: on the stage you have a black box called: myClip in actionscript you type: growClip = grow(myClip); spinClip = spin(myClip); now when you call:
0
1105
by: shapper | last post by:
Hello, I need to create the following code at runtime: <ajaxToolkit:UpdatePanelAnimationExtender ID="upae" BehaviorID="animation" runat="server" TargetControlID="updatePanel"> <Animations> <OnUpdating> <Parallel duration="0"> <ScriptAction Script="onUpdating();" />
4
13913
by: Sin Jeong-hun | last post by:
Most applications, including Windows Explorer, show some sort of 'wait' dialog with animation when a lengthy operation is going on. For example, When the Windows Explorer is searching for something, it shows a small dialog with a moving flashlight. I examined the explorer.exe and found that that was an avi file. Now that, I would like to do similar thing in my C# application. But what is the most efficient way to do so? 1)Manually...
8
5537
by: DelphiCoder | last post by:
As part of familiarizing myself with the Win32 API, I wrote a simple animation program in C. The program has a struct for each bitmap, holding information such as its location, visibility, mask (for transparency), etc. Then I have a separate thread running that has a WHILE loop that looks like this: WHILE (TRUE) { /* update all structs (bitmap locations, etc) */ SleepEx(iSpeed, FALSE); InvalidateRect(hwnd, lpRect, TRUE); }
0
8709
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8638
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9058
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8952
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8909
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7791
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4395
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4649
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2371
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.