GT LCC 6310 - The Computer as an Expressive Medium

Unformatted text preview:

1LCC 6310The Computer as an Expressive MediumLecture 18OverviewProject 4 questions?Assignment 5Java for real!Java application basicsJava applet basicsGraphical Java - double buffering!Mouse listenersProject 4Due: Friday November 2Making sense of the world is not just a matter of structure, but of process, of the dynamic construction of meaning. And as we've been discovering together, computation is fundamentally a process medium. What would you do to the web? Create an applet that dynamically does something to one or more web pages (e.g. collage, systematic distortion, re-layout, ironic superposition, etc.).Assignment 5Posted online, not gradedA5-01: Modify image collage to, instead of grabbing images, grab headlines from several news sources and display them. This gives you practice in looking at the html source for multiple sites (e.g. New York Times, CNN), determining how a piece of information is represented, and writing the parse code to grab that piece of information.A5-02: Write an html parser that looks for keywords (you pick the keywords) in the text (not within a tag) of a page and counts how many times different keywords appear. You can imagine that this might be the beginning of an information visualizer that visualizes pages as a function of different keywords that appear.2JDKDownload the JDK (J2SE Development Kit) from java.sun.comThe JDK provides command line tools to compile and run java applications and applets, located in the <jdk-install>/bin directory:javac.exe - compile java application or appletjar.exe - archive files into a .jar filejava.exe - run java application(We'll see the usage of these later…)Choose your favorite text editor to write Java code (e.g. I like Notepad2 or emacs so that's what you'll see me using, but you can choose any simple text editor you like - e.g. notepad, vi, bbedit, etc.)We'll build a simple java application and then a java applet…Java application basicsThe main classYour application needs to have a main class with a main methodThis is where the program execution thread will startpublic static void main(String[] args) {…}This method needs to be public since it is called from outside and staticbecause it is called before any object is instantiatedThe array of strings are the command line arguments (if any) for the applicationLet's try to build a simple application…Hello world!public class HelloConsole {// Constructor// -----------------------------------------------public HelloConsole() {System.out.println("Hello world!");}// Main Entry Point// -----------------------------------------------public static void main(String[] args) {new HelloConsole();}}Let's look at the HelloConsole.java file…Now we just need to compile and run this!3CompileThe first step is to compile our java class…We do this by opening a command prompt (e.g. DOS shell on Windows), navigating to the directory where the source code is stored, and typing the following command:> javac *.javaThis means "compile all the java classes in this directory" (the '*' is a wildcard) and generates compiled .class files If there are any errors, they will show up in the console windowIf the <jdk-install>/bin directory is not in your PATH environment variable, you might need to type the entire path for your java command, e.g. c:\java\jdk1.6.0_03\bin\javac.exeLet's try compiling our HelloConsole.java file at the command line…Jar manifestNow that we've compiled, we want to run our application. To do this, we can package our .class files into a .jar file…This isn't strictly necessary, but it makes things a lot easier when you start to have lots of .class files!But first we need to create a Manifest…The jar manifest is used to define extension and package-related data for a java application. You can read the details here:http://java.sun.com/j2se/1.3/docs/guide/jar/jar.htmlWe need to have a Main-Class attribute in our manifest. This will define the relative path of the main application class which thelauncher will load at startup. Without one, we wouldn't be able to run the jar file from the command-line. Let's create a manifest file…HelloConsole Manifest fileCreate a new file in a text editor and type the following line:Main-Class: HelloConsoleSave this file (you can use whatever name you like, e.g. Manifest.txt)Next we'll see how to use the jar command to add it to our jar file when we package our java classes…Jar commandNow we're ready to package our .class files into a .jar file!We do this by invoking the jar command at the command line:> jar -cfm HelloConsole.jar Manifest.txt *.classExtensions invoked with our call to the jar command:c - create a new archivef - specify the name of the archive (e.g. HelloConsole.jar)m - include manifest info from the specified file (e.g. Manifest.txt)(Note: the order of arguments in your call should correspond to the order in which you typed in the extensions, e.g. cfm vs. cmf)You can look at the usage of the jar command as follows:> jarThis will output all the possible extensions you can use…4RunNow that we have our HelloConsole.jar file, we can run our Java application using the following command:> java -jar HelloConsole.jarIn this case, we see the following output:Hello world!The java command launches our Java application by starting a Java Runtime Environment (JRE), loading the specified main class and invoking its main method. The -jar extension launches the application from the packaged .jar file.You can also run the application by double-clicking the jar file.Summary of stepsHow to compile, package and run a Java application:Step 0: Write source code for your java classes in text editor and create a manifest file which describes the main classStep 1: Compile your .java files> javac *.javaStep 2: Package your .class files into a .jar> jar -cfm MyJar.jar MyManifest.txt *.classStep 3: Run your java application using the .jar> java -jar MyJar.jarJava applet basicsCreating appletsUnlike applications, applets do not have a main method. Instead, to create an applet, we start by extending the Java Applet classLook at the API docs for Applet:http://java.sun.com/j2se/1.4.2/docs/api/Some methods we can override to give the applet desired functionality:init() - called by the browser to inform that the applet is loadedstart() - called by the browser to tell the applet to start its executionstop() - called by the browser to tell the applet to stop its executiondestroy() - called by the browser to tell the applet that it is being


View Full Document

GT LCC 6310 - The Computer as an Expressive Medium

Documents in this Course
Load more
Download The Computer as an Expressive Medium
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view The Computer as an Expressive Medium and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view The Computer as an Expressive Medium 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?