LCC 6310 Computation as an Expressive Medium - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

LCC 6310 Computation as an Expressive Medium

Description:

LCC 6310. Computation as an Expressive Medium. Lecture 8 (another ... Here's something to wrap your noggin around... Allows you to program in pure Java ... – PowerPoint PPT presentation

Number of Views:50
Avg rating:3.0/5.0
Slides: 19
Provided by: michael74
Category:

less

Transcript and Presenter's Notes

Title: LCC 6310 Computation as an Expressive Medium


1
LCC 6310Computation as an Expressive Medium
  • Lecture 8
  • (another bloodless TA coup)

2
Overview
  • Recap
  • Processingin JAVA-MODE!
  • Libraries
  • Using other classes/libraries
  • HTML and parsing it.
  • Intro to the HTML parser

3
We started with Processing in
// any code here, no methods line(0,0,20,20)

// methods! // global varsint a // methodsvoid
setup() void draw()
// with classes // (all of the above and
then)class Emotion //fields //constructor //met
hods
// and subclasses! // (ALL of the above,
and) class Happy extends Emotion //new
fields //constructor //methods
4
(No Transcript)
5
Heres something to wrap your noggin around
  • Everything you write in Processing is actually
    within a full-up Java class

// dum-dum-DUMMM! // Java-Mode!!! class Uneasy
extends PApplet // void setup() and void draw()
as normally //methods //classes and
subclasses
6
Java Mode
  • Allows you to program in pure Java
  • Lets you import classes that arent normally
    imported into a Processing app
  • Importing means making a classes available to
    your program the Java API docs tell you what
    package classes are in so you know what to import
  • To go into Java mode, create a class that extends
    PApplet
  • Normally all Processing applets extend PApplet
    behind the scenes
  • Take at any compiled Processing app
  • So, those top-level functions that werent
    methods of any class really are methods of a
    class, a class extending PApplet
  • setup(), draw(), etc. are methods of the class
    extending PApplet

7
Template of a Java-mode program
  • class MyProgram extends PApplet
  • void setup()
  • void draw()
  • void myTopLevelMethod()
  • class Text // Text is just an example
  • int xPos, yPos
  • String word
  • Notice that any classes you define are inside the
    top class

8
Why use Java-mode again?
  • Java-mode gives you access to the entire Java SDK
  • We need access to some SDK classes for HTML
    parsing that Processing doesnt make visible by
    default
  • Java-mode helps you to understand how Processing
    is built on-top of Java
  • All those magic functions and variables are
    just methods and fields of PApplet that your
    program inherits

9
Libraries!
  • Sowhat are these libraries and how do I get
    them?
  • Libraries are just other classes (in .java or
    .jar files )
  • Use import nameoflibrary.nameofmethod (e.g.,
    import video. )
  • Now with Java-mode, you can ALSO put your
    programs in multiple files
  • A file for each class? Just like big kid
    programmers? Yay!
  • Create new tabs (files) with that button in the
    upper right

(There is a little confusion the old version of
processing, you had to stick all extra code into
a code/ folder in the same directory, but this
version seems lax on thatstandby for more info.)
10
What do you mean parse HTML?(and why would you
want to do it?)
  • Parsing means to walk through the structure of
    a file (not just look at it character-by-character
    , word-by-word)
  • Look at an HTML file
  • The structure of an HTML file is the tag
    structure
  • So parsing means to walk through and interpret
    the tags
  • If you can parse HTML files, that means you can
    pull content out of web pages and do stuff with
    it
  • Procedural manipulation of web content

ltfont size-1 colorgtResults ltbgt1lt/bgt - ltbgt20lt/bgt
of about ltbgt202lt/bgt for ltbgtlta href/url?saXoidi
ctqhttp//www.answers.com/matrix26r3D67
title"Look up definition of matrix"gtltbgtmatrixlt/bgt
lt/agtltbgt lt/bgtlta href/url?saXoidictqhttp//www
.answers.com/red26r3D67 title"Look up
definition of red"gtltbgtredlt/bgtlt/agt
ltbgtsome textlt/bgt some text
11
Please Pardon Our Technical Difficulties
  • The code from last year no longer works
  • proHTML is a Processing library
  • easy! but poorly documented, and chokes on any
    malformed HTML.
  • At least five other HTML parsers that were going
    throughdetails on use to be announced.
  • Disregard slides that follow for now.

12
Basic approach
  • Use two classes to parse
  • One class reads info from a URL HTMLParser
  • The other class is used by HTMLParser to process
    tags child of HTMLEditorKit.ParserCallback
  • HTMLParser recognizes when a tag appears (ltTAGgt)
    and calls appropriate methods on the
    ParserCallback class (start-tags, end-tags,
    simple-tags, text, etc.)
  • The programmer (ie. you), fill in the
    ParserCallback methods to do whatever you want
    when you see different kinds of tags

13
Running the example
  • Weve written HTMLParser for you
  • To access it, it must be in the data directory of
    your project
  • Simplest thing will be just to copy the code from
    the website and put the directory in your default
    sketchbook directory

14
handleSimpleTag
  • public void handleSimpleTag(HTML.Tag tag,
    MutableAttributeSet attrib, int pos)
  • Called for tags like IMG
  • tag stores the name of the tag
  • attrib stores any attributes
  • pos is the position in the file
  • Example ltimg srcimage.gif alttext
    description of image alignright width10gt
  • The tag is img
  • The attributes are src, alt, align, width (with
    their respective values)

15
handleStartTag
  • public void handleStartTag(HTML.Tag tag,
    MutableAttributeSet attrib, int pos)
  • Called for tags like BODY
  • tag stores the name of the tag
  • attrib stores any attributes
  • pos is the position in the file
  • Example ltbody bgcolorFFFFFF topmargin0
    leftmargin0 marginheight0 marginwidth0gt
  • The tag is body
  • The attributes are bgcolor, topmargin,
    leftmargin, marginheight (with their respective
    values)

16
handleEndTag
  • public void handleEndTag(HTML.Tag tag, int pos)
  • Called for tags like lt/agt
  • tag stores the name of the tag
  • pos is the position in the file

17
handleText
  • public void handleText(char data, int pos)
  • Handles anything thats not a tag (the text
    between tags)
  • data is an array of characters containing the
    text
  • pos is the position

18
Filling in these methods
  • You fill in these methods to do whatever
    processing you want
  • In the image collage example
  • handleSimpleTag is looking for images
  • handleStartTag is looking for the start of
    anchors and follows links
Write a Comment
User Comments (0)
About PowerShow.com