Title: Computation as an Expressive Medium
1Computation as an Expressive Medium
- Lab 9 Java Mode, External Code, and .JAR signing
- Annie Lausier
2You are going to be sick of me.
- Adding external code!
- Squirreled-away java-mode tips!
- .jar signing not just for pottery celebrities
anymore! - Review of the code you didn't finish!
3Hold upwhat the heck is a .JAR?
- A .JAR file is a java applet.
- When you write a sketch in processing
- it gets converted to a full-up .java file
- (See this in the Applet folder! Read it!
Ponder!) - the .java file gets compiled into a .class
- the .class gets compressed into a .jar
- In fact, if you change the extension from .jar to
.zip, you can unzip it and see the original
.class!!
4Let's add us some external code
- You've just downloaded a java library off the
amazing INTARWEB! - toastmaker.jar
- You can do two things
- Put it in
- or, put it into(which, like files in data,
gets exported)
processing-0091/libraries/toastmaker/library/toast
maker.jar
ltyour sketch foldergt/code/toastmaker.jar
5Adding (uncompiled) external code
- See that arrow on the left?
- Click it, and choose Add Tab
- Give the new file a name and it adds another .pde
in your sketch folder - or end the name with .java and it will add a
full-up .java file in your sketch folder - (Useful for when you have an uncompiled .java
class that you want to add to your project!)
6Java-mode gotchas!
- First of all, as you've found, you don't need to
go into java mode to use the import statement - If you do decide to use java mode, you have to
write - public class Something extends PApplet
- This public is important! And it is ONLY
necessary on the class extends PApplet
7More Java-Mode Gotchas
happy.pde
somethingelse.pde
public class happy extends PApplet // global
vars void setup() void draw()
void othermethod() class something
class somethingelse // fields
somethingelse() void method() void
totallyawesome()
- The class code in somethingelse.pde
- Gets added to the end of the code inside public
class happy before compiling - Does NOT have a public in front of the class,
that is, it's just plain class somethingelse
8Even More Java-Mode Gotchas
happy.pde
yetanother.java
public class happy extends PApplet // global
vars yetanother varname void setup()
void draw() class something
public class yetanother // fields public
static void main blah blah
- The class code in yetanother.java
- Can be any standard java .java file, pretty much
- Can have public wherever the heck it wants it
(not true, but you get the picture)
9Using Web crawling on Courseware
- Sonow you've seen that the code in the
Processing window extends PApplet. You can view
Applets on the web, which is why they work
(usually) seamlessly with the Courseware. - HOWEVER, browsers have security problems when a
Java applet tries to access other files at
different sites.
10Using Web crawling on Courseware
- For instance, this call works both in Processing
and on the Courseware (provided image1.jpg is in
your data directory) - PImage im loadImage(image1.jpg)
- But this call works only in the Processing
program, not online - PImage im loadImage(http//idt.gatech.edu/mate
as/image1.jpg)
11Signing your jar file
- To allow browsers to control the security of your
applet, you must sign it first. - Two steps
- Create a keystore file.
- Sign your jar file.
- Before you can do this, you must either
- upload your jar file to your Steel account.
- For the following commands, use a shell prompt.
- install the Java SDK on your machine.
- get to a command line in the directory of your
jar.
12Signing your jar file
- Create a keystore file. Run the following
command - keytool -genkey -alias ltaliasgt -keystore
ltlocationgt - The -keystore ltlocationgt part is optional. It
allows you to specify where the .keystore file
will go. If you dont specify, it will place it
in your default system path. This should be fine
for most applications.
Just substitute ltaliasgt with a name for your
key that you're generating
13Signing your jar file
- After you run keytool, it will prompt you for
some things - keystore password this is used when signing your
jars. - Name, Organizational Unit, blah blah not very
important, just provides viewers information on
who theyre trusting. - key password also used when signing your jars.
Not a problem to make it the same as the keystore
password.
14Signing your jar file
- Sign your jar file. Run the following command
- jarsigner ltjar filegt ltaliasgt -keystore ltlocationgt
- ltjar filegt is just the file name of the jar.
- ltaliasgt just needs to match the alias you used
for the keystore. - -keystore ltlocationgt is also optional. The
default will be the same location as keytool. - You will be prompted for your keystore password.
15Viewing the jar file
- The jar file is signed! Upload it to the
courseware like you would normally. - When anyone loads the applet, a window will come
up asking if they accept the certificate. Just
click Yes, and the applet will load.
16Unca' Mayhew's Debugging Tips
- Stack Trace The indecipherable lines of red that
pop up when an error occurs. - This shows what methods were running in what
classes when the program broke, as well as the
line numbers in their java files.
17Unca' Mayhew's Debugging Tips
- Common errors, and what they mean
- ArrayOutOfBoundsException
- You are trying to access an index in an array
that doesnt have that index. For example,
thisArray-1 or thisArray6 in an array with
length 6 (max index of 5). Check to make sure any
for loops have the right conditions.
18Unca' Mayhew's Debugging Tips
- Common errors, and what they mean
- NullPointerException
- You are trying to access an object that hasnt
been initialized, or is set to null. Remember
that in addition to declaring a variable (telling
the program this variable exists, has this type,
and this name), you must initialize the variable
(give it a value or point it at an object). - String myString // declares String variable.
- myString new String() // sets variable to
point to a String object.
19Unca' Mayhew's Debugging Tips
- Split up tasks into smaller methods. Processing
will tell you which method the error occurred in,
so the smaller they are, the closer you can
pinpoint it. - Processing also gives you a line number. Not as
useful when it doesnt give you a way to scroll
to that line, but you can copy and paste your
code into another editor (NetBeans, even
Dreamweaver) that does have a go to line
function.
20Unca' Mayhew's Debugging Tips
- Use println intelligently to try and figure out
whats wrong. You can use this to keep track of
what variables are at different points in the
program, or even just to tell you what methods
the program is going into. Doing this can help
give a sense as to the flow of what is happening
in the program.
21End of Slides