ISE%20582:%20Web%20Technology%20for%20Industrial%20Engineering - PowerPoint PPT Presentation

About This Presentation
Title:

ISE%20582:%20Web%20Technology%20for%20Industrial%20Engineering

Description:

ISE 582: Web Technology for Industrial Engineering. University of Southern California ... throws IOException, ClassNotFoundException ... – PowerPoint PPT presentation

Number of Views:37
Avg rating:3.0/5.0
Slides: 27
Provided by: elain90
Category:

less

Transcript and Presenter's Notes

Title: ISE%20582:%20Web%20Technology%20for%20Industrial%20Engineering


1
ISE 582 Web Technology for Industrial Engineering
  • University of Southern California
  • DJE Dept of Industrial and Systems Engineering

Lecture 7
JAVA Cup 7 Its all in the Packaging
2
Handouts
  • Lecture 7 slides
  • READ Winston Narasimhan
  • Chapters 33-38 (pp 201-233)

3
JAVA Cup 7
  • Characters and Strings
  • Codestrings and delimiters
  • How to Read/Write Objects
  • How to Modularize Programs
  • Creating a Window

4
Specifying Delimiters
  • You can use codestrings to specify interesting
    information in textfile

5
Specifying Delimiters
  • To advise the tokens tokenizer to use double
    quotation marks to delimit strings
  • tokens.quoteChar((int) )
  • To tell the tokenizer to recognize carriage
    returns
  • tokens.eolIsSignificant(true)

6
Working with O/p File Streams
  • To connect to output file
  • FileOutputStream stream new FileOutputStream(ou
    tput.data)
  • To write more than 1-byte-at-a-time
  • PrintWriter writer new PrintWriter(stream)
  • Its good to flush out buffered characters
  • writer.flush()
  • Close the file
  • stream.close()

7
Reading / Writing Objects
  • Serialized input-output operations
  • ltobj.o/p.streamgt.writeObject(ltvectorgt)
  • ltobj.i/p.streamgt.readObject()
  • Indicate intentions to use operations by
  • implements Serializable
  • throws IOException, ClassNotFoundException
  • Each instance must belong a class that implements
    the Serializable Interface

8
Review
stream
writer
9
Reading Objects from File
  • FileInputStream fileInputStream
  • new FileInputStream(in.data)
  • ObjectInputStream objectInputStream
  • new ObjectInputStream(fileInputStream)
  • Vector ltvectorgt
  • (Vector) objectInputStream.readObject()

10
To Write Objects to File
  • FileOutputStream fileOutputStream new
    FileOutputStream(out.data)
  • ObjectOutputStream objectOutputStream new
    ObjectOutputStream(fileOutputStream)
  • objectOutputStream.writeObject(ltvectorgt)
  • objectOutputStream.close()

11
Modularing Your Program
  • Compilation Units
  • Packages
  • Setting CLASSPATH
  • Calling Methods from a Module
  • Access to Var/Methods in Package

12
Compilation Units
  • Define all classes in same file
  • Only one class can be public
  • Only one class is universally accessible
  • Convention each class has its own compilation
    unit

13
Packages
  • Use single-class compilation units
  • Indicate module using package statement at
    beginning of each c.u
  • package onto.java.entertainment
  • Convention package names consist of components
    separated by dots

14
CLASSPATH
  • Package names correspond to paths
  • package onto.java.entertainment
  • Files stores in ./onto/java
  • Setting the path
  • setenv CLASSPATH ltpath1gtltpath2gt.
  • setenv CLASSPATHltpath1gtltpath2gt.

UNIX
PC
15
Using Methods from a Package
  • First import package
  • import onto.java.entertainment.
  • Auxiliaries.readMovieFile(input.data)
  • ((Movie) vectorElement).rating()
  • Or, refer to entire name
  • onto.java.entertainment.Auxiliaries.readMovieFile
    (input.data)
  • ((onto.java.entertainment.Movie)
    vectorElement).rating()

16
Access to Variables/Methods
  • private
  • available only to methods inside own class
  • protected
  • available to methods in same class, c.u. or
    package, subclasses
  • No keyword
  • available only to c.u. or package

17
How to Create Windows
  • Nomenclature
  • Intro to Swing classes
  • Hierarchy of Swing classes
  • Listener Classes
  • Window Creation Pattern

18
Nomenclature
  • GUI (pronounced goo-ey)
  • Graphical User Interface
  • Components
  • class instances that have a graphical
    representation
  • Containers
  • components that allow nesting of other containers
    inside their boundaries
  • Window
  • a containers graphical representation

19
Introduction to Swing (J) Classes
  • API Application Programmers Interface
  • The AWT Package java.awt.
  • AWT Abstract Window Toolkit
  • contains Component, Container classes
  • The Swing Package java.swing.
  • contains JFrame, JApplet, JComponent, JPanel
    classes
  • Try to restrict display work to Swing classes

20
Hierarchy of Swing Classes
21
Example A Window
  • import javax.swing.
  • public class Demonstrate
  • public static void main (String argv )
  • JFrame frame new JFrame (I am a window,
    square and proud)
  • frame.setSize(200,200)
  • frame.show()

22
Listener Classes
  • Event as a state change
  • Mouse clicks and key presses
  • Variable-value changes
  • Event as instance of EventObject class
  • Describes state change
  • Java deals with events through Listener Classes
  • Listener classes are defined by
  • Extending existing listener classes
  • Implementing listener interfaces

23
Example Link listener to frame
  • When mouse clicks
  • a WindowEvent instance is created
  • the windowClosing method is called with connected
    listener as target and WindowEvent instance as arg

24
Adapter Classes
  • Adapter classes implement all interface-required
    methods as do-nothing methods.
  • You can define shadowing methods in your subclass
    for whatever subset of methods you need

25
Nesting Class Definitions
  • Advantage of nesting classes
  • Method definition (windowClosing) appears in
    proximity to window definition
  • Can reuse names of private classes such as
    LocalWindowListener

26
Window Creation Pattern
  • Define a subclass of JFrame class
  • Main method calls constructor
  • Constructor
  • assigns title, size, and displays a window
  • creates required class instances
  • connects class instances
Write a Comment
User Comments (0)
About PowerShow.com