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.

Slides:



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

Made with love, by Zachary Langley Applets The Graphics Presentation.
MC365 Application Servers: Servlets. Today We Will Cover: What a servlet is The HTTPServlet and some of its more important methods How to configure the.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
Graphics Programming With Applets Feb 23, Applets There are three different types of executable java code. –Standalone application, which has main()
Servlets and a little bit of Web Services Russell Beale.
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.
18-Jun-15 Applets. 2 An applet is a program that is typically embedded in a Web page and can be run from a browser You need special HTML in the Web page.
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.
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.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 14 Applets, Images,
28-Jun-15 Applets. 2 An applet is a program that is typically embedded in a Web page and can be run from a browser You need special HTML in the Web page.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L05 (Chapter 16) Applets.
SE-2840 Dr. Mark L. Hornick1 Java Servlet-based web apps Servlet Architecture.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
Java Programming, 2E Introductory Concepts and Techniques Chapter 2 Creating a Java Application and Applet.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
Applets  The Applet Class  The HTML Tag F Passing Parameters to Applets.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
Applets, AWTS CompSci 230 Software Construction.
Chapter 12 Applets and Advanced Graphics  The Applet Class  The HTML Tag F Passing Parameters to Applets F Conversions Between Applications and Applets.
Chapter 17 - Deploying Java Applications on the Web1 Chapter 17 Deploying Java Applications on the Web.
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.
111 Java Servlets Dynamic Web Pages (Program Files) Servlets versus Java Server Pages Implementing Servlets Example: F15 Warranty Registration Tomcat Configuration.
 Embeds Java code  In HTML tags  When used well  Simple way to generate dynamic web-pages  When misused (complex embedded Java)  Terribly messy.
JAPPLET.
CMPUT 391 – Database Management Systems Department of Computing Science University of Alberta CMPUT 391 Database Management Systems Web based Applications,
Chapter 12 Applets and Advanced GUI  The Applet Class  The HTML Tag F Passing Parameters to Applets F Conversions Between Applications and Applets F.
Chapter 3 Servlet Basics. 1.Recall the Servlet Role 2.Basic Servlet Structure 3.A simple servlet that generates plain text 4.A servlet that generates.
Chapter 10: Applets and Advanced Graphics The Applet Class The Applet Class The HTML Tag The HTML Tag Passing Parameters to Applets Passing Parameters.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Java Applets 1. What is an applet? An applet is a small Java program that is typically embedded in a Web page and can be run using the applet viewer or.
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.
Writing Enterprise Applications with J2EE (Fourth lesson) Alessio Bechini June 2002 (based on material by Monica Pawlan)
MSc Workshop - © S. Kamin, U. ReddyLect 3 - GUI -1 Lecture 3 - Graphical User Interfaces r GUI toolkits in Java API r JFrame r GUI components.
Chapter 6 Applets and HTML  Overview  HTML tags for Applets  Applet Life Cycle  Applet Class  JAR files.
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
Chapter 10: Applets and Advanced Graphics The Applet Class The Applet Class The HTML Tag The HTML Tag Passing Parameters to Applets Passing Parameters.
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.
1 WWW. 2 World Wide Web Major application protocol used on the Internet Simple interface Two concepts –Point –Click.
1 Java Servlets l Servlets : programs that run within the context of a server, analogous to applets that run within the context of a browser. l Used to.
JS (Java Servlets). Internet evolution [1] The internet Internet started of as a static content dispersal and delivery mechanism, where files residing.
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.
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.
CIS Intro to JAVA Lecture Notes Set July-05 GUI Programming –TextField Action Listeners, JEditorPane action listeners, HTML in a JEditorPane,
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.
CHAPTER Agenda Applets Servelets Browsers HelloWorld.
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 10.
1 Applets Programming. Introduction Java programs are divided into two main categories, applets and applications. An application is an ordinary Java program.
30 Java Applets.
Distributed Computing, M. L. Liu
Distributed Computing, M. L. Liu
UNIT-5.
Introduction to Computing Using Java
Java Applets.
Java applets 1/3/2019.
Java Programming COMP-417 Applet
JAVA APPLET PREPARED BY Mr. Jahanzaib Ahmed
G6DICP - Lecture 27 Java Applets.
APPLET PROGRAMMING.
Presentation transcript:

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 means definitive (or even necessarily completely correct)

Applets

An applet is a special type of Java program designed to run inside a web browser (or an applet viewer.) Applets are one way to create “live” web pages. Applets are constrained in what they are allowed to do. See: users.aber.ac.uk/ltt/test-applet

A Simple Applet Example also in this web space with lectures

Applet lifecycle 1: Browser - HTML - Java a browser JVM

Applet lifecycle 2: The Applet / Browser Protocol (in theory) 1. Browser accesses page loads applet and calls init() 2. Having loaded applet and called init() start() the applet is now running and has drawn itself 3. The browser leaves the page stop() 4. If the page is accessed again start() 5. If the browser is exited destroy() calls

Notice that the applet runs on the client, but comes from the server It should be obvious that this has implications with respect to reading and writing files. You don’t want someone’s random applet writing and reading in your filestore! See later about webstart To debug you need the java console to show - settings More on all this in later modules

Steps 1.The html to run it issue of getting right version of JVM in browser 2.The applet code itself (extends Japplet) issue of threads

The applet tag is now obsolete in html 5 You have to use instead I have not yet investigated this

1. Start with this html in whatever.html <applet code="Silly.class" width=305 height= 205> source

Issue of getting the right version of the JVM in the browser Start with your html file as I showed Run HtmlConverter on it Will insert extra tags to enable: – Dynamic download of Java plug-in on first request – Use of local plug-in libraries subsequently instead of the browser’s default Java run-time libraries Available in Windows or on Suns – I used HtmlConverter index.html on Sun or HtmlConverter -gui Don’t forget to set right permissions – I did chmod 755 *

Ends up looking like: <object classid = "clsid:CAFEEFAC ABCDEFFEDCBA" codebase = " WIDTH = 305 HEIGHT = 205 > <embed type = "application/x-java-applet;jpi-version=1.6.0_02" \ CODE = "Silly.class" \ WIDTH = 305 \ HEIGHT = 205 scriptable = false pluginspage = " <!-- --> source

2. Defining the JApplet (note Swing stuff) import java.applet.*; import java.awt.event.*; import java.awt.*; import javax.swing.*; public class Silly extends JApplet implements MouseListener{ static final int MAXLOCS=100; private Dimension Locs[]; private int NumClicks; private DrawArea drawing; public Silly() { NumClicks=0; Locs=new Dimension[MAXLOCS]; } public void init() { this.addMouseListener(this); drawing=new DrawArea(); add(drawing,BorderLayout.CENTER); setSize(300,200); } public void mouseReleased(MouseEvent e){} public void mousePressed(MouseEvent e){} public void mouseEntered( MouseEvent e){} public void mouseExited( MouseEvent e){} public void mouseClicked( MouseEvent e) { int x=e.getX(); int y=e.getY(); if(NumClicks<MAXLOCS-1) { Locs[NumClicks]=new Dimension(x,y); NumClicks++; repaint(); } ////////////////////////////////////////// class DrawArea extends JPanel{ public DrawArea() { setSize(300,200); } public void paintComponent(Graphics g) { g.drawRect(1,1,299,199); for (int i=0;i<NumClicks ; i++) for (int j=0;j<NumClicks;j++) g.drawLine(Locs[i].width, Locs[i].height, Locs[j].width, Locs[j].height); }

Methods init() - Called by the browser or applet viewer to inform this applet that it has been loaded into the system. destroy() - Called by the browser or applet viewer to inform this applet that it is being reclaimed and that it should destroy any resources that it has allocated. start() - Called by the browser or applet viewer to inform this applet that it should start its execution. NOTE this may be called many times !, e.g. every time a window is resized, when a page is re-visited and so on. stop() - Called by the browser or applet viewer to inform this applet that it should stop its execution. NOTE this may be called many times !, e.g. every time a window is resized, when a page is left

String getParameter(String name) – Returns the value of the named parameter in the HTML tag. void showStatus(String msg) – Requests that the argument string be displayed in the "status window“ void play(URL url, String name) – Plays the audio clip given the URL and a specifier that is relative to it.

In order to load an Image into an applet: You use a method called getDocumentBase() to find the applet’s path and put Image file there Relevant bits of code: import java.net.URL; ….. Image my_gif; URL base; ….. try { base = getDocumentBase(); } catch (Exception e) {} ….. my_gif = getImage(base,"icon1.gif"); public void paintComponent(Graphics g) { g.drawImage(my_gif, 20,20,this);

The above should be enough to let you create an Applet version of your cartoonmaker Write the application version Replace ‘extends JFrame’ with ‘extends JApplet’ Pare it down (take out the save and load) Remove the main, and put in an init() method Write a basic html file and HtmlConvert it Put it all in your public_html directory Get the permissions right Bob’s your uncle! (make sure you can see Java console – use controlpanel settings)

In order to get an applet to work with a JTextField in it See applet-simple-input-too

Applets and SwingWorker Applets are often (usually?) Swing applications That means that we need to pay attention to the things we said about SwingWorker and threads: First, in the init method we should ask the event dispatch thread to build our user interface rather than doing it ourself – see applet-simple (and over) Second, we should use a SwingWorker thread to do complex processing so GUI doesn’t freeze - see applet-swingworker in this directory

public Silly() { NumClicks=0; Locs=new Dimension[MAXLOCS]; } public void init() { try { SwingUtilities.invokeAndWait ( new Runnable() { public void run() { buildGUI(); } ); } catch (Exception e) { System.err.println("Attempt to use invoke and wait threw exception " + e);} } public void buildGUI() { this.addMouseListener(this); drawing=new DrawArea(); add(drawing,BorderLayout.CENTER); setSize(300,200); }

You can launch an applet by specifying the applet's launch properties directly in the applet tag. This old way of deploying applets imposes severe security restrictions on the applet. Alternatively, you can launch your applet by using Java Network Launch Protocol (JNLP). Applets launched by using JNLP have access to powerful JNLP APIs and extensions.

webstart e/tutorial/deployment/webstart/in dex.html

Another possibility is to use webstart instead to start an application. There is an example of that in Along with some notes I made while getting it working

Webstart With Java Web Start software, users can launch a Java application by clicking a link in a web page. The link points to a Java Network Launch Protocol (JNLP) file, which instructs Java Web Start software to download, cache, and run the application.

Servlets nlineTraining/Programming/Basic Java1/servlet.html

a Servlet is a Java class server-side code standards are set through Java APIs – tighter, with more checking, that other technologies an HTTP server (eg. Tomcat) knows that a URL represents a Java class instance there must be a JVM running the URL and a class must be associated the server knows what method to call and what parameters details of the HTTP request have to be delivered to the class the result from the class has to be delivered as an HTTP response

Containers a specialised server typically a Java application offers HTTP has a running JVM the servlet will be running in it Examples Tomcat -

HTML is something like: The servlet example A simple web application Enter Some Text

The doPost method performs the HTTP POST operation, which is the type of operation specified in the HTML form used for this example. POST requests are for sending any amount of data directly over the connection without changing the URL uses the response object to create an HTML page and then puts html in it

Methods doGet, doPost also init() called at startup and destroy() called at shutdown

JSPs JSPs are a higher level abstraction of servlets They are compiled into servlets by a JSP Compiler A JSP compiler may generate a servlet in Java code that is then compiled by the Java compiler, or it may generate byte code for the servlet directly.

a JSP <%= toStringOrBlank ( "expanded inline data " + 1 ) %>

This has been a lot of ‘handwaving’ I know Just introducing you here to some things that you may find useful before they are covered properly in years 2 and 3 Last year the 2 nd year group project used JSPs for instance and I thought it would be useful for you to know some of the things to google