473,396 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

caterpillar application help!

Hi,

I am currently taking a Java Programming course and the assignment is to create an application (or applet) in which a caterpillar or any other type of bug goes up a set of steps. If anyone can help me out with some code, advice, etc, that would be very VERY helpful.

Thank you,
NewJack
Oct 31 '06 #1
10 1784
r035198x
13,262 8TB
Hi,

I am currently taking a Java Programming course and the assignment is to create an application (or applet) in which a caterpillar or any other type of bug goes up a set of steps. If anyone can help me out with some code, advice, etc, that would be very VERY helpful.

Thank you,
NewJack
And what have you done so far.
Nov 1 '06 #2
I have already finished an application in which the caterpillar slinks down a set of stairs. I just need to make a different type of bug go UP the set. I'm having a lot of trouble with it so any help would be great.
Nov 1 '06 #3
r035198x
13,262 8TB
I have already finished an application in which the caterpillar slinks down a set of stairs. I just need to make a different type of bug go UP the set. I'm having a lot of trouble with it so any help would be great.
Since you have already done a lot concerning this, it would be unfair to want people to help you by starting from scratch. Perhaps you can post what you have where you are stuck so that those helping can start from there otherwise we would all start it in a different way from the way you had already done it.
Nov 1 '06 #4
Allright, here's what I have so far...it's the lines of code to draw the set of stairs and that's where I need help at, in drawing the bug and moving it up the stairs..

import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JApplet;

public class Test extends JApplet
{
public void paint (Graphics g)
{
//stairs
g.setColor(Color.BLACK);
g.drawLine(0,90,90,90);
g.drawLine(90,90,90,180);
g.drawLine(90,180,180,180);
g.drawLine(180,180,180,270);
g.drawLine(180,270,270,270);
}
void marcsPause(long ms)
{

try
{
Thread.sleep(ms);
}
catch(InterruptedException e) {}

}

}
Nov 1 '06 #5
any suggestions?
Nov 2 '06 #6
r035198x
13,262 8TB
any suggestions?
O sorry about that. I think all you need to do is change the one you have a little to get the desired effect. The principles are still the same. So if you can post the one where you have the bug moving down ...
Nov 2 '06 #7
Yeah, I will post the original, it may take me some time b/c it is pretty long, but I'll have it up soon, thanks 4 your help.
Nov 2 '06 #8
here's the orignal in its entirety...

import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JApplet;

public class Worms extends JApplet
{
int y = 0;

public void paint(Graphics g)

{ //stairs
g.setColor(Color.BLUE);
g.drawLine(0,90,90,90);
g.drawLine(90,90,90,180);
g.drawLine(90,180,180,180);
g.drawLine(180,180,180,270);
g.drawLine(180,270,270,270);

//drawred1
for(int x = 0; x < 30; x = x + 30)
{
y = 60;
drawMyOvalred( g, x);
marcsPause(200);
}

showStatus("Come on little guy, you can do it!");

//drawgreen1
for(int x = 30; x < 60; x = x + 30)
{
y = 60;
drawMyOvalgreen( g, x);
marcsPause(200);
}

//drawblue1
for(int x = 60; x < 90; x = x + 30)
{
y = 60;
drawMyOvalblue( g, x);
marcsPause(200);
}

//erase red 2
for(int x = 90; x < 120; x = x + 30)
{
y = 60;
drawMyOvalred( g, x);
marcsPause(200);
}

//draw red1
for(int x = 0; x < 30; x = x + 30)
{
y = 60;
eraseMyOval( g, x);
marcsPause(200);
}
//erase green 2
for(int x = 90; x < 120; x = x + 30)
{
y = 90;
drawMyOvalgreen( g, x);
marcsPause(200);

}

//draw green 1
for(int x = 30; x < 60; x = x + 30)
{
y = 60;
eraseMyOval( g, x);
marcsPause(200);
}
//erase blue 2
for(int x = 90; x < 120; x = x + 30)
{
y = 120;
drawMyOvalblue( g, x);
marcsPause(200);
}
//draw blue 1
for(int x = 60; x < 90; x = x + 30)
{
y = 60;
eraseMyOval( g, x);
marcsPause(200);
}
//erase red 3
for(int x = 90; x < 120; x = x + 30)
{
y = 150;
drawMyOvalred( g, x);
marcsPause(200);
}
//draw red 2
for(int x = 90; x < 120; x = x + 30)
{
y = 60;
eraseMyOval( g, x);
marcsPause(200);
}
//erase green 3
for(int x = 120; x < 150; x = x + 30)
{
y = 150;
drawMyOvalgreen( g, x);
marcsPause(200);
}
//draw green 2
for(int x = 90; x < 120; x = x + 30)
{
y = 90;
eraseMyOval( g, x);
marcsPause(200);
}
//erase blue 3
for(int x = 150; x < 180; x = x + 30)
{
y = 150;
drawMyOvalblue( g, x);
marcsPause(200);
}
//draw blue 2
for(int x = 90; x < 120; x = x + 30)
{
y = 120;
eraseMyOval( g, x);
marcsPause(200);
}
//erase red 4
for(int x = 180; x < 210; x = x + 30)
{
y = 150;
drawMyOvalred( g, x);
marcsPause(200);
}
//draw red 3
for(int x = 90; x < 120; x = x + 30)
{
y = 150;
eraseMyOval( g, x);
marcsPause(200);
}
//erase green 4
for(int x = 180; x < 210; x = x + 30)
{
y = 180;
drawMyOvalgreen( g, x);
marcsPause(200);
}
//draw green 3
for(int x = 120; x < 150; x = x + 30)
{
y = 150;
eraseMyOval( g, x);
marcsPause(200);
}
//erase blue 4
for(int x = 180; x < 210; x = x + 30)
{
y = 210;
drawMyOvalblue( g, x);
marcsPause(200);
}
//draw blue 3
for(int x = 150; x < 180; x = x + 30)
{
y = 150;
eraseMyOval( g, x);
marcsPause(200);
}
//erase red 5
for(int x = 180; x < 210; x = x + 30)
{
y = 240;
drawMyOvalred( g, x);
marcsPause(200);
}
//draw red 4
for(int x = 180; x < 210; x = x + 30)
{
y = 150;
eraseMyOval( g, x);
marcsPause(200);
}
//erase green 5
for(int x = 210; x < 240; x = x + 30)
{
y = 240;
drawMyOvalgreen( g, x);
marcsPause(200);
}
//draw green 4
for(int x = 180; x < 210; x = x + 30)
{
y = 180;
eraseMyOval( g, x);
marcsPause(200);
}
//erase blue 5
for(int x = 240; x < 270; x = x + 30)
{
y = 240;
drawMyOvalblue( g, x);
marcsPause(200);
}
//draw blue 4
for(int x = 180; x < 210; x = x + 30)
{
y = 210;
eraseMyOval( g, x);
marcsPause(200);
}

showStatus("Ta-Da!");

//draw red 6
for(int x = 240; x < 270; x = x + 30)
{
y = 210;
drawMyOvalred( g, x);
drawMyLeftExe( g, x);
drawMyRightExe( g, x);
drawMySmile( g, x);
marcsPause(200);
}



}

public void drawMyOvalred (Graphics g, int x)
{
//yellow circle
g.setColor(Color.YELLOW);
g.fillOval(x,y,30,30);
g.drawOval(x,y,30,30);

}
public void drawMyOvalgreen (Graphics g, int x)
{
//black circle
g.setColor(Color.BLACK);
g.fillOval(x,y,30,30);
g.drawOval(x,y,30,30);

}
public void drawMyOvalblue (Graphics g, int x)
{
//green circle
g.setColor(Color.GREEN);
g.fillOval(x,y,30,30);
g.drawOval(x,y,30,30);

}

public void drawMyLeftExe (Graphics g, int x)
{
//draw exe, blue circle
g.setColor(Color.BLUE);
g.fillOval(x + 10,y + 10,1,1);
g.drawOval(x + 10,y + 10,1,1);

}
public void drawMyRightExe (Graphics g, int x)
{
//draw exe, blue circle
g.setColor(Color.BLUE);
g.fillOval(x + 20,y + 10,1,1);
g.drawOval(x + 20,y + 10,1,1);

}
public void drawMySmile (Graphics g, int x)
{
//draw smile, red line
g.setColor(Color.RED);
g.drawLine(250,230,260,230);

}

public void eraseMyOval (Graphics g, int x)
{
//white circle
g.setColor(Color.WHITE);
g.fillOval(x,y,30,30);
g.drawOval(x,y,30,30);

}


void marcsPause(long ms)
{

try
{
Thread.sleep(ms);
}
catch(InterruptedException e) {}

}

}
Nov 3 '06 #9
r035198x
13,262 8TB
here's the orignal in its entirety...

import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JApplet;

public class Worms extends JApplet
{
int y = 0;

public void paint(Graphics g)

{ //stairs
g.setColor(Color.BLUE);
g.drawLine(0,90,90,90);
g.drawLine(90,90,90,180);
g.drawLine(90,180,180,180);
g.drawLine(180,180,180,270);
g.drawLine(180,270,270,270);

//drawred1
for(int x = 0; x < 30; x = x + 30)
{
y = 60;
drawMyOvalred( g, x);
marcsPause(200);
}

showStatus("Come on little guy, you can do it!");

//drawgreen1
for(int x = 30; x < 60; x = x + 30)
{
y = 60;
drawMyOvalgreen( g, x);
marcsPause(200);
}

//drawblue1
for(int x = 60; x < 90; x = x + 30)
{
y = 60;
drawMyOvalblue( g, x);
marcsPause(200);
}

//erase red 2
for(int x = 90; x < 120; x = x + 30)
{
y = 60;
drawMyOvalred( g, x);
marcsPause(200);
}

//draw red1
for(int x = 0; x < 30; x = x + 30)
{
y = 60;
eraseMyOval( g, x);
marcsPause(200);
}
//erase green 2
for(int x = 90; x < 120; x = x + 30)
{
y = 90;
drawMyOvalgreen( g, x);
marcsPause(200);

}

//draw green 1
for(int x = 30; x < 60; x = x + 30)
{
y = 60;
eraseMyOval( g, x);
marcsPause(200);
}
//erase blue 2
for(int x = 90; x < 120; x = x + 30)
{
y = 120;
drawMyOvalblue( g, x);
marcsPause(200);
}
//draw blue 1
for(int x = 60; x < 90; x = x + 30)
{
y = 60;
eraseMyOval( g, x);
marcsPause(200);
}
//erase red 3
for(int x = 90; x < 120; x = x + 30)
{
y = 150;
drawMyOvalred( g, x);
marcsPause(200);
}
//draw red 2
for(int x = 90; x < 120; x = x + 30)
{
y = 60;
eraseMyOval( g, x);
marcsPause(200);
}
//erase green 3
for(int x = 120; x < 150; x = x + 30)
{
y = 150;
drawMyOvalgreen( g, x);
marcsPause(200);
}
//draw green 2
for(int x = 90; x < 120; x = x + 30)
{
y = 90;
eraseMyOval( g, x);
marcsPause(200);
}
//erase blue 3
for(int x = 150; x < 180; x = x + 30)
{
y = 150;
drawMyOvalblue( g, x);
marcsPause(200);
}
//draw blue 2
for(int x = 90; x < 120; x = x + 30)
{
y = 120;
eraseMyOval( g, x);
marcsPause(200);
}
//erase red 4
for(int x = 180; x < 210; x = x + 30)
{
y = 150;
drawMyOvalred( g, x);
marcsPause(200);
}
//draw red 3
for(int x = 90; x < 120; x = x + 30)
{
y = 150;
eraseMyOval( g, x);
marcsPause(200);
}
//erase green 4
for(int x = 180; x < 210; x = x + 30)
{
y = 180;
drawMyOvalgreen( g, x);
marcsPause(200);
}
//draw green 3
for(int x = 120; x < 150; x = x + 30)
{
y = 150;
eraseMyOval( g, x);
marcsPause(200);
}
//erase blue 4
for(int x = 180; x < 210; x = x + 30)
{
y = 210;
drawMyOvalblue( g, x);
marcsPause(200);
}
//draw blue 3
for(int x = 150; x < 180; x = x + 30)
{
y = 150;
eraseMyOval( g, x);
marcsPause(200);
}
//erase red 5
for(int x = 180; x < 210; x = x + 30)
{
y = 240;
drawMyOvalred( g, x);
marcsPause(200);
}
//draw red 4
for(int x = 180; x < 210; x = x + 30)
{
y = 150;
eraseMyOval( g, x);
marcsPause(200);
}
//erase green 5
for(int x = 210; x < 240; x = x + 30)
{
y = 240;
drawMyOvalgreen( g, x);
marcsPause(200);
}
//draw green 4
for(int x = 180; x < 210; x = x + 30)
{
y = 180;
eraseMyOval( g, x);
marcsPause(200);
}
//erase blue 5
for(int x = 240; x < 270; x = x + 30)
{
y = 240;
drawMyOvalblue( g, x);
marcsPause(200);
}
//draw blue 4
for(int x = 180; x < 210; x = x + 30)
{
y = 210;
eraseMyOval( g, x);
marcsPause(200);
}

showStatus("Ta-Da!");

//draw red 6
for(int x = 240; x < 270; x = x + 30)
{
y = 210;
drawMyOvalred( g, x);
drawMyLeftExe( g, x);
drawMyRightExe( g, x);
drawMySmile( g, x);
marcsPause(200);
}



}

public void drawMyOvalred (Graphics g, int x)
{
//yellow circle
g.setColor(Color.YELLOW);
g.fillOval(x,y,30,30);
g.drawOval(x,y,30,30);

}
public void drawMyOvalgreen (Graphics g, int x)
{
//black circle
g.setColor(Color.BLACK);
g.fillOval(x,y,30,30);
g.drawOval(x,y,30,30);

}
public void drawMyOvalblue (Graphics g, int x)
{
//green circle
g.setColor(Color.GREEN);
g.fillOval(x,y,30,30);
g.drawOval(x,y,30,30);

}

public void drawMyLeftExe (Graphics g, int x)
{
//draw exe, blue circle
g.setColor(Color.BLUE);
g.fillOval(x + 10,y + 10,1,1);
g.drawOval(x + 10,y + 10,1,1);

}
public void drawMyRightExe (Graphics g, int x)
{
//draw exe, blue circle
g.setColor(Color.BLUE);
g.fillOval(x + 20,y + 10,1,1);
g.drawOval(x + 20,y + 10,1,1);

}
public void drawMySmile (Graphics g, int x)
{
//draw smile, red line
g.setColor(Color.RED);
g.drawLine(250,230,260,230);

}

public void eraseMyOval (Graphics g, int x)
{
//white circle
g.setColor(Color.WHITE);
g.fillOval(x,y,30,30);
g.drawOval(x,y,30,30);

}


void marcsPause(long ms)
{

try
{
Thread.sleep(ms);
}
catch(InterruptedException e) {}

}

}
Just looking at your code now. Shouldn't take long...
Nov 4 '06 #10
r035198x
13,262 8TB
Expand|Select|Wrap|Line Numbers
  1.  
  2. import java.awt.Color;
  3. import java.awt.Graphics;
  4. import javax.swing.JApplet;
  5. public class Worms1 extends JApplet
  6. {
  7. int y = 0;
  8. public void paint(Graphics g) 
  9. { //stairs
  10. g.setColor(Color.BLUE);
  11. g.drawLine(0,90,90,90);
  12. g.drawLine(90,90,90,180);
  13. g.drawLine(90,180,180,180);
  14. g.drawLine(180,180,180,270);
  15. g.drawLine(180,270,270,270);
  16. //drawred1
  17. showStatus("Come on little guy, you can do it!");
  18. for(int x = 240; x < 270; x = x + 30)
  19. {
  20. y = 240;
  21. drawMyOvalred( g, x);
  22. marcsPause(200);
  23. }
  24.  
  25. //drawgreen1
  26. for(int x = 210; x < 240; x = x + 30)
  27. {
  28. y = 240;
  29. drawMyOvalgreen( g, x);
  30. marcsPause(200);
  31. }
  32. //drawblue1
  33. for(int x = 180; x < 210; x = x + 30)
  34. {
  35. y = 240;
  36. drawMyOvalblue( g, x);
  37. marcsPause(200);
  38. }
  39. //erase red 2
  40. for(int x = 180; x < 210; x = x + 30)
  41. {
  42. y = 210;
  43. drawMyOvalred( g, x);
  44. marcsPause(200);
  45. }
  46. //draw red1
  47. for(int x = 240; x < 270; x = x + 30)
  48. {
  49. y = 240;
  50. eraseMyOval( g, x);
  51. marcsPause(200);
  52. }
  53.  
  54. //erase green 2
  55. for(int x = 180; x < 210; x = x + 30)
  56. {
  57. y = 180;
  58. drawMyOvalgreen( g, x);
  59. marcsPause(200);
  60. }
  61.  
  62. for(int x = 210; x < 240; x = x + 30)
  63. {
  64. y = 240;
  65. eraseMyOval( g, x);
  66. marcsPause(200);
  67. }
  68. for(int x = 180; x < 210; x = x + 30)
  69. {
  70. y = 150;
  71. drawMyOvalblue( g, x);
  72. marcsPause(200);
  73. }
  74.  
  75. for(int x = 180; x < 210; x = x + 30)
  76. {
  77. y = 240;
  78. eraseMyOval( g, x);
  79. marcsPause(200);
  80. }
  81.  
  82. for(int x = 150; x < 180; x = x + 30)
  83. {
  84. y = 150;
  85. drawMyOvalred( g, x);
  86. marcsPause(200);
  87. }
  88.  
  89. for(int x = 180; x < 210; x = x + 30)
  90. {
  91. y = 210;
  92. eraseMyOval( g, x);
  93. marcsPause(200);
  94. }
  95.  
  96. for(int x = 120; x < 150; x = x + 30)
  97. {
  98. y = 150;
  99. drawMyOvalgreen( g, x);
  100. marcsPause(200);
  101. }
  102.  
  103. for(int x = 180; x < 210; x = x + 30)
  104. {
  105. y = 180;
  106. eraseMyOval( g, x);
  107. marcsPause(200);
  108. }
  109. for(int x = 180; x < 210; x = x + 30)
  110. {
  111. y = 150;
  112. drawMyOvalblue( g, x);
  113. marcsPause(200);
  114. }
  115.  
  116. showStatus("Ta-Da!");
  117. //draw red 6
  118. //for(int x = 240; x < 270; x = x + 30)
  119. //{
  120. //y = 210;
  121. //drawMyOvalred( g, x);
  122. //drawMyLeftExe( g, x);
  123. //drawMyRightExe( g, x);
  124. //drawMySmile( g, x);
  125. //marcsPause(200);
  126. //}
  127.  
  128. }
  129. public void drawMyOvalred (Graphics g, int x)
  130. {
  131. g.setColor(Color.RED);
  132. g.fillOval(x,y,30,30);
  133. g.drawOval(x,y,30,30);
  134. }
  135. public void drawMyOvalgreen (Graphics g, int x)
  136. {
  137. g.setColor(Color.GREEN);
  138. g.fillOval(x,y,30,30);
  139. g.drawOval(x,y,30,30);
  140. }
  141. public void drawMyOvalblue (Graphics g, int x)
  142. {
  143. g.setColor(Color.BLUE);
  144. g.fillOval(x,y,30,30);
  145. g.drawOval(x,y,30,30);
  146. }
  147. public void drawMyLeftExe (Graphics g, int x)
  148. {
  149. //draw exe, blue circle
  150. g.setColor(Color.BLUE);
  151. g.fillOval(x + 10,y + 10,1,1);
  152. g.drawOval(x + 10,y + 10,1,1);
  153. }
  154. public void drawMyRightExe (Graphics g, int x)
  155. {
  156. //draw exe, blue circle
  157. g.setColor(Color.BLUE);
  158. g.fillOval(x + 20,y + 10,1,1);
  159. g.drawOval(x + 20,y + 10,1,1);
  160. }
  161. public void drawMySmile (Graphics g, int x)
  162. {
  163. //draw smile, red line
  164. g.setColor(Color.RED);
  165. g.drawLine(250,230,260,230);
  166. }
  167. public void eraseMyOval (Graphics g, int x)
  168. {
  169. //white circle
  170. g.setColor(Color.WHITE);
  171. g.fillOval(x,y,30,30);
  172. g.drawOval(x,y,30,30);
  173. }
  174.  
  175. void marcsPause(long ms)
  176. {
  177. try
  178. {
  179. Thread.sleep(ms);
  180. }
  181. catch(InterruptedException e) {}
  182. }
  183. }
  184.  
  185.  
I suppose you can finish it off from here. May I point out the approach may have been improved by using arrays somewhere in there to reduce the for loops. If you need to have the bugs on the same applet, you would need to add a boolean flag, say goingUp, and put an if else on the fors to execute.
Nov 4 '06 #11

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

Similar topics

12
by: serge calderara | last post by:
Dear all, I have an application which is suppose to start another executable process. As soon as that process is running, I need to retrive its handle. The problem of the particular process I am...
11
by: Timothy Shih | last post by:
Hi, I am having a freezing issue with my application. My application serves several remotable objects, all of which must be initialized before their use. Furthermore, some of them depend on each...
4
by: Dave | last post by:
I need to add the ability to drag from a Windows Form and drop into a non dotNet application. For example, having a generated image in my app that I wish to drag out into explorer as a friendly way...
9
by: Rajat Tandon | last post by:
Hello there, I am relatively new to the newsgroups and C#. I have never been disappointed with the groups and always got the prompt replies to my queries.This is yet another strange issue, I am...
9
by: Graham | last post by:
I have been having some fun learning and using the new Controls and methods in .Net 2.0 which will make my life in the future easier and faster. Specifically the new databinding practises and...
1
by: Alain \Mbuna\ | last post by:
Hi to you all. As a beginning programmer, I finally succeeded in finishing my first application. I made the application with VB expr 2005 and provided the application with a help project, which...
1
by: G Gerard | last post by:
Hello I have written some help files using Html Help Workshop version 4.74.8702 I use the following code to launch the chm file Declare Function HtmlHelp Lib "HHCtrl.ocx" Alias "HtmlHelpA" _...
1
by: abhijitbkulkarni | last post by:
Hello, I am designing a .NET database application that uses 3 tier architecture. Starting initially, this application will be desktop application but I will convert it into a website later but...
0
by: hitencontractor | last post by:
I am working on .NET Version 2003 making an SDI application that calls MS Excel 2003. I added a menu item called "MyApp Help" in the end of the menu bar to show Help-> About. The application...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...
0
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...
0
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...

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.