Search the web
Sign In
New User? Sign Up
jurtle-users · Jurtle Users
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Message search is now enhanced, find messages faster. Take it for a spin.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Multi-Threaded Wonders   Message List  
Reply | Forward Message #113 of 119 |
Re: [jurtle-users] Multi-Threaded Wonders

Bill,

Well, this isn't the behavior we're seeing. If we press the blue button
4 times, it takes 5 presses of the STOP button ( 1 for each spawned
thread and 1 for the Turtle I presume). The pattern holds true for any
number of blueBtnHandler threads that are spawned. The BlueBtnHandler is
an inner class of the outer Turtle class, so is each press of Jurtle's
STOP button finding and killing off these "child" threads?

I also assume that since these drawing threads are being spawned from
the same Turtle instance that they share and overwrite the same
attributes of that Turtle such as penWidth, penColor, penWidth,
penPosition, etc. The display is quite entertaining actually and we had
a blast in class today as a result.

Here's the output from the Console...

With curious glee,

John

----------------------- Begin Console Output ------------------------

Execution started...

Red button clicked
Green button clicked
Blue button clicked
Blue button clicked
Blue button clicked
Blue button clicked
com.otherwise.jurtle.Turtle$StopException
at com.otherwise.jurtle.Turtle.checkForStop(Turtle.java:132)
at com.otherwise.jurtle.Turtle.setPosition(Turtle.java:650)
at com.otherwise.jurtle.Turtle.forward(Turtle.java:170)
at GUIDisplayReloaded$HandleBlueBtn.run(GUIDisplayReloaded.java:107)
com.otherwise.jurtle.Turtle$StopException
at com.otherwise.jurtle.Turtle.checkForStop(Turtle.java:132)
at com.otherwise.jurtle.Turtle.setPosition(Turtle.java:650)
at com.otherwise.jurtle.Turtle.forward(Turtle.java:170)
at GUIDisplayReloaded$HandleBlueBtn.run(GUIDisplayReloaded.java:107)
com.otherwise.jurtle.Turtle$StopException
at com.otherwise.jurtle.Turtle.checkForStop(Turtle.java:132)
at com.otherwise.jurtle.Turtle.setPosition(Turtle.java:650)
at com.otherwise.jurtle.Turtle.forward(Turtle.java:170)
at GUIDisplayReloaded$HandleBlueBtn.run(GUIDisplayReloaded.java:107)
com.otherwise.jurtle.Turtle$StopException
at com.otherwise.jurtle.Turtle.checkForStop(Turtle.java:132)
at com.otherwise.jurtle.Turtle.setPosition(Turtle.java:650)
at GUIDisplayReloaded$HandleBlueBtn.run(GUIDisplayReloaded.java:105)

Bill Tschumy wrote:

> The Stop button will only stop the Turtle thread. Any other threads
> that you may start are unknown to Jurtle and must terminate on their
> own (the normal case) or you have to have code yourself that deals
> with stopping them.
>
>
> On Sep 10, 2005, at 4:28 PM, John Kirkilis wrote:
>
> > Hi Bill,
> >
> > With the changes you suggested to create a separate drawing thread, my
> > students found that if they changed the number of iterations in the
> > ColorWheel code from 360 to something like 3600 which goes around 10
> > times and pressed the Blue button several times in succession, they
> > could get several drawing threads all updating the screen at the same
> > time which is entertaining. They also discovered that if hitting the
> > STOP button in Jurtle appears to kill off one of the threads while
> > leaving the remaining ones running. If you've got a lot of drawing
> > threads, then it takes a lot of clicks to terminate the program. It
> > also
> > appears that the CPU stays pegged even though control has returned to
> > Jurtle. Is this the intended behavior or should the STOP button
> > stop all
> > active user threads?
> >
> > - John
> >
> > p.s. Now my students want to have separate threads drawing in
> > different
> > areas of the display. We've created a monster!
> >
> > Here's the code:
> >
> > /**
> > * The GUIDisplay turtle displays the same basic user interface as
> > GUI,
> > but it does
> > * it within the Display. This shows how to get the display panel and
> > add graphical
> > * elements to it.
> > *
> > * Note the use of waitForStop() at the end of the runTurtle() method.
> > This causes
> > * the turtle to not finish until the Stop button has been clicked or
> > the stopTurtle()
> > * method has been called.
> > */
> >
> > import java.awt.*;
> > import java.awt.event.*;
> > import javax.swing.*;
> > import com.otherwise.jurtle.*;
> >
> > public class GUIDisplayReloaded extends Turtle
> > {
> >
> > JButton redBtn;
> > JButton greenBtn;
> > JButton blueBtn;
> > Container displayContainer;
> >
> > /**
> > * Main entry point to the code. Creates the GUI within the
> > Display
> > * area calls waitForStop to wait until the Stop button is
> > clicked.
> > */
> >
> > public void runTurtle()
> > {
> > displayContainer = getDisplayContainer();
> > JPanel controlsPanel = new JPanel();
> > controlsPanel.setLayout( new FlowLayout() );
> >
> > displayContainer.setLayout( new BorderLayout() );
> > displayContainer.add( controlsPanel, BorderLayout.NORTH );
> > displayContainer.add( getDisplay(), BorderLayout.CENTER );
> >
> > redBtn = new JButton( "Red" );
> > redBtn.addActionListener( new BtnHandler() );
> > controlsPanel.add( redBtn );
> >
> > greenBtn = new JButton( "Green" );
> > greenBtn.addActionListener( new BtnHandler() );
> > controlsPanel.add( greenBtn );
> >
> > blueBtn = new JButton( "Blue" );
> > blueBtn.addActionListener( new BtnHandler() );
> > controlsPanel.add( blueBtn );
> >
> > displayContainer.validate();
> > waitForStop();
> > }
> >
> > /**
> > * The BtnHandler class is responsible for responding to mouse
> > * clicks on the buttons.
> > */
> >
> > private class BtnHandler implements ActionListener
> > {
> > public void actionPerformed( ActionEvent evt )
> > {
> > Object src = evt.getSource();
> > if ( src == redBtn )
> > {
> > setDisplayColor( Color.red );
> > Console.println( "Red button clicked" );
> > }
> > else if ( src == greenBtn )
> > {
> > setDisplayColor( Color.green );
> > Console.println( "Green button clicked" );
> > }
> > else if ( src == blueBtn )
> > {
> > new HandleBlueBtn().start();
> > }
> >
> > }
> > }
> >
> > private class HandleBlueBtn extends Thread
> > {
> > public void run()
> > {
> > setDisplayColor( Color.blue );
> > Console.println( "Blue button clicked" );
> >
> > // insert code from ColorWheel class
> >
> > setPenWidth( 5 );
> > setAutoUpdate( false );
> > hideTurtle();
> >
> > for ( int i = 0; i < 36000; i = i + 1 )
> > {
> > setPenColor( Color.getHSBColor( i / 360.0f, 1.0f,
> > 1.0f ) );
> > center();
> > forward( 200 );
> > right( 1 );
> >
> > // Only update the display every 10th line drawn.
> > This
> > decreases time to draw the entire wheel.
> >
> > if ( ( i % 10 ) == 0 )
> > updateDisplay();
> > }
> > updateDisplay();
> > }
> > }
> > }
> >
> >
> >
> > ------------------------ Yahoo! Groups Sponsor --------------------
> > ~-->
> > Get Bzzzy! (real tools to help you find a job). Welcome to the
> > Sweet Life.
> > http://us.click.yahoo.com/A77XvD/vlQLAA/TtwFAA/5cFolB/TM
> > --------------------------------------------------------------------
> > ~->
> >
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> >
> >
>
> --
> Bill Tschumy
> Otherwise -- Austin, TX
> http://www.otherwise.com
>
>
>
>
> SPONSORED LINKS
> Basic programming language
>
<http://groups.yahoo.com/gads?t=ms&k=Basic+programming+language&w1=Basic+program\
ming+language&w2=C+programming+language&w3=Computer+programming+languages&w4=The\
+c+programming+language&w5=C+++programming+language&w6=List+of+programming+langu\
ages&c=6&s=193&.sig=aLlETYEcZKW67uFZnuZPPw
>
> C programming language
>
<http://groups.yahoo.com/gads?t=ms&k=C+programming+language&w1=Basic+programming\
+language&w2=C+programming+language&w3=Computer+programming+languages&w4=The+c+p\
rogramming+language&w5=C+++programming+language&w6=List+of+programming+languages\
&c=6&s=193&.sig=n4wEVXDpIBKogo8e_G77cw
>
> Computer programming languages
>
<http://groups.yahoo.com/gads?t=ms&k=Computer+programming+languages&w1=Basic+pro\
gramming+language&w2=C+programming+language&w3=Computer+programming+languages&w4\
=The+c+programming+language&w5=C+++programming+language&w6=List+of+programming+l\
anguages&c=6&s=193&.sig=KFl1CeQi7jrKmsK4WD6ygQ
>
>
> The c programming language
>
<http://groups.yahoo.com/gads?t=ms&k=The+c+programming+language&w1=Basic+program\
ming+language&w2=C+programming+language&w3=Computer+programming+languages&w4=The\
+c+programming+language&w5=C+++programming+language&w6=List+of+programming+langu\
ages&c=6&s=193&.sig=lU9w7-4UlGPB4LjDy84c2Q
>
> C programming language
>
<http://groups.yahoo.com/gads?t=ms&k=C+++programming+language&w1=Basic+programmi\
ng+language&w2=C+programming+language&w3=Computer+programming+languages&w4=The+c\
+programming+language&w5=C+++programming+language&w6=List+of+programming+languag\
es&c=6&s=193&.sig=dtKotXT1Ne2N9AO_aEbPFQ
>
> List of programming languages
>
<http://groups.yahoo.com/gads?t=ms&k=List+of+programming+languages&w1=Basic+prog\
ramming+language&w2=C+programming+language&w3=Computer+programming+languages&w4=\
The+c+programming+language&w5=C+++programming+language&w6=List+of+programming+la\
nguages&c=6&s=193&.sig=0shmxLBHwrZWcSjC3QvZAA
>
>
>
>
> ------------------------------------------------------------------------
> YAHOO! GROUPS LINKS
>
> * Visit your group "jurtle-users
> <http://groups.yahoo.com/group/jurtle-users>" on the web.
>
> * To unsubscribe from this group, send an email to:
> jurtle-users-unsubscribe@yahoogroups.com
> <mailto:jurtle-users-unsubscribe@yahoogroups.com?subject=Unsubscribe>
>
> * Your use of Yahoo! Groups is subject to the Yahoo! Terms of
> Service <http://docs.yahoo.com/info/terms/>.
>
>
> ------------------------------------------------------------------------
>



Tue Sep 13, 2005 12:12 am

johnkirkilis
Offline Offline
Send Email Send Email

Forward
Message #113 of 119 |
Expand Messages Author Sort by Date

Hi Bill, With the changes you suggested to create a separate drawing thread, my students found that if they changed the number of iterations in the ColorWheel...
John Kirkilis
johnkirkilis
Offline Send Email
Sep 10, 2005
9:24 pm

The Stop button will only stop the Turtle thread. Any other threads that you may start are unknown to Jurtle and must terminate on their own (the normal case)...
Bill Tschumy
btschumy
Offline Send Email
Sep 10, 2005
9:40 pm

Bill, Well, this isn't the behavior we're seeing. If we press the blue button 4 times, it takes 5 presses of the STOP button ( 1 for each spawned thread and 1...
John Kirkilis
johnkirkilis
Offline Send Email
Sep 13, 2005
12:09 am

John, You guys are definitely treading in uncharted waters. Jurtle wasn't really designed with the idea of non-Turtle threads using the Turtle API calls. I...
Bill Tschumy
btschumy
Offline Send Email
Sep 13, 2005
1:09 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help