CSTP WS00CS423 (cotter)1 Java Applets Objective: Learn how to develop Java programs that interact with users through a Web browser.

Slides:



Advertisements
Similar presentations
Java Applets:. How Applets differ from application?: They do not use main method but init(), start() and paint() methods of the applet class They can.
Advertisements

Programming and Problem Solving With Java Copyright 1999, James M. Slack Applets What is an Applet? Applet Parameters Graphics in Applets Other Applet.
Graphics Programming With Applets Feb 23, Applets There are three different types of executable java code. –Standalone application, which has main()
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 Review of applets & Computer Graphis GUILecture 6 Review of Applets & Compute Graphics GUI Overview  Introduction to Graphics. Applets: a quick review.
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.
CS3157 Java UI Recitation. Material Covered: Overview of AWT components, Event Handling, creating applets, and sample UI. Not covered in recitation: Drawing,
Applets, Graphical User Interfaces, and Threads / Chapter 9 1 Applets, Graphical User Interfaces, and Threads.
Applet class The Applet class provides the essential framework that enables applets to be run by a web browser Applet do not have main method Applet depend.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 14 Applets, Images,
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L05 (Chapter 16) Applets.
Java Applets. Applets The term Applet refers to a little application. In JAVA the applet is a java program that is embedded within a HTML document and.
Programming Task: Task 1 Controlled Assessment Practice.
Applets  The Applet Class  The HTML Tag F Passing Parameters to Applets.
Chapter 9: Applets Jim Burns Fall Outline Learn about applets Learn about applets Write an HTML doc to host an applet Write an HTML doc to host.
Applets Java API.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
Applets CS 3331 Sections 3.3 & 4.7 of [Jia03].
Internet Software Development Applets Paul J Krause.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
Applets.
JAPPLET.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
GUI programming Graphical user interface-based programming.
Intro to Java Java Applications Swing Class Graphics.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Introduction to Applets Course Lecture Slides 29 th July 2010.
Applets Session 8. Java Simplified / Session 8 / 2 of 31 Review The Abstract Windowing Toolkit (AWT) is a set of classes that allow us to create a graphical.
Applets & Graphics. Applets programs that run inside a browser Java platform-independence makes applets possible security restrictions: –cannot read or.
CSTP FS99CS423 (cotter)1 Java Graphics java.awt.*;
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,
Pravin Yannawar, DOCS, NMU Jalgaon Basic Java : Applets 2 Objectives of This Session Identify the need for Applets Distinguish between Applets and Applications.
Java Applets: GUI Components, Events, Etc. Ralph Westfall June, 2010.
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
Java Programming Applets. Topics Write an HTML document to host an applet Understand simple applets Use Labels with simple AWT applets Write a simple.
Java Applet Basics (2). The Body Mass Index Calculator.
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.
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 Applications & Applets Standalone applications & Java applets Peter Mozelius DSV/UCSC.
Applets, Images, and Audio Chapter 14 CSCI CSCI 1302 – Applets, Images, and Audio2 Outline Introduction The Applet Class –The init Method –The start.
CSI 3125, Preliminaries, page 1 Applet. CSI 3125, Preliminaries, page 2 Graphics Methods public abstract void drawString(String str, int x, int y): is.
CSI 3125, Preliminaries, page 1 Applet. CSI 3125, Preliminaries, page 2 Applet An applet is a Java program that runs in a Web browser. An applet can be.
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.
1 Java Applet Basics Chapter Eight. 2 Applets vs. Applications l Applications: Stand alone Java programs run by interpreter l Applets WWW browser embedded.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
JAVA, JAVA, JAVA Object-Oriented Problem Solving Ralph Morelli Trinity College Hartford, CT presentation slides for published by Prentice Hall Second Edition.
Applets. 9/04/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L12: Applets Slide 2 Applets Usually.
1 Applets Programming. Introduction Java programs are divided into two main categories, applets and applications. An application is an ordinary Java program.
Creating an Object that can draw itself The paint method can ‘draw’ because it is passed a graphics environment as a parameter. If a class method is passed.
Java Applets.
Java Applets.
Chapter 13: Advanced GUIs and Graphics
Distributed Computing, M. L. Liu
Distributed Computing, M. L. Liu
Graphical user interface-based programming
Java Applets.
Java Applets.
Introduction to Applet, Application and JDK
Java applets 1/3/2019.
Applet in Java.
Java Programming COMP-417 Applet
11.1 Applets & graphics.
JAVA APPLET PREPARED BY Mr. Jahanzaib Ahmed
Enabling Application Delivery Via the Web
Advanced GUIs and Graphics
APPLET PROGRAMMING.
Presentation transcript:

CSTP WS00CS423 (cotter)1 Java Applets Objective: Learn how to develop Java programs that interact with users through a Web browser

CSTP WS00CS423 (cotter) 2 Java Applet Lifecycle Methods init ( ) –Called when applet is loaded onto user’s machine. Prep work or one-time-only work done at this time. start ( ) –Called when applet becomes visible (page called up). Called every time applet becomes visible. stop ( ) –Called when applet becomes hidden (page loses focus). destroy ( ) –Guaranteed to be called when browser shuts down.

CSTP WS00CS423 (cotter) 3 Applets vs. Applications Extend Applet instead of Frame Use of init( ) vs. constructor No use of main( ) Default layout managers –application: BorderLayout –applet: FlowLayout Security

CSTP WS00CS423 (cotter) 4 Applet Presentation Uses applet Tag in HTML MyNewApplet Here’s My first Applet

CSTP WS00CS423 (cotter) 5 Applet Inheritance (extension) Object - “cosmic base class” Component - button, listBox Container - dialog box Panel - “sub-window”, group of buttons, etc. Applet - small application, web enabled MyApplet - specific instance of an applet

CSTP WS00CS423 (cotter) 6 MyTextApplet import java.applet.*; import java.awt.*; import java.awt.event.*; public class MyTextApplet extends Applet { public void init() { setBackground(Color.gray); Panel p = new Panel(); ButtonAction aButtonAction = new ButtonAction(); p.setLayout(new FlowLayout()); tickButton = new Button("Tick"); tickButton.addActionListener(aButtonAction); p.add(tickButton);

CSTP WS00CS423 (cotter) 7 MyTextApplet setButton = new Button("Set time"); setButton.addActionListener(aButtonAction); p.add(setButton); hourField = new TextField("12", 3); p.add(hourField); minuteField = new TextField("00", 3); p.add(minuteField); timeField = new TextField("", 12); p.add(timeField); add(p); }

CSTP WS00CS423 (cotter) 8 MyTextApplet Class ButtonAction implements ActionListener { public void actionPerformed(ActionEvent evt) { String buttoncommand = evt.getActionCommand(); if (buttoncommand.equals("Tick")) { int minutes = Integer.parseInt(minuteField.getText()); minutes += 1; String min = String.valueOf(minutes); minuteField.setText(min); }

CSTP WS00CS423 (cotter) 9 MyTextApplet else if (buttoncommand.equals("Set time")) { int hours = Integer.parseInt(hourField.getText()); int minutes = Integer.parseInt(minuteField.getText()); String tim = hourField.getText() + ":" + minuteField.getText(); timeField.setText(tim); } } //end of ButtonAction private TextField hourField; private TextField minuteField; private TextField timeField; private Button tickButton; private Button setButton; }

CSTP WS00CS423 (cotter) 10 HTML file for MyTextApplet My Text Applet Demo Here's my Demo Applet

CSTP WS00CS423 (cotter) 11 MyTextApplet Output

CSTP WS00CS423 (cotter) 12 Parameter Passing to Applets import java.applet.*; import java.awt.*; public class FontApplet extends Applet { public void paint (Graphics g) { String fontName = getParameter ("font"); int fontSize = Integer.parseInt (getParameter("size")); Font f = new Font(fontName, Font.BOLD, fontSize); g.setFont (f); g.drawString("Welcome to CS423", 25, 50); }

CSTP WS00CS423 (cotter) 13 HTML file for FontApplet FontApplet Here’s a demo of parameter passing to an Applet

CSTP WS00CS423 (cotter) 14 FontApplet.htm

CSTP WS00CS423 (cotter) Using Applet Parameters in VJ++

CSTP WS00CS423 (cotter) 16 Java Applet Lifecycle Methods (again...) init ( ) –Called when applet is loaded onto user’s machine. Prep work or one-time-only work done at this time. start ( ) –Called when applet becomes visible (page called up). Called every time applet becomes visible. stop ( ) –Called when applet becomes hidden (page loses focus). destroy ( ) –Guaranteed to be called when browser shuts down.

CSTP WS00CS423 (cotter) 17 LifecycleApplet.java import java.applet.Applet; import java.awt.Graphics; public class LifecycleApplet extends Applet { public LifecycleApplet() { System.out.println("Constructor running..."); } public void init() { System.out.println("This is init."); } public void start() { System.out.println("Applet started."); } public void paint(Graphics theGraphics) { theGraphics.drawString("Hello, World!", 0, 50); System.out.println("Applet just painted."); } public void stop() { System.out.println("Applet stopped."); } public void destroy() { System.out.println("Applet destroyed."); } }

CSTP WS00CS423 (cotter) 18 LifecycleApplet.java

CSTP WS00CS423 (cotter) 19 LifecycleApplet.java

CSTP WS00CS423 (cotter) 20 Summary Java Applet managed through applet lifecycle Applet can interact with browser through HTML code Uses Event programming model to interact with user (using buttons, textfields, etc.)