September 04, 2010, 01:24:49 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  Home Help Media Affiliates Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Animated java applet demo  (Read 1584 times)
0 Members and 1 Guest are viewing this topic.
Arkie
Javaforums.net Admin
Senior Member
*

Reputation: 16
Developer @ Javaforums.net
Offline Offline
Posts: 2620
Referrals: 13

WWW Awards
« on: June 29, 2008, 10:01:28 AM »

This is an animated java applet I made that shows a falling apple.

Code
GeSHi (java):
  1. package house;
  2.  
  3. import java.applet.Applet;
  4. import java.awt.*;
  5.  
  6. public class HouseAnimated extends Applet implements Runnable{
  7. Thread imageThread;
  8. int ani1 = 0, apple = 60, x = 0, delay = 0;
  9. boolean appleDelay = true;
  10.  
  11. public void paint(Graphics g){
  12. g.setColor (Color.BLACK);
  13. g.drawLine (120, 40, 60, 70);
  14. g.drawLine (120, 40, 180, 70);  
  15. g.drawRect (60, 70, 120,70);
  16. g.setColor (Color.yellow);
  17. g.fillRect (61, 70, 119,70);
  18. g.drawRect (70, 100, 30,40);
  19. g.setColor (Color.orange);
  20. g.fillRect (70, 100, 30,40);
  21. g.drawRect (120,100, 20,20);
  22. g.setColor (Color.blue);
  23. g.fillRect (120,100, 20,20);
  24. g.setColor (Color.red);
  25. g.fillRect (150,100, 20,20);
  26. g.setColor (new Color (255, 192, 81));
  27. g.fillRect (240,70, 20,70);
  28. g.setColor (Color.green);
  29. g.fillOval (220, 20, 70, 70);
  30. g.drawString("An animated Applet :: www.engineeringserver.com", 100,200);
  31.  
  32.  
  33. g.setColor(Color.yellow);
  34. g.fillOval(400,10,50,50);
  35.  
  36. getRandom();
  37.  
  38. if (x == 1){
  39. g.drawLine(395, 20, 350, 10);
  40. g.drawLine(395, 35, 370, 35);
  41. g.drawLine(395, 50, 350, 60);
  42. g.drawLine(410, 60, 380, 70);
  43. ani1++;
  44. }
  45.  
  46. if (x == 2){
  47. g.drawLine(395, 35, 370, 35);
  48. g.drawLine(410, 60, 380, 70);
  49. ani1++;
  50. }
  51.  
  52. if (x == 3){
  53. g.drawLine(395, 20, 350, 10);
  54. g.drawLine(395, 50, 350, 60);
  55. ani1++;
  56. }
  57. if (x == 4){
  58. g.drawLine(395, 20, 350, 10);
  59. g.drawLine(410, 60, 380, 70);
  60. ani1++;
  61. }
  62. else{
  63. ani1--;
  64. }
  65. g.setColor(Color.red);
  66. g.fillOval(240, 60, 10, 10);
  67. g.fillOval(250, 25, 10, 10);
  68. g.fillOval(225, 40, 15, 15);
  69. g.fillOval(265, apple, 15, 15);
  70. }
  71.  
  72. public void init(){}
  73.  
  74. public void  appleAni(){
  75. if (apple <=120 && appleDelay== false){
  76. apple = apple+5;
  77. }
  78. }
  79.  
  80. public void getRandom(){
  81. x = (int) (1 * Math.random()* 5);
  82. }
  83.  
  84. public void start(){
  85. imageThread = new Thread(this, "");
  86. imageThread.start();
  87. }
  88.  
  89. public void destroy(){}
  90.  
  91. public void run() {
  92. while(Thread.currentThread() == imageThread){
  93. Thread t = new Thread();
  94. try {
  95. t.sleep(500);
  96. appleAni();
  97. delay++;
  98. repaint();
  99. if( delay ==10){
  100. appleDelay = false;
  101. }
  102. } catch (InterruptedException e) {
  103. e.printStackTrace();
  104. }
  105. }
  106. }
  107. }
Created by GeSHI 1.0.7.20
Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
Javaforums.net :: a community about Java software development.
« on: June 29, 2008, 10:01:28 AM »

 Logged
lokesh05
Member
*

Reputation: 0
Offline Offline
Gender: Male
Posts: 32
Referrals: 0

Awards
« Reply #1 on: July 07, 2008, 06:11:46 AM »

Thanks for the code! That's real cool logic!
Logged
Javaforums.net :: a community about Java software development.
   

Your Ad Here
 Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.10 | SMF © 2006-2009, Simple Machines LLC
TinyPortal v0.9.8 © Bloc
Valid XHTML 1.0! Valid CSS!
Page created in 0.356 seconds with 33 queries.

Google visited last this page September 01, 2010, 12:14:13 PM