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
10 1784
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.
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.
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.
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) {}
}
}
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 ...
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.
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) {}
}
}
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...
-
-
import java.awt.Color;
-
import java.awt.Graphics;
-
import javax.swing.JApplet;
-
public class Worms1 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
-
showStatus("Come on little guy, you can do it!");
-
for(int x = 240; x < 270; x = x + 30)
-
{
-
y = 240;
-
drawMyOvalred( g, x);
-
marcsPause(200);
-
}
-
-
//drawgreen1
-
for(int x = 210; x < 240; x = x + 30)
-
{
-
y = 240;
-
drawMyOvalgreen( g, x);
-
marcsPause(200);
-
}
-
//drawblue1
-
for(int x = 180; x < 210; x = x + 30)
-
{
-
y = 240;
-
drawMyOvalblue( g, x);
-
marcsPause(200);
-
}
-
//erase red 2
-
for(int x = 180; x < 210; x = x + 30)
-
{
-
y = 210;
-
drawMyOvalred( g, x);
-
marcsPause(200);
-
}
-
//draw red1
-
for(int x = 240; x < 270; x = x + 30)
-
{
-
y = 240;
-
eraseMyOval( g, x);
-
marcsPause(200);
-
}
-
-
//erase green 2
-
for(int x = 180; x < 210; x = x + 30)
-
{
-
y = 180;
-
drawMyOvalgreen( g, x);
-
marcsPause(200);
-
}
-
-
for(int x = 210; x < 240; x = x + 30)
-
{
-
y = 240;
-
eraseMyOval( g, x);
-
marcsPause(200);
-
}
-
for(int x = 180; x < 210; x = x + 30)
-
{
-
y = 150;
-
drawMyOvalblue( g, x);
-
marcsPause(200);
-
}
-
-
for(int x = 180; x < 210; x = x + 30)
-
{
-
y = 240;
-
eraseMyOval( g, x);
-
marcsPause(200);
-
}
-
-
for(int x = 150; x < 180; x = x + 30)
-
{
-
y = 150;
-
drawMyOvalred( g, x);
-
marcsPause(200);
-
}
-
-
for(int x = 180; x < 210; x = x + 30)
-
{
-
y = 210;
-
eraseMyOval( g, x);
-
marcsPause(200);
-
}
-
-
for(int x = 120; x < 150; x = x + 30)
-
{
-
y = 150;
-
drawMyOvalgreen( g, x);
-
marcsPause(200);
-
}
-
-
for(int x = 180; x < 210; x = x + 30)
-
{
-
y = 180;
-
eraseMyOval( g, x);
-
marcsPause(200);
-
}
-
for(int x = 180; x < 210; x = x + 30)
-
{
-
y = 150;
-
drawMyOvalblue( 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)
-
{
-
g.setColor(Color.RED);
-
g.fillOval(x,y,30,30);
-
g.drawOval(x,y,30,30);
-
}
-
public void drawMyOvalgreen (Graphics g, int x)
-
{
-
g.setColor(Color.GREEN);
-
g.fillOval(x,y,30,30);
-
g.drawOval(x,y,30,30);
-
}
-
public void drawMyOvalblue (Graphics g, int x)
-
{
-
g.setColor(Color.BLUE);
-
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) {}
-
}
-
}
-
-
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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" _...
|
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...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
| |