Computation as an Expressive MediumYou are going to be sick of me.Hold up—what the heck is a .JAR?Let's add us some external codeAdding (uncompiled) external codeJava-mode gotchas!More Java-Mode GotchasEven More Java-Mode GotchasUsing Web crawling on CoursewareSlide 10Signing your jar fileSlide 12Slide 13Slide 14Viewing the jar fileEnd of SlidesComputation as an Computation as an Expressive MediumExpressive MediumLab 9: Java Mode, External Lab 9: Java Mode, External Code, and .JAR signingCode, and .JAR signingAnnie LausierAnnie LausierYou are going to be You are going to be sick of me.sick of me.Adding external code!Adding external code!Squirreled-away java-mode tips! Squirreled-away java-mode tips! .jar signing – not just for .jar signing – not just for pottery celebrities anymore!pottery celebrities anymore!Review of the code you didn't Review of the code you didn't finish!finish!Hold up—what the heck is a Hold up—what the heck is a .JAR?.JAR?A A .JAR.JAR file is a java applet. file is a java applet.When you write a When you write a sketchsketch in processing… in processing………it gets converted to a full-up it gets converted to a full-up .java.java file file(See this in the (See this in the Applet Applet folder! Read it! folder! Read it! Ponder!)Ponder!)the .java file gets compiled into a the .java file gets compiled into a .class.classthe .class gets compressed into a the .class gets compressed into a .jar.jarIn fact, if you change the extension from .jar In fact, if you change the extension from .jar to .zip,to .zip, you can unzip it and see the you can unzip it and see the original .class!!original .class!!Let's add us some Let's add us some external codeexternal codeYou've just downloaded a java You've just downloaded a java library off the amazing INTARWEB!library off the amazing INTARWEB!toastmaker.jartoastmaker.jarYou can do two things:You can do two things:Put it in Put it in ……or, put it intoor, put it into(which, like files in (which, like files in datadata, gets , gets exported)exported)processing-0091/libraries/toastmaker/library/toastmaker.jarprocessing-0091/libraries/toastmaker/library/toastmaker.jar<your sketch folder><your sketch folder>/code/toastmaker.jar/code/toastmaker.jarAdding (uncompiled) Adding (uncompiled) external codeexternal codeSee that arrow See that arrow on the left?on the left?Click it, and choose Click it, and choose Add Tab…Add Tab…Give the new file a name and it Give the new file a name and it adds adds another .pdeanother .pde in your sketch folder in your sketch folder……oror end the name with end the name with .java.java and it and it will add a full-up .java file in your will add a full-up .java file in your sketch foldersketch folder(Useful for when you have an (Useful for when you have an uncompiled .java classuncompiled .java class that you want to that you want to add to your project!)add to your project!)Java-mode gotchas!Java-mode gotchas!First of all, as you've found, you First of all, as you've found, you don't need to go into java mode to don't need to go into java mode to use the import statementuse the import statementIf you If you dodo decide to use java mode, decide to use java mode, you have to writeyou have to writepublicpublic class class Something Something extends extends PApplet {PApplet { … …This This publicpublic is important! And it is is important! And it is ONLY necessary on the ONLY necessary on the class … extends class … extends PAppletPAppletMore Java-Mode GotchasMore Java-Mode Gotchaspublic class happy extends PApplet { // global vars void setup(){ … } void draw(){ … } void othermethod(){ … } class something{ … }}class somethingelse { // fields somethingelse(){ … } void method(){ … } void totallyawesome(){ … }}happy.pdesomethingelse.pdeThe class code in The class code in somethingelse.pdesomethingelse.pdeGets Gets addedadded to the to the endend of the code of the code insideinside public public class happyclass happy before compiling before compilingDoes Does NOTNOT have a have a publicpublic in front of the class, in front of the class, that is, it's just plain that is, it's just plain class somethingelse {class somethingelse {Even More Java-Mode Even More Java-Mode GotchasGotchaspublic class happy extends PApplet { // global vars yetanother varname; void setup(){ … } void draw(){ … } class something{ … }}public class yetanother { // fields public static void main blah blah…}happy.pdeyetanother.javaThe class code in The class code in yetanother.javayetanother.javaCan be any standard java Can be any standard java .java file.java file, pretty , pretty muchmuchCan have Can have publicpublic wherever the heck it wants it… wherever the heck it wants it… (not true, but you get the picture)(not true, but you get the picture)Using Web crawling on Using Web crawling on CoursewareCoursewareSo…now you've seen that the code in So…now you've seen that the code in the Processing window the Processing window extends extends PAppletPApplet. You can view Applets on the . You can view Applets on the web, which is why they work (usually) web, which is why they work (usually) seamlessly with the Courseware.seamlessly with the Courseware.HOWEVER, browsers HOWEVER, browsers have security have security problemsproblems when a Java applet when a Java applet tries to tries to access other filesaccess other files at different at different sites.sites.Using Web crawling on Using Web crawling on CoursewareCoursewareFor instance, this call works both in For instance, this call works both in Processing and on the Courseware (provided Processing and on the Courseware (provided image1.jpgimage1.jpg is in your data directory): is in your data directory):PImage im = loadImage(“image1.jpg”);PImage im = loadImage(“image1.jpg”);But this call works But this call works onlyonly in the Processing in the Processing program, program, not onlinenot online::PImage im = PImage im = loadImage(“loadImage(“http://idt.gatech.edu/~mateas/imagehttp://idt.gatech.edu/~mateas/image1.jpg1.jpg”);”);Signing your jar fileSigning your jar fileTo allow browsers to control the security To allow browsers to control the security of your applet, you must sign it first.of your applet, you must sign it first.Two steps:Two steps:Create
View Full Document