Applets & Graphics. Applets programs that run inside a browser Java platform-independence makes applets possible security restrictions: –cannot read or.

Slides:



Advertisements
Similar presentations
2D Graphics Drawing Things. Graphics In your GUI, you might want to draw graphics E.g. draw lines, circles, shapes, draw strings etc The Graphics class.
Advertisements

Made with love, by Zachary Langley Applets The Graphics Presentation.
PHY-102 SAPIntroductory GraphicsSlide 1 Introductory Graphics In this section we will learn how about how to draw graphics on the screen in Java:  Drawing.
LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class.
Applets Graphical Java programs Run inside web browser Platform-neutral Easy deployment--loads when needed Secure.
Applets An applet is similar to a Java program, but it runs within a Web-browser on a client machine. For security, you cannot change anything on a client.
Graphics Programming With Applets Feb 23, Applets There are three different types of executable java code. –Standalone application, which has main()
1 A Simple Applet. 2 Applets and applications An application is an “ordinary” program Examples: Notepad, MS Word, Firefox, Halo, etc. An applet is a Java.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 - Introduction to Java Applets Outline 3.1 Introduction 3.2 Sample Applets from the Java 2.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Topics  Applets  Classes used for graphics Graphics Point Dimension.
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.
A Simple Applet --- Digital Clock import java.awt.*; import java.util.Calendar; public class DigitalColok extends java.applet.Applet implements Runnable.
Java Applets. Road Map Introduction to Java Applets Review applets that ship with JDK Make our own simple applets –Introduce inheritance –Introduce the.
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.
APPLETS CSC 171 FALL 2004 LECTURE 6. APPLETS Graphical Java programs Run inside web browser Platform-neutral Easy deployment--loads when needed Secure.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 5 Java Graphics Applets.
26-Jun-15 Applets. 2 An applet is a Panel that allows interaction with a Java program A applet is typically embedded in a Web page and can be run from.
A Simple Applet. Applets and applications An applet is a Java program that runs on a web page –Applets can be run from: Internet Explorer Netscape Navigator.
A Simple Applet.
Object Oriented Programming (OOP) LAB # 5 TA. Maram & TA. Mubaraka TA. Kholood & TA. Aamal.
Program Design With Methods And Graphics / Chapter 4 1 Abstract Window Toolkit.
1 Drawing Shapes and Text With Applets. 2 Drawing in the paint method import java.awt.*;// access the Graphics object import javax.swing.*;// access to.
Graphics. Graphics Features in Java Topics to be covered Topics to be covered Graphics Basics Graphics Basics Coordinate System Coordinate System Graphics,
Java Applets. Lecture Objectives  Learn about Java applets.  Know the differences between Java applets and applications.  Designing and using Java.
CSTP WS00CS423 (cotter)1 Java Applets Objective: Learn how to develop Java programs that interact with users through a Web browser.
Applets  The Applet Class  The HTML Tag F Passing Parameters to Applets.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Java Applets What is an Applet? How do you create.
Applets CS 3331 Sections 3.3 & 4.7 of [Jia03].
Internet Software Development Applets Paul J Krause.
Java On The Web Session 15. Memory Upload JAVA Applets Colors Fonts Drawing Methods Posting your Applet.
Applets.
JAPPLET.
// Java0601.java // This program demonstrates that the methods of a class are not always // accessible, like they were with the class. In this case an.
Graphics and Java 2D. 2 Introduction Java’s graphics capabilities –Drawing 2D shapes –Controlling colors –Controlling fonts Java 2D API –More sophisticated.
Graphics & Java 2D Drawing Two Dimensional Shapes Controlling Fonts Controlling Colors.
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 Applet is java program that can be embedded into HTML pages. Java applets runs on the java enabled web browsers such as mozilla and internet explorer.
Graphics Copyright © 2015 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved. Java Methods Object-Oriented Programming and Data.
1 A Simple Applet. 2 Applets and applications An application is an “ordinary” program Examples: Notepad, MS Word, Firefox, Halo, etc. An applet is a Java.
1 Applets and Course Evaluation Applet Example - Sailing Applet UML Diagrams Applet Web Page Encoding (HTML) Applet Java Coding – Hello World Course Evaluation.
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.
Pravin Yannawar, DOCS, NMU Jalgaon Basic Java : Applets 2 Objectives of This Session Identify the need for Applets Distinguish between Applets and Applications.
Lec 16 Adding Mouse and KeyEvent handlers to an Applet Class.
APPLET. 2 Introduction to Java Applet Programs Applications are stand alone programs ◦ executed with Java interpreter Applet is a small program ◦ can.
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
Painting (Chapter 12) Java Certification Study Group January 25, 1999 Mark Roth.
(c)2006 E.S.Boese All Rights Reserved.1 Drawing Shapes and Text Chapter 2 – Lecture Slides.
Chapter 2: Graphics In Java Basics of classes –instance variables –methods –overriding methods Graphics class (drawing routines) Other classes –Color –Font.
1 Contents Introduction Applet Vs Application Security Restrictions on Applet A simple example “Hello World!” applet Compiling & Running Applet HTML document.
1 A Simple Applet. 2 Applets and applications An applet is a Java program that runs on a web page Applets can be run within any modern browser To run.
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.
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Jaeki Song ISQS6337 JAVA Lecture 10 Applets. Jaeki Song ISQS6337 JAVA Applet Applets run within the Web browser environment –Applets bring dynamic interaction.
Java Applets. Introduction to Java and Java Applets Java applications Run in stand-alone mode No additional software required (such as a Web browser)
Graphics JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin, Gary Litvin, and Skylight.
Applet: An applet is a java program that is transmitted over the network from the server to client & executed within clients browser. Applets are used.
Java Applets.
Object Oriented Programming
Java Applets.
Graphics Applets By Mr. Dave Clausen
Distributed Computing, M. L. Liu
Distributed Computing, M. L. Liu
Java Applets.
Java Applets.
Java applets 1/3/2019.
G6DICP - Lecture 27 Java Applets.
APPLET PROGRAMMING.
Presentation transcript:

Applets & Graphics

Applets programs that run inside a browser Java platform-independence makes applets possible security restrictions: –cannot read or write to local disk –cannot print –can only access the server that delivered them –signed applets compatibility issues –JDK built-in to browser (still at JDK1.1) –Java plug-in may be installed into browser –Java must be enabled in browser download speed

HTML A page-definition language for browsers applets must be invoked via an HTML page My Applet Here is my first applet: <applet code=“MyApplet.class” width=200 height=200> MyApplet here

Creating an Applet An applet must extend the Applet class public class MyApplet extends Applet this allows it to inherit the hooks which enable it to run in a browser applets inherit a method: public void paint(Graphics g) from a superclass; a browser will call an applet’s paint() method in this case, the inherited method does nothing; but we may override it to draw a picture in our applet the browser creates and supplies a Graphics object the Graphics object has methods for drawing

Some Methods of the Graphics Class –void drawString (String s, int x, int y) –void drawRect (int x, int y, int width, int height) – void drawOval (int x, int y, int width, int height) –void drawLine (int x1, int y1, int x2, int y2) –void fillRect (int x, int y, int width, int height) – void fillOval (int x, int y, int width, int height) –void drawImage(Image img, int x, int y, ImageObserver observer) –void setColor (Color c) –void setFont (Font f)

Coordinate System Graphics uses an integer coordinate system with origin at top left corner of the applet 0,0 width, height x y

Color Class Constructor (values from ) public Color (int red, int green, int blue) Examples Color red = new Color (255, 0, 0); Color purple = new Color (255, 0, 255); Color whatever = new Color (25, 128, 200); Predefined colors Color.lightGray Color.magenta Color.white Color.blue, etc.

Font Class Constructor public Font (String name, int style, int size) Names –“TimesRoman” –“ Arial ” –“ Courier ” –“ Impact ” Logical names –“serif” // TimesRoman –“ sanserif ” // Helvetica –“ monospaced ” // Courier

Font Class (continued) Styles –Font.BOLD –Font.ITALIC –Font.PLAIN –Font.BOLD+Font.ITALIC Sizes (in points, 1/72 inch) –8 // pretty small –12 // readable –20 // large

Font Class (continued) Examples –Font normal = new Font (“serif”, Font.PLAIN, 12); –Font emphatic = new Font (“Helvetica”, Font.BOLD+ Font.ITALIC, 24); –Font program = new Font (“monospaced”, Font.PLAIN, 12);

import java.awt.*; import java.applet.*; public class SampleApplet extends Applet { public void paint(Graphics g) { Font f1 = new Font (“serif”, Font.PLAIN, 14); g.setFont (f1); g.drawString (“Let’s try some things”, 20, 20); g.setColor (new Color (100, 200, 100)); g.drawRect (5, 40, 50, 30); g.setColor (Color.green); g.fillRect (30, 60, 30, 50); } }

Other Methods of Applet paint(Graphics g) is called whenever the applet needs repainting the Applet class has other methods that may be overridden: –public void init() // called once,when the applet is loaded –public void start() // called whenever the applet’s page is viewed –public void stop() // called whenever the applet’s page is exited –public void destroy() // called when the browser exits

Applet Parameters You may wish to change the behavior of your applet without modifying and recompiling it parameters may be specified in the HTML applet start and end tags <applet code = “MyApplet.class” width = 200 height = 200> an applet can read these parameters String s = this.getParameter (“font”);

Sample Applet <applet code=SampleApplet.class width=350 height=150>

import java.awt.*; import java.applet.*; public class SampleApplet extends Applet { private String fontName; private int fontSize; public void init() { fontName = this.getParameter (“font”); String s = this.getParameter (“size”); fontSize = Integer.parseInt (s); } public void paint(Graphics g) { Font f1 = new Font (fontName, Font.PLAIN, fontSize); g.setFont (f1); g.drawString (“Let’s try some things”, 20, 20);... } }

Applet Size in JDK1.1 Dimension size = this.getSize(); int width = size.width; int height = size.height; in JDK1.2 int width = this.getWidth(); int height = this.getHeight(); these methods are inherited from the Component class