tag:blogger.com,1999:blog-46102502083062234362024-03-13T23:38:17.268-07:00TheNewBoston Source CodeHere is all of my source code for all of my tutorials! Note: Any code for tutorials created before 5/3/2010 is not available.Bucky Robertshttp://www.blogger.com/profile/09487652301873140432noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-4610250208306223436.post-36419966920912912782010-05-03T22:05:00.000-07:002010-05-03T22:46:12.299-07:00Intermediate Java Tutorial - 27 - What do I look like, a Thread?<div style="text-align: center;"><object height="385" width="640"><param name="movie" value="http://www.youtube.com/v/oUSpVDbT5eg&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/oUSpVDbT5eg&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object></div><br />
<div style="font-family: "Courier New",Courier,monospace;"><span style="font-size: small;">public class Bucky {<br />
public static void main(String[] args) {<br />
<br />
Thread t1 = new Thread(new Tuna("one"));<br />
Thread t2 = new Thread(new Tuna("two"));<br />
Thread t3 = new Thread(new Tuna("three"));<br />
<br />
t1.start();<br />
t2.start();<br />
t3.start();<br />
}<br />
}</span></div>Bucky Robertshttp://www.blogger.com/profile/09487652301873140432noreply@blogger.com1tag:blogger.com,1999:blog-4610250208306223436.post-49253010020946503342010-05-03T20:55:00.000-07:002010-05-03T22:45:22.878-07:00Intermediate Java Tutorial - 26 - Learning about Threads<div style="text-align: center;"><object height="385" width="640"><param name="movie" value="http://www.youtube.com/v/VYN-CBtPNiM&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/VYN-CBtPNiM&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object></div><br />
<span style="font-size: small;"></span><br />
<span style="font-size: small;"><span style="font-family: "Courier New",Courier,monospace;">import java.util.*;</span><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;">//Runnable interface contains run() method</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;">public class Tuna implements Runnable{</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> String name;</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> int time;</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> Random r = new Random();</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> </span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> public Tuna(String x){</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> name = x;</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> time = r.nextInt(999); //between 0-1 second</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> }</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> </span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> //this runs when you start thread</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> public void run(){</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> try{</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> System.out.printf("%s is sleeping for %d\n", name, time);</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> Thread.sleep(time); //how long do u want to sleep for?</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> System.out.printf("%s is done\n", name);</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> }catch(Exception e){}</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> }</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;">}</span></span><br />
<div style="font-family: "Courier New",Courier,monospace;"><span style="font-size: small;"><br />
</span></div>Bucky Robertshttp://www.blogger.com/profile/09487652301873140432noreply@blogger.com0tag:blogger.com,1999:blog-4610250208306223436.post-1421243454580000922010-05-03T20:02:00.000-07:002010-05-03T22:44:44.943-07:00Objective C Programming Tutorial - 27 - But what if I'm a millionaire?<div style="text-align: center;"><object height="385" width="640"><param name="movie" value="http://www.youtube.com/v/mX2d6UU8Cqk&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/mX2d6UU8Cqk&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object></div><br />
<span style="font-size: small;"><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> #import </span><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> @interface Person : NSObject {</span></span> <span style="font-size: small;"><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> int age;</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> int weight;</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> }</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> @property int age,weight;</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> -(void) print;</span><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> -(void) dateAge: (int) a: (int) i; </span></span><span style="font-size: small;"><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> @end</span></span><span style="font-size: small;"><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> //////////////////////////////////////////////////</span></span><span style="font-size: small;"><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> #import "Person.h"</span></span><span style="font-size: small;"><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> @implementation Person</span></span><span style="font-size: small;"><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> @synthesize age,weight;</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> -(void) print{</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> NSLog(@"I am %i years old and weigh %i pounds", age, weight);</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> }</span><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> -(void) dateAge: (int) a: (int) i{</span></span><span style="font-size: small;"><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> NSLog(@"You can date chicks %i years old", (a/2+7)-(i/100000));</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> }</span><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> @end</span></span><span style="font-size: small;"><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> ///////////////////////////////////////</span></span><span style="font-size: small;"><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> #import </span></span><span style="font-size: small;"><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> #import "Person.h"</span><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> int main (int argc, const char * argv[]) {</span></span><span style="font-size: small;"><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];</span><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> Person *bucky = [[Person alloc]init];</span></span><span style="font-size: small;"><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> bucky.age = 12;</span></span><span style="font-size: small;"><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> bucky.weight = 540;</span><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> [bucky print];</span></span><span style="font-size: small;"><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> [bucky dateAge:45]; </span></span><span style="font-size: small;"><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> [bucky release];</span></span><span style="font-size: small;"><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> [pool drain];</span></span><span style="font-size: small;"><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> return 0;</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> }</span></span>Bucky Robertshttp://www.blogger.com/profile/09487652301873140432noreply@blogger.com1tag:blogger.com,1999:blog-4610250208306223436.post-11187187658970677122010-05-03T19:36:00.000-07:002010-05-03T19:36:16.387-07:00Welcome to my new blog!<div class="separator" style="clear: both; text-align: center;"><a href="http://www.ncpc.org/resources/enhancement-assets/clipart-and-stock-art/iStock-000003290557XSmall.jpg/image_preview" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="http://www.ncpc.org/resources/enhancement-assets/clipart-and-stock-art/iStock-000003290557XSmall.jpg/image_preview" width="320" /></a></div><br />
<br />
Hey everyone, welcome to my new blog. This blog isn't going to be as cool as my other one but I'm sure a lot of you guys will find it very useful. I am going to be posting all of my source code from all of the tutorials that I make form here on out on this blog. Sorry, but I don't have the source code anymore from any earlier tutorials. <br />
<br />
-BuckyBucky Robertshttp://www.blogger.com/profile/09487652301873140432noreply@blogger.com1