threads

Reply

Join Date: Nov 2007
Posts: 33
Reputation: snitch321 is an unknown quantity at this point 
Solved Threads: 1
snitch321 snitch321 is offline Offline
Light Poster

threads

 
0
  #1
Jan 4th, 2008
how would i incorperate multi-threads in my coding to make the last section all execute at the same time(ive highlighted the last section):


/**
* draw a balloon on to a canvas
* then to make them fly
*
* @author (chris twaits)
* @version (12/10/07)
*/
public class Balloons
{
private Circle top;
private Triangle middle;
private Triangle bottom;
private Circle top2;
private Triangle middle2;
private Triangle bottom2;
private Circle top3;
private Triangle middle3;
private Triangle bottom3;

/**
* construct object
*/
public void draw()
{
top = new Circle();
top.changeColor("red");
top.moveHorizontal(8);
top.moveVertical(121);
top.changeSize(60);
top.makeVisible();

middle = new Triangle();
middle.changeColor("green");
middle.changeSize(-38, 55);
middle.moveHorizontal(8);
middle.moveVertical(247);
middle.makeVisible();

bottom = new Triangle();
bottom.changeColor("blue");
bottom.changeSize(7, 11);
bottom.moveHorizontal(8);
bottom.moveVertical(246);
bottom.makeVisible();

top2 = new Circle();
top2.changeColor("blue");
top2.moveHorizontal(125);
top2.moveVertical(175);
top2.changeSize(60);
top2.makeVisible();

middle2 = new Triangle();
middle2.changeColor("magenta");
middle2.changeSize(-38, 55);
middle2.moveHorizontal(125);
middle2.moveVertical(301);
middle2.makeVisible();

bottom2 = new Triangle();
bottom2.changeColor("green");
bottom2.changeSize(7, 11);
bottom2.moveHorizontal(125);
bottom2.moveVertical(300);
bottom2.makeVisible();


top3 = new Circle();
top3.changeColor("yellow");
top3.moveHorizontal(240);
top3.moveVertical(141);
top3.changeSize(60);
top3.makeVisible();

middle3 = new Triangle();
middle3.changeColor("blue");
middle3.changeSize(-38, 55);
middle3.moveHorizontal(240);
middle3.moveVertical(267);
middle3.makeVisible();

bottom3 = new Triangle();
bottom3.changeColor("black");
bottom3.changeSize(7, 11);
bottom3.moveHorizontal(240);
bottom3.moveVertical(266);
bottom3.makeVisible();

}
/**
* Create method for balloons to fly
*/

public void slowMoveVertical ()

{
top.slowMoveVertical(-50);
top2.slowMoveVertical(-50);
top3.slowMoveVertical(-50);
middle.slowMoveVertical(-50);
middle2.slowMoveVertical(-50);
middle3.slowMoveVertical(-50);
bottom.slowMoveVertical(-50);
bottom2.slowMoveVertical(-50);
bottom3.slowMoveVertical(-50);

}
}
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 763
Reputation: Phaelax is on a distinguished road 
Solved Threads: 38
Phaelax Phaelax is offline Offline
Master Poster

Re: threads

 
1
  #2
Jan 4th, 2008
Actually, this should all be done in 1 thread. I'm guessing you have multiple objects on screen that you want to appear to move at the same time? You would update the positions of all the objects, and only after that should you redraw the objects. If you use double buffering on your canvas, the redraw won't flicker at all and you should see what appears to be all the objects move at the same time.

If the slowMoveVertical(int) method isn't an instant jump from X to X-50 and instead slowly increments up to that position, then you can make an additional thread but it would handle the movement for all the objects. You do not want a separate thread for each moving object, which is what I think you were trying to do.

Can you display the code for those 'move' methods?
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 33
Reputation: snitch321 is an unknown quantity at this point 
Solved Threads: 1
snitch321 snitch321 is offline Offline
Light Poster

Re: threads

 
0
  #3
Jan 6th, 2008
im not totally sure what you are sayin, but i thought my move method source code is shown.
my overall project goes like this:
Balloons(class)

square(class) circle(class) Triangle(class)

canvas(class)
sry if that is not clear or helps.
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 763
Reputation: Phaelax is on a distinguished road 
Solved Threads: 38
Phaelax Phaelax is offline Offline
Master Poster

Re: threads

 
0
  #4
Jan 7th, 2008
I do not know what any of those objects are.

slowMoveVertical(-50)

How does this work? I need to see its implementation so I know exactly what it's doing. You've basically just posted a bunch of method calls belonging to classes nobody but you knows anything about.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 33
Reputation: snitch321 is an unknown quantity at this point 
Solved Threads: 1
snitch321 snitch321 is offline Offline
Light Poster

Re: threads

 
0
  #5
Jan 9th, 2008
ok dude i know your trying to help, but your speakin a little negative, im a beginner ok, im not a professional so have some patience.anyways no worrys guys, ill go else where thank you for your efforts.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,454
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 511
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: threads

 
0
  #6
Jan 9th, 2008
Several people have asked you to show the code for slowMoveVertical(int) from the appropriate class, yet you never do - in this thread or the others you have posted about this same question. If you want to get offended at "speakin a little negative" and refused to be helped, then the problem is your own and perhaps you should go elsewhere.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC