Unit 071 Review of Applets Learning Outcomes oDistinguish between Java Applications and Java Applets. oWrite applet programs that can load images and play.

Slides:



Advertisements
Similar presentations
1 More on Applets Overview l Changing Colors l Changing Fonts & Styles l Applet Life-Cycle l Input using Dialog Window l Input using HTML parameters l.
Advertisements

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()
Graphics Programming UQC117S2 Semester /4. Session 3 1 Drawing in Java 2D Graphics API.
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.
1 Introduction to Applets Overview l What is an Applet? l Steps for creating an applet l What is HTML? l Basic HTML tags l Drawing Simple Graphical shapes.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 16 Applets.
2D Graphics in Java COMP53 Nov 14, Applets and Applications Java applications are stand-alone programs – start execution with main() – runs in JVM.
1 Review of applets & Computer Graphis GUILecture 6 Review of Applets & Compute Graphics GUI Overview  Introduction to Graphics. Applets: a quick review.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 14 Applets, Images,
APPLETS CSC 171 FALL 2004 LECTURE 6. APPLETS Graphical Java programs Run inside web browser Platform-neutral Easy deployment--loads when needed Secure.
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
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.
Web Design & Development Lecture 18. Java Graphics.
Java Applets. Lecture Objectives  Learn about Java applets.  Know the differences between Java applets and applications.  Designing and using Java.
Applets  The Applet Class  The HTML Tag F Passing Parameters to Applets.
Applets CS 3331 Sections 3.3 & 4.7 of [Jia03].
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.
Internet Software Development Applets Paul J Krause.
Java applet basics, loading & displaying images After this section, you should be able to : –Use the applet tag and applet parameters –Describe what a.
JAPPLET.
COP 4331 – OOD&P Lecture 6. Review Midterm Review Complete sample application –See SwingColorTest.java.
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.
GUI programming Graphical user interface-based programming.
Object Oriented Programming Lecture 4: Refactoring, An Applet Example, Idiom - Animation applets, Introduction to the Laboratorial exercise www2.hh.se/staff/jebe/oop2005/
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.
J McQuillan SE204: 2004/2005: Lecture 4slide 1 The Graphics Class Used when we need to draw to the screen Two graphics classes –Graphics –Graphics2D.
Canvas and Graphics CS 21a. 9/26/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L17: Canvas.
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,
1 CSC Computer Education (P) Ltd. DESIGNED BY K PRAKASH,
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.
The Drawing program – Java Applets
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.
Chapter 6 Applets and HTML  Overview  HTML tags for Applets  Applet Life Cycle  Applet Class  JAR files.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Review of Graphics in Java,
Lec 16 Adding Mouse and KeyEvent handlers to an Applet Class.
1 GUIs, Layout, Drawing Rick Mercer. 2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces (GUIs)
APPLET. 2 Introduction to Java Applet Programs Applications are stand alone programs ◦ executed with Java interpreter Applet is a small program ◦ can.
Java Programming Working with Sound and Images. Topics Learn about the paint() and repaint() methods Learn about paintComponent() method Use the drawString()
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 GUIs, Layout, Drawing Rick Mercer. 2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces (GUIs)
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.
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.
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.
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 10.
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
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 Getting Started. Import Files In order to run the applet properly, we have to import some files into our class. These files are: –import.
Java Applets.
Java Graphics.
Java Applets.
Distributed Computing, M. L. Liu
Distributed Computing, M. L. Liu
UNIT-5.
Java Applets.
Java Applets.
Java applets 1/3/2019.
Java Programming COMP-417 Applet
JAVA APPLET PREPARED BY Mr. Jahanzaib Ahmed
APPLET PROGRAMMING.
Presentation transcript:

Unit 071 Review of Applets Learning Outcomes oDistinguish between Java Applications and Java Applets. oWrite applet programs that can load images and play sound. oExplain the limitations of constructors in applet programs. Applications and Applets Example 1: Passing Parameters to Applets The Graphics and the Graphics2D Classes Example 2: Loading Images and Playing Sounds How Java Loads and Displays Images Example 3: Applet and Application Hybrid

Unit 072 Applications and Applets A Java program can be an application, applet or both. A Java application is a stand-alone, unrestricted program. A Java applet is a restricted program that relies on another program to execute. A Java applet executes under a Web browser or applet viewer. An applet is defined by extending the Applet or the JApplet class.

Unit 073 Life Cycle of an Applet An applet may call the following methods in its life cycle: 1.init() 2.start() 3.stop() 4.paint() 5.destroy() By default, these methods have empty implementations.

Unit 074 Example 1: Passing Parameters to Applets 1 import javax.swing.*; import java.awt.*; 2 public class AppletParameters extends JApplet{ 3 private int size; 4 private String font; 5 private String message; 6 public void init() { 7 size = Integer.parseInt(getParameter("size")); 8 font = getParameter("font"); 9 message = getParameter("message"); 10 } 11 public void paint(Graphics g) { 12 g.setColor(Color.green); 13 g.setFont(new Font(font, Font.PLAIN, size)); 14 g.drawString(message,20, 50); 15 Font myFont = new Font("Dialog", Font.BOLD, 36); 16 g.setFont(myFont); g.setColor(Color.red); 17 g.drawString("You are Welcome to CCSE", 20, 100); 18 g.setColor(Color.blue); 19 g.setFont(new Font("Courier", Font.BOLD+Font.ITALIC, 24)); 20 g.drawString("This is Introduction to Computer Science", 20, 150); 21 } 22 }

Unit 075 The Graphics and the Graphics2D Classes Drawing graphics is done differently on different computer platforms. Java provides an abstract Graphics class that covers all platforms. The Graphics class was included with the first version of Java. A more sophisticated graphics class, Graphics2D, was introduced later. The Graphics2D class extends rather than replace Graphics.

Unit 076 Graphics and Graphics2D (cont’d) In many earlier programs, the public void paint(Graphics g) method includes the statement Graphics2D g2 = (Graphics2D)g; Each time paint is called it is passed a Graphics2D object for drawing in the display area An instance of Graphics or Graphics2D is called a graphics context. A graphics context represents a drawing surface. The Graphics2D object passed to paint is up-cast to Graphics. Additional functionality in Graphics2D is available after the down-cast.

Unit 077 Example 2: Loading Images, Playing Sounds 1 import javax.swing.*;import java.awt.*;import java.applet.*; 2 public class ImageAndSound extends Applet{ 3 Image image; AudioClip sound; 4 public void init( ) { 5 image = getImage(getDocumentBase(), "myImage.gif" ) ; 6 sound = getAudioClip(getDocumentBase(), "mySound.au" ) ; 7 setBackground(Color.red) ; 8 } 9 public void start( ) { 10 repaint(); 11 if (sound != null) 12 sound.loop(); 13 } 14 public void stop( ) { 15 sound.stop(); 16 } 17 public void paint(Graphics g){ 18 Graphics2D g2 = (Graphics2D)g; 19 g2.drawImage(image, 5, 5, this) ; 20 } 21 }

Unit 078 How Java Loads and Displays Images The preceding example reminds us of loading images and playing sounds To display an image you need to: 1. retrieve the image from a file or from an Internet source; 2. draw the image. The getImage method starts the loading process and returns immediately. Thus, Java loads images in an asynchronous manner. The benefit is that the program can do something if loading the image takes time.

Unit 079 How Java Displays Images (cont’d) Java will start loading a new image only when we attempt to display or manipulate the image Images are drawn using the overloaded drawImage method: drawImage(Image img, int x, int y, Color bgC, ImageObserver obs) The drawImage method starts the download and returns immediately. ImageObserver is an interface that the Component class implements. An image observer is informed about many aspects of the image. The image observer usually calls repaint to update the applet.

Unit 0710 Example 3: Applet and Application Hybrid import java.awt.*; import javax.swing.*; public class AppletApplication extends JApplet{ public void paint(Graphics g){ Graphics2D g2 = (Graphics2D)g; g2.drawString("Salaam Shabab!", 30,30); } public static void main(String args []){ JFrame f = new JFrame("Applet and Application"); AppletApplication applet = new AppletApplication(); Container cp = f.getContentPane(); cp.add(applet); f.setSize(150,150); f.setVisible(true); }