ISE 582: Web Technology for Industrial Engineering University of Southern California DJE Dept of Industrial and Systems Engineering Lecture 9 JAVA Cup.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming Lecture 10 Applets.
Advertisements

Made with love, by Zachary Langley Applets The Graphics Presentation.
Computer Science 209 Applets. Applications and Applets A Java application runs on a stand-alone computer and may connect to other computers via sockets.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
Slides prepared by Rose Williams, Binghamton University Mouse Events + Chapter 17: Applets.
Applets. The Applet Class public class MyApplet extends java.applet.Applet {... /** The no-arg constructor is called by the browser when the Web page.
Review of Java Applets Vijayan Sugumaran Decision and Information Sciences Oakland University.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 16 Applets.
1 Applets. 2 Motivations When browsing the Web, you frequently see the graphical user interface and animation developed using Java. These programs are.
Slides prepared by Rose Williams, Binghamton University Chapter 18 Applets.
1 Applets Chapter 1 To understand:  why applets are used to extend the capabilities of Web pages  how an applet is executed and know about the restrictions.
Chapter 14 Applets. 2 Knowledge Goals Understand the differing roles of applications and applets Understand how a browser operates Understand the role.
ISE 582: Web Technology for Industrial Engineering University of Southern California DJE Dept of Industrial and Systems Engineering Lecture 7 JAVA Cup.
1 Recitation 11. Applet Applets. An applet is a Java program that is started by a browser (e.g. netscape or internet explorer) when an html file has a.
Slides prepared by Rose Williams, Binghamton University Chapter 18 Applets.
Java Applets. Lecture Objectives Learn about Java applets. Know the differences between Java applets and applications. Designing and using Java applets.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 14 Applets, Images,
ISE 582: Information Technology for Industrial Engineering Instructor: Elaine Chew University of Southern California Department of Industrial and Systems.
ISE 582: Information Technology for Industrial Engineering Instructor: Elaine Chew University of Southern California Department of Industrial and Systems.
ISE 582: Information Technology for Industrial Engineering Instructor: Elaine Chew University of Southern California Department of Industrial and Systems.
ISE 582: Web Technology for Industrial Engineers University of Southern California Department of Industrial and Systems Engineering Lecture 4 JAVA Cup.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L05 (Chapter 16) Applets.
Applets, HTML and GUI’s Recitation – 04/11/2008 CS 180 Department of Computer Science, Purdue University.
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
Java Programming, 2E Introductory Concepts and Techniques Chapter 2 Creating a Java Application and Applet.
Applets  The Applet Class  The HTML Tag F Passing Parameters to Applets.
Applets Java API.
19-Sep-15 Air Force Institute of Technology Electrical and Computer Engineering Object-Oriented Programming Design Topic : Applets Maj Joel Young
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
JAVA APPLETS By: Ms. Humaira Siddiqui. Java and the Internet Java is considered to be a language well suited to be used in the internet. In contrast with.
Applets Chapter 17.  Java’s big splash onto the scene came in the mid 90’s. The people at Sun Microsystems had managed to work java programs into Web.
JAPPLET.
Applets Life Cycle Drawing and Event Handling Methods for UI Components Applet Capabilities Example.
1 INF160 IS Development Environments AUBG, COS dept Lecture 04 Title: Computer Applications (Extract from Syllabus)
Chapter 17: Applets, Images, and Sound. Objectives Learn about applets Write an HTML document to host an applet Use the init() method Work with JApplet.
Not all java code is an application! Applets, Webstart and Servlets Warning: this is just to show you where to look and some things to look for – by no.
GUI programming Graphical user interface-based programming.
Applets. What is an applet? Why create applets instead of applications? – Applets are Java programs that can be embedded in an HTML document – In contrast,
CSC 205 – Java Programming II Applet. Types of Java Programs Applets Applications Console applications Graphics applications Applications are stand-alone.
Pravin Yannawar, DOCS, NMU Jalgaon Basic Java : Applets 2 Objectives of This Session Identify the need for Applets Distinguish between Applets and Applications.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 16 Applets and Multimedia.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Applets and Multimedia.
Chapter 14 Applets and Advanced GUI  The Applet Class  The HTML Tag F Passing Parameters to Applets F Conversions Between Applications and Applets F.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
Creating Applets. What is an applet? What is an applet? A Java program that runs in a web browser. A Java program that runs in a web browser. An applet.
CIS Intro to JAVA Lecture Notes Set July-05 GUI Programming – Home and reload buttons for the webbrowser, Applets.
1 GUI programming Graphical user interface-based programming Chapter G1 (pages )
1 Applets are small applications that are accessed on an Internet server, transported over the internet, automatically installed and run as a part of web.
1 Applets. 2 Design of Applets 3 Sun wrote Java to be executable within a hosting application browser The applications are applets. An applet is downloaded.
Chapter 131 Applets and HTML Chapter Objectives learn how to write applets learn to write a simple HTML document learn how to embed an applet in.
Applets, Images, and Audio Chapter 14 CSCI CSCI 1302 – Applets, Images, and Audio2 Outline Introduction The Applet Class –The init Method –The start.
Applets Java code is compiled into byte code instead of machine language –Languages like C, C++, Pascal and others are compiled into machine language so.
Creating a Java Application and Applet
1 Applets. 2 What is an applet? Applet: a Java program that can be inserted into a web page and run by loading that page in a browser brings web pages.
Introduction to Applets Chapter 21. Applets An applet is a Java application that is intended to be invoked and executed through a Web browser. Click Here.
SourceAnatomy1 Java Source Anatomy Barb Ericson Georgia Institute of Technology July 2008.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
1 Applets Programming. Introduction Java programs are divided into two main categories, applets and applications. An application is an ordinary Java program.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 17 : Applets King Fahd University of Petroleum & Minerals College of Computer Science.
Chapter 14 Applets. Applets: Introduction Java programs are divided into two main categories, applets and applications An application is an ordinary Java.
Applets.
Distributed Computing, M. L. Liu
Distributed Computing, M. L. Liu
Graphical user interface-based programming
UNIT-5.
Introduction to Computing Using Java
Java applets 1/3/2019.
11.1 Applets & graphics.
JAVA APPLET PREPARED BY Mr. Jahanzaib Ahmed
G6DICP - Lecture 27 Java Applets.
Presentation transcript:

ISE 582: Web Technology for Industrial Engineering University of Southern California DJE Dept of Industrial and Systems Engineering Lecture 9 JAVA Cup 8: Applets

14 November 2002Web Technology for IE2 Handouts & Announcements Lecture 9 slides READ Winston & Narasimhan : –Chapters (pp )

14 November 2002Web Technology for IE3 JAVA Cup 8 Standalone Observers / Listeners Defining Applets Calling Applets from Web Browsers Resource Allocators Making Lists for Selection Adding Images to Applets

14 November 2002Web Technology for IE4 Hierarchy of Swing Classes

14 November 2002Web Technology for IE5 Review the Model-View Approach Model View Application

14 November 2002Web Technology for IE6 Standalone Observers / Listeners Goal: move Observers / Listeners into independent files Changes: –Establish a MovieApplication instance variable in the class –Include the application instance as an argument to the constructor –Assign the application instance variable in the constructor

14 November 2002Web Technology for IE7 Example: Old format import java.util.*; public class MovieObserver implements Observer { public void update (Observable observable, Object object) { getMeter().setValue(getMovie().rating()); // BUG! getMeter().setTitle(getMovie().getTitle()); // BUG! }

14 November 2002Web Technology for IE8 Example: New Format import java.util.*; public class MovieObserver implements Observer { private MovieApplication applet; public MovieObserver (MovieApplication a) { applet = a; } public void update (Observable observable, Object object) { applet.getMeter().setValue(applet.getMovie().rating()); applet.getMeter().setTitle(applet.getMovie().getTitle()); } In setMovie: movie.addObserver(new MovieObserver(this));

14 November 2002Web Technology for IE9 Similar Changes in MeterListener import java.awt.event.*; public class MeterListener extends MouseAdapter { MovieApplication applet; public MeterListener (MovieApplication a) { applet = a; } public void mouseClicked (MouseEvent e) { int x = e.getX(); int y = e.getY(); int v = (int) Math.round(applet.getMeter().getValueAtCoordinates (x, y) / 3.0 ); applet.getMovie().setScript(v); applet.getMovie().setActing(v); applet.getMovie().setDirection(v); }} In setMeter: meter.addMouseListener(new MeterListener(this));

14 November 2002Web Technology for IE10 Applets Properties Browser Conventions What Applets Cannot Do What Applets Can Do Accessing Applets from Web Browsers

14 November 2002Web Technology for IE11 Applets: Properties Applets have no main methods. The applet’s size is determined by the html file (no calls to setSize, show). There are no WindowAdapter subclass and no windowClosing method in JApplet classes.

14 November 2002Web Technology for IE12 Changing to an Applet extend JApplet instead of Jframe Remove main method Remove WindowListener and call to addWindowListener, do not import java.awt.event package Constructor need not pass title to super(), eliminate calls to setSize, show Application

14 November 2002Web Technology for IE13 Browser Conventions When a browser loads an applet, it calls: –the constructor –the init method (default init does nothing) –the start method (contains computations to be performed to start the applet) When the applet page is replaced, it calls: –the stop method (also called before destroy) When the applet page is abandoned completely, it calls: –the destroy method

14 November 2002Web Technology for IE14 What Applets Cannot Do Load libraries or define native methods. Read/write files on the host that's executing it. Make network connections except to the host that it came from. Start any program on the host that's executing it. Read certain system properties. Windows that an applet brings up look different than windows that an application brings up.

14 November 2002Web Technology for IE15 What Applets Can Do Play Sounds Make network connections to the host they came from. Cause HTML documents to be displayed. Invoke public methods of other applets on the same page. Applets that are loaded from the local file system have none of the restrictions that applets loaded over the network do. Keep running after you leave their page.

14 November 2002Web Technology for IE16 Calling an Applet from an HTML file When a Java-enabled browser encounters an tag, it: –reserves a display area of the specified width and height for the applet, –loads the bytecodes for the specified Applet subclass, –creates an instance of the subclass, and then –calls the instance's init and start methods.

14 November 2002Web Technology for IE17 Using Resource Locators Why use Resource Locators? The Class class Using the Class class How Resource Locators work Accessing Image Files

14 November 2002Web Technology for IE18 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 2002Web Technology for IE19 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 2002Web Technology for IE20 Using the Class class public class MovieAuxiliaries { public static Vector readMovieFile(String fileName) { Vector v = new Vector(); URL url = MovieAuxiliaries.class.getResource(fileName); InputStream stream = (InputStream) (url.getContent()); InputStreamReader reader = new InputStreamReader(stream);... } } Auxiliaries streamreadertokens

14 November 2002Web Technology for IE21 How Resource Locators Work The resource locator starts looking for the file in the same location as the class If the filename includes a relative path, the resource locator will look for the file in the subdirectory of the directory holding that class If the class is part of a browser, this determines the security rules employed Why insist on the same-place restriction?

14 November 2002Web Technology for IE22 Accessing Image Files import java.net.*; import java.awt.image.*; Blah blah blah… public static Image readMovieImage(String fileName) { try { URL url = MovieAuxiliaries.class.getResource(fileName); if (url == null) {return null;} ImageProducer producer = (ImageProducer) (url.getContent()); if (producer == null) {return null;} Toolkit tk = Toolkit.getDefaultToolkit(); Image image = tk.createImage(producer); return image; } catch (IOException e) { System.out.println(e); }; return null; } Blah blah blah… Auxiliaries

14 November 2002Web Technology for IE23 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 2002Web Technology for IE24 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 2002Web Technology for IE25 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 2002Web Technology for IE26 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 2002Web Technology for IE27 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 2002Web Technology for IE28 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)); }

14 November 2002Web Technology for IE29 Final Changes Blah blah blah… public void setMovieData (MovieData m) { movieData = m; movieData.addObserver(new MovieDataObserver(this)); movieData.changed(); } public void setJList (JList j) { jList = j; jList.addListSelectionListener(new MovieListListener(this)); } Blah blah blah… Application

14 November 2002Web Technology for IE30 Using a Scroll Pane Instead of –getContentPane().add(“East”,getJList()); Use –getContentPane().add(“East”,new JScrollPane(getJList()));