Need a lot of advice on an applet

JApplet vs. applet need 3 walkers w/checkbox options

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 6260 Views - Last Post: 21 June 2010 - 03:58 PM Rate Topic: -----

#1 laehm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 20-May 10

Need a lot of advice on an applet

Posted 24 May 2010 - 10:56 AM

To let everyone know, this is an exam and I don't expect you to do my homework. I, however, need advice on how to get 3 walkers with 3 different speeds & color set into one JApplet using checkboxes to select 1 walker, 2 walkers, or 3 walkers. I have been working on this for 2 days and I am stuck on how to add them. I created the walkers but if I do it in JApplet the previous lines don't repaint in white and I can't seem to get the checkboxes to work.

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.

Is This A Good Question/Topic? 0
  • +

Replies To: Need a lot of advice on an applet

#2 laehm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 20-May 10

Re: Need a lot of advice on an applet

Posted 24 May 2010 - 11:22 AM

I found many errors in the last one I added. Here is the updated. It compiles but doesn't run properly.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


public class Walkathon extends JApplet implements ActionListener
{
	
//		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.addActionListener(this);
		guy2.addActionListener(this);
		guy3.addActionListener(this);
	
	}
	public void actionPerformed(ActionEvent e)
	{
		Graphics gr = getGraphics();
		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();
			
			}
	}

}





Was This Post Helpful? 0
  • +
  • -

#3 eker676  Icon User is offline

  • Software Engineer
  • member icon

Reputation: 378
  • View blog
  • Posts: 1,833
  • Joined: 18-April 09

Re: Need a lot of advice on an applet

Posted 24 May 2010 - 12:29 PM

Instead of trying to clear the last lines you could paint a rectangle over the entire screen using a default color.

That will take care of the line clearing problem.

Another method would be to hold the lines in an array and when you call the paint method just iterate through the array.

Are you trying to get the "walkers" to move across the screen? The simplest way would probably be to use a properly configured for loop to add the the lines. Clear the screen, paint the new lines, wait X milliseconds depending on the walker, then repeat until the guy moves across the screen.
Was This Post Helpful? 0
  • +
  • -

#4 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2858
  • View blog
  • Posts: 10,962
  • Joined: 15-July 08

Re: Need a lot of advice on an applet

Posted 24 May 2010 - 01:24 PM

Quote

I have tried to do it all in one app but I screwed up massively.


I assume you mean 1 file? WHY?! Java is object oriented and you should take advantage of this. Encapsulation and possible abstraction are going to be very useful to you in this program. I would make 3 files with 3 classes.
1) GameApplet extends JApplet - This really doesn't do much except sit there and look pretty.
2) GamePanel extends JPanel - Add this to the JApplet and control all the painting, updating, and controlling of the next object.
3) Walker - This class holds the x and y locations, it holds the image of the walker and the x and y speeds. What I typically do is provide a move() method that increments the speed to the location and a draw(Graphics g) method that uses the draw method to paint itself.

As for the frame rate, I haven't looked at how you have implemented it, but you should not use threads as Swing is not thread safe. However, you can utilize a javax.swing.Timer object to control the repainting.

Now, here are the class skeletons:
public class GameApplet extends JApplet {
    public void init() {
        add(new GamePanel());
    }
    ...
}



public class GamePanel extends JPanel {
    private Walker[] walkers = new Walker[3];

    public GamePanel() {
        ... Add the walkers with location, images, speeds...
        ... Set up your event listeners...
        // Set up the timer to update and repaint every 16 milliseconds
        Timer time = new Timer(16, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                update();
                repaint(); // Eventually calls the paintComponent() method.
            }
        }
        time.start();
    }
 
    private void update() {
        ... move the walkers around ...
    }
 
    public void actionPerformed(Graphics g) {
        ... Draw Background ...
        // Now draw all the walkers.
        for (Walker w : walkers) {
            w.draw(g);
    }
}



Now, finally, set up the Walker class that manages itself.
public class Walker {
    private int x, y;
    private int xSpeed, ySpeed;
    private BufferedImage image;

    public Walker(int x, int y, int xSpeed, int ySpeed, String imageName) {
        this.x = x;
        ...
        ... Then load the image ...
    }

    // Increment the location by speed. To go the other way,
    // give speed a negative value.
    public void move() {
        x += xSpeed;
        y += ySpeed;
    }

    // Finally, this draws itself.
    public void draw(Graphics g) {
        ... use g.drawImage(); ...
    }
}



If you have any further questions or have any questions on how to do something I described, let us know ok?

This post has been edited by Dogstopper: 24 May 2010 - 01:25 PM
Reason for edit:: typo

Was This Post Helpful? 0
  • +
  • -

#5 laehm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 20-May 10

Re: Need a lot of advice on an applet

Posted 24 May 2010 - 01:37 PM

Yes, I meant 1 file. I inevitably say app, sorry about that. :oops:

I will take a look at that later today and reply if anything confuses me. I don't know how the swing Timer works so I will have to search tutorial & API for that one, lol. I just know that I don't like how they teach me to do things in applet but expect me to do it in JApplet. I know there are differences. Not many but enough to make my walker seem like it is "dragging" across the screen instead of walking. (take the single walker file and put extends JApplet instead of Applet). I'll figure it out sooner or later.....hopefully.

Thank you very much :)
Was This Post Helpful? 0
  • +
  • -

#6 laehm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 20-May 10

Re: Need a lot of advice on an applet

Posted 24 May 2010 - 01:44 PM

btw, I am using sleep() as the incremental.
Was This Post Helpful? 0
  • +
  • -

#7 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2858
  • View blog
  • Posts: 10,962
  • Joined: 15-July 08

Re: Need a lot of advice on an applet

Posted 24 May 2010 - 01:53 PM

Unfortunately sleep() is a method that uses Threads. It may not directly have an impact on this program, but you will run into this at some point. Concurrency in Swing is difficult and you cannot simply do it using Thread.sleep(). The easiest way is to use a Timer. I have a tutorial here on the subject:
http://www.dreaminco...e-rate-in-java/
Was This Post Helpful? 1
  • +
  • -

#8 laehm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 20-May 10

Re: Need a lot of advice on an applet

Posted 24 May 2010 - 10:00 PM

OK...after reading through tutorials a little I found that ":" is ternary, but I am not sure how that comes into play. I wiki'd it to get a basic description. I think my brain is numb or dead cause I got a little more confused on it's actual purpose.

My other confusion point is the walker[]...is that making 3 different walker classes (one for each walker) and then pulling all three into the JPanel class? I want to make sure I am following this correctly.

These are great skeletons for learning...but I think they might be a little too advanced for my stand point. My course was basics in java for web design.

I will keep studying this and hopefully it will click after I get my eye to stop twitching from working on this majority of the day, lol.

Thank you very much Dogstopper. I appreciate your help grealty. I will also take a look at your tutorial in hopes to make sense of all this, lol :)
Was This Post Helpful? 0
  • +
  • -

#9 laehm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 20-May 10

Re: Need a lot of advice on an applet

Posted 24 May 2010 - 10:10 PM

sorry for the transposed letters, I do it all the time.

I can almost guarantee if this was to be in flash I would have had it done on the first day of reading it.
Was This Post Helpful? 0
  • +
  • -

#10 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2858
  • View blog
  • Posts: 10,962
  • Joined: 15-July 08

Re: Need a lot of advice on an applet

Posted 25 May 2010 - 03:54 AM

View Postlaehm, on 25 May 2010 - 12:00 AM, said:

OK...after reading through tutorials a little I found that ":" is ternary, but I am not sure how that comes into play. I wiki'd it to get a basic description. I think my brain is numb or dead cause I got a little more confused on it's actual purpose.


If you mean this?
 for (Walker w : walkers) {


That means it grabs each walker from the walkers array and sticks it in the "w" variable... This make is very simple to quickly have access to the objects in the array.

Quote

My other confusion point is the walker[]...is that making 3 different walker classes (one for each walker) and then pulling all three into the JPanel class? I want to make sure I am following this correctly.


The Walker[] walkers = new Walker[3]; thing that you say was making space for three Walkers in the array. However, you still need to make a new Walker for each location.

Look into arrays: http://www.dreaminco...tion-to-arrays/

Quote

These are great skeletons for learning...but I think they might be a little too advanced for my stand point. My course was basics in java for web design.

I will keep studying this and hopefully it will click after I get my eye to stop twitching from working on this majority of the day, lol.

Thank you very much Dogstopper. I appreciate your help grealty. I will also take a look at your tutorial in hopes to make sense of all this, lol :)


Well, if they are too advanced, I'd look into class design and arrays for sure. Make sure you know about Collections: http://java.sun.com/...ions/index.html
Was This Post Helpful? 0
  • +
  • -

#11 laehm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 20-May 10

Re: Need a lot of advice on an applet

Posted 25 May 2010 - 07:54 AM

Yeah, that's what I did most of last night. I went to the tutorial and was reading about the arrays and collections. I'm going to re-read the collections to help get a better understanding of them (and do all the practices.) I was only taught about the single array not array[][]. That looks as if it would be a lot easier for a few things (not here). Either way, my exam will have to wait until I can learn a little more beyond the scopes of this textbook. Thanks again :)
Was This Post Helpful? 0
  • +
  • -

#12 laehm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 20-May 10

Re: Need a lot of advice on an applet

Posted 26 May 2010 - 11:54 AM

I have been going through this in my head and on paper & screen. I can't seem to get it all to work and "pass" into other files. Hopefully you know what I mean.

I started looking around for other ways to do this and have come across glass Panes. I think this would be an option as long as it has a transparent background so I can layer 2 or 3 panes on top of each other.

any takes on the use of glass Panes?
Was This Post Helpful? 0
  • +
  • -

#13 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2858
  • View blog
  • Posts: 10,962
  • Joined: 15-July 08

Re: Need a lot of advice on an applet

Posted 26 May 2010 - 03:11 PM

View Postlaehm, on 26 May 2010 - 01:54 PM, said:

I have been going through this in my head and on paper & screen. I can't seem to get it all to work and "pass" into other files. Hopefully you know what I mean.

I started looking around for other ways to do this and have come across glass Panes. I think this would be an option as long as it has a transparent background so I can layer 2 or 3 panes on top of each other.

any takes on the use of glass Panes?


In my game programming library that I am currently writing, there is a lot of passing classes to other classes. Like, right now I only have 4 classes (not even half done).

I have:
GSGame - the main class that is extended by the user
GSPanel - the drawing screen
GSSprite - Represents any image moving on screen
GSInputManager - Input...

Now, since all the methods the user interacts with are in GSGame, I pass a reference to the other three classes for settings/other.

So like this:
// Constructor
public GSGame() {
    GSPanel screen = new GSPanel(this);
}



For information on "this", look at 's tutorial: http://www.dreaminco...eyword-in-java/
Was This Post Helpful? 0
  • +
  • -

#14 laehm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 20-May 10

Re: Need a lot of advice on an applet

Posted 15 June 2010 - 11:55 PM

Sorry it took so long to reply. I am still working on how to get all three to work in the same applet but I finished my exam and turned it in getting a 100% with what I had. My instructor told me to just make 3 html files and do a link for each one with one, two, or three walkers. Everything was set the same way so it didn't look like it was changing to another page at all. It all worked but I am still working hard at getting this to work in my spare time. It is a really good lesson for me and helping me understand Java a little bit better.

I am also working on a way to convert text to ASCII. Except is has to have each character in it's own text box. Basically having "R" in a box and below three boxes containing the ASCII code with one digit in each one. It's simple conversion but trying to figure out how to get it all to come out correctly without typing 12 pages of code is the pain, lol. I think I have a solid work-a-round but it is a lot of coding to do for such a simple program.

Either way....Thank you for all your help. I will keep at it and hopefully my old brain will get it. :)
Was This Post Helpful? 0
  • +
  • -

#15 bcranger  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,199
  • Joined: 01-February 10

Re: Need a lot of advice on an applet

Posted 16 June 2010 - 03:38 AM

You may wish to make a new topic for your ASCII topic.

As for ASCII values, converting whatever letter or symbol to char will give you the ASCII value.

Simply store all the desired letters, symbols in 1 string. Use the toCharArray() method to return a character array of your values. Then convert each character value into an int. That's your ASCII value.

Note: ASCII values start at 0 so you do not need 3 boxes for every letter/symbol. In fact, the majority are two digits.

Use a look to add the text boxes...should be doable within 20-30 lines of code max.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2