Unfortunately I deleted my test application to see if I can do it as constructors and call to the methods to add into the main JApplet. It didn't work. I have tried to do it all in one app but I screwed up massively.
If anyone has addvice on which direction I need to be headed I would really appreciate it. I have been working in jgrasp and don't know how to set all this up in NB yet. I want to finish this exam before taking on NB.
Thank you!!!
Below is the *.java files to view. I am only uploading walker 1 since the only difference between the three are color (black, red, blue), and sleep (400, 200, 100).
This is the walker (3 of them but different colors as stated above)
import java.applet.*;
import java.awt.*;
import javax.swing.*;
public class Walker1 extends Applet
{
private int index = 0;
private int horizmove = 0;
int[] Ahoriz = {20,30,40,50,40,30,20};
int[] Ahoriz2 = {60,50,40,30,40,50,60};
int[] Avert = {120, 110, 100, 90, 80, 90, 100, 110, 120};
private int sleep = 400;
public void paint(Graphics gr)
{
gr.setColor(Color.black);
gr.drawOval(20 + horizmove, 20, 40, 40);
gr.drawLine(40 + horizmove, 60, 40 + horizmove, 120);
gr.drawLine(40 + horizmove,120,Ahoriz[index] + horizmove,160);
gr.drawLine(40 + horizmove,120,Ahoriz2[index] + horizmove,160);
gr.setColor(Color.WHITE);
++index;
++horizmove;
repaint();
if(index == Ahoriz.length)
index = 0;
if(horizmove == 600)
horizmove = 0;
try
{
Thread.sleep(sleep);
}
catch(InterruptedException e)
{
}
repaint();
}
}
This is the failed attempt to have all three in one file(*WARNING:It is very messy: * lol)
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Walkathon extends JApplet implements ActionListener, Runnable
{
public static void Walkathon()
{
JCheckBox guy1 = new JCheckBox("1 Walker");
JCheckBox guy2 = new JCheckBox("2 Walkers");
JCheckBox guy3 = new JCheckBox("3 Walkers");
}
public void init()
{
Container con = getContentPane();
con.setVisible(true);
con.setSize(600,200);
con.setBackground(Color.WHITE);
con.setLayout(new BorderLayout());
con.add(guy1);
con.add(guy2);
con.add(guy3);
guy1.addActionLisenter(this);
guy2.addActionLisenter(this);
guy3.addActionLisenter(this);
}
public void actionPerformed(ActionEvent e, Graphics gr)
{
int[] Ahoriz = {20,30,40,50,40,30,20};
int[] Ahoriz2 = {60,50,40,30,40,50,60};
int[] Avert = {120, 110, 100, 90, 80, 90, 100, 110, 120};
int sleep1 = 400;
int sleep2 = 200;
int sleep3 = 100;
int index = 0;
int horizmove = 0;
Object source = e.getSource();
if(source == guy3)
{
gr.setColor(Color.black);
gr.drawOval(20 + horizmove, 20, 40, 40);
gr.drawLine(40 + horizmove, 60, 40 + horizmove, 120);
gr.drawLine(40 + horizmove,120,Ahoriz[index] + horizmove,160);
gr.drawLine(40 + horizmove,120,Ahoriz2[index] + horizmove,160);
gr.setColor(Color.WHITE);
++index;
++horizmove;
repaint();
if(index == Ahoriz.length)
index = 0;
if(horizmove == 600)
horizmove = 0;
try
{
Thread.sleep(sleep1);
}
catch(InterruptedException e1)
{
}
gr.setColor(Color.RED);
gr.drawOval(20 + horizmove, 20, 40, 40);
gr.drawLine(40 + horizmove, 60, 40 + horizmove, 120);
gr.drawLine(40 + horizmove,120,Ahoriz[index] + horizmove,160);
gr.drawLine(40 + horizmove,120,Ahoriz2[index] + horizmove,160);
gr.setColor(Color.WHITE);
++index;
++horizmove;
repaint();
if(index == Ahoriz.length)
index = 0;
if(horizmove == 600)
horizmove = 0;
try
{
Thread.sleep(sleep2);
}
catch(InterruptedException e2)
{
}
gr.setColor(Color.BLUE);
gr.drawOval(20 + horizmove, 20, 40, 40);
gr.drawLine(40 + horizmove, 60, 40 + horizmove, 120);
gr.drawLine(40 + horizmove,120,Ahoriz[index] + horizmove,160);
gr.drawLine(40 + horizmove,120,Ahoriz2[index] + horizmove,160);
gr.setColor(Color.WHITE);
++index;
++horizmove;
repaint();
if(index == Ahoriz.length)
index = 0;
if(horizmove == 600)
horizmove = 0;
try
{
Thread.sleep(sleep3);
}
catch(InterruptedException e3)
{
}
repaint();
}
if(source == guy2)
{
gr.setColor(Color.black);
gr.drawOval(20 + horizmove, 20, 40, 40);
gr.drawLine(40 + horizmove, 60, 40 + horizmove, 120);
gr.drawLine(40 + horizmove,120,Ahoriz[index] + horizmove,160);
gr.drawLine(40 + horizmove,120,Ahoriz2[index] + horizmove,160);
gr.setColor(Color.WHITE);
++index;
++horizmove;
repaint();
if(index == Ahoriz.length)
index = 0;
if(horizmove == 600)
horizmove = 0;
try
{
Thread.sleep(sleep1);
}
catch(InterruptedException e5)
{
}
gr.setColor(Color.RED);
gr.drawOval(20 + horizmove, 20, 40, 40);
gr.drawLine(40 + horizmove, 60, 40 + horizmove, 120);
gr.drawLine(40 + horizmove,120,Ahoriz[index] + horizmove,160);
gr.drawLine(40 + horizmove,120,Ahoriz2[index] + horizmove,160);
gr.setColor(Color.WHITE);
++index;
++horizmove;
repaint();
if(index == Ahoriz.length)
index = 0;
if(horizmove == 600)
horizmove = 0;
try
{
Thread.sleep(sleep2);
}
catch(InterruptedException e6)
{
}
repaint();
}
else
{
gr.setColor(Color.black);
gr.drawOval(20 + horizmove, 20, 40, 40);
gr.drawLine(40 + horizmove, 60, 40 + horizmove, 120);
gr.drawLine(40 + horizmove,120,Ahoriz[index] + horizmove,160);
gr.drawLine(40 + horizmove,120,Ahoriz2[index] + horizmove,160);
gr.setColor(Color.WHITE);
++index;
++horizmove;
repaint();
if(index == Ahoriz.length)
index = 0;
if(horizmove == 600)
horizmove = 0;
try
{
Thread.sleep(sleep1);
}
catch(InterruptedException e8)
{
}
repaint();
}
}
}
thank you again in advance for any help offered on which direction I need to go. please remember - this is an exam so I don't want anyone doing my work for me. I have gotten this far with 95% average (and it is beyond me how) I would like to keep it that way.
in the second sett of code, the public static void walkathon() was testing it. It wasn't meant to stay in at that position.

New Topic/Question
Reply




MultiQuote








|