Docsity

Web Technology for Industrial Engineering: Resource Locators and Image Files in Java, Study notes of Engineering

Toggle sidebar
bg1
Web Technology for IE 14 November 2002
http://www-classes.usc.edu/engr/ise/582 1
ISE 582: Web Technology for
Industrial Engineering
University of Southern California
DJE Dept of Industrial and Systems Engineering
Lecture 10
JAVA Cup 8: Applets
14 November 2002 Web Technology for IE 2
Handouts & Announcements
• Lecture 9 slides
• READ Winston & Narasimhan :
– Chapters 42-46 (pp 275-304)
14 November 2002 Web Technology for IE 3
JAVA Cup 9
• Resource Locators
•Making Lists for Selection
•Adding Images to Applets
pf3
pf4
pf5

Partial preview of the text

Download Web Technology for Industrial Engineering: Resource Locators and Image Files in Java and more Study notes Engineering in PDF only on Docsity!

ISE 582: Web Technology for

Industrial Engineering

University of Southern California

DJE Dept of Industrial and Systems Engineering

Lecture 10

JAVA Cup 8: Applets

14 November 2002 Web Technology for IE 2

Handouts & Announcements

• Lecture 9 slides

• READ Winston & Narasimhan :

– Chapters 42-46 (pp 275-304)

14 November 2002 Web Technology for IE 3

JAVA Cup 9

• Resource Locators

• Making Lists for Selection

• Adding Images to Applets

14 November 2002 Web Technology for IE 4

Using Resource Locators

  • Why use Resource Locators?
  • The Class class
  • Using the Class class
  • How Resource Locators work
  • Accessing Image Files

14 November 2002 Web Technology for IE 5

Why Use Resource Locators

  • They find files even after you have

moved your program from one

directory to another

  • They find files properly not only for

standalone applications, but also for

browser applications

14 November 2002 Web Technology for IE 6

The Class class

  • When the JVM loads a class / interface,
    • it creates a companion “Class” instance
  • The “Class” instance provides
    • information about the class’s name and instance variables
    • access to methods for locating resources such as text and image files

14 November 2002 Web Technology for IE 10

Using Choice Lists

  • A new MovieData class
  • Modifications to the Model side
  • Modifications to the View side
  • Linking the new model and new view
  • Final changes
  • Using a ScrollPane

14 November 2002 Web Technology for IE 11

MovieDataInterface

import java. util.*;

public interface MovieDataInterface {

// Put movies into data source:

public abstract void setMovieVector (Vector v) ;

// Extract movies from data source:

public abstract Vector getMovieVector () ;

// Find a particular movie at given index:

public abstract Movie getMovie(int index) ;

// Miscellaneous method:

public abstract void changed () ;

14 November 2002 Web Technology for IE 12

Modifications to the Model

Blah blah blah… private MovieData movieData; Blah blah blah… public MovieData getMovieData () { if (movieData == null) { setMovieData(new MovieData ()); } return movieData; } Blah blah blah… public void setMovieData (MovieData m) { movieData = m; movieData.addObserver(new MovieDataObserver(this)); movieData.changed(); } Blah blah blah…

Application

14 November 2002 Web Technology for IE 13

Modifications to the View

Blah blah blah… private JList jList; Blah blah blah… public MovieApplication() { getMovie(); getMovieData(); getContentPane().add(“Center”, getMeter()); getContentPane().add(“East”, getJList()); } Blah blah blah… public JList getJList () { if (jList == null) {setJList(new JList());} return jList; } Blah blah blah… public void setJList (JList j) { jList = j; }

Application

14 November 2002 Web Technology for IE 14

Linking Model and View

import java.util.; import javax.swing.; public class MovieDataObserver implements Observer { private MovieApplication applet; public MovieDataObserver (MovieApplication a) { applet = a; } public void update (Observable observable, Object object) { Vector titles = new Vector(); for (Iterator i = applet.getMovieData().getMovieVector().iterator(); i.hasNext();) { Movie movie = (Movie) (i.next()); titles .add(movie.getTitle()); } applet.getJList().setListData( titles ); } }

14 November 2002 Web Technology for IE 15

Linking Model and View

import javax.swing.*;

import javax.swing.event.*;

public class MovieListListener implements ListSelectionListener

private MovieApplication applet;

public MovieListListener (MovieApplication a) {

applet = a;

public void valueChanged(ListSelectionEvent e) {

int index = applet. getJList(). getSelectedIndex ();

applet.setMovie(applet.getMovieData ().getMovie(index));