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.

Slides:



Advertisements
Similar presentations
Applets and Graphics.
Advertisements

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.
Graphics You draw on a Graphics object The Graphics object cannot directly be created by your code, instead one is generated when the method paintComponent.
Graphics Chapter 16.  If you want to draw shapes such as a bar chart, a clock, or a stop sign, how do you do it?
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.
Java Graphics Section 1 - Multi-File Graphics Programs Section 2 - The Coordinate System and Graphics Context g Section 3 - The Java Drawing and Painting.
Java Applets. 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 browser.
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.
©2004 Brooks/Cole Applets Graphics & GUIs. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Graphical Programs Most applications these days are.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Topics  Applets  Classes used for graphics Graphics Point Dimension.
May 11, 1998CS102-02Lecture 7-1 More Graphics in Java CS Lecture 7-1 A picture's worth a thousand words.
2D Graphics in Java COMP53 Nov 14, Applets and Applications Java applications are stand-alone programs – start execution with main() – runs in JVM.
©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. 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 browser You.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 5 Java Graphics Applets.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 5 Applets and Graphics.
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.
Chapter 5 Graphics. Topics Applets Classes used for graphics –Graphics –Point –Dimension –Color.
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
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 Applets By Mr. Dave Clausen. 2 Applets  A Java application is a stand-alone program with a main method (like the ones we've seen so far)  A.
Java Applets. Lecture Objectives  Learn about Java applets.  Know the differences between Java applets and applications.  Designing and using Java.
©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.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Standard Graphics in Java,
Applets CS 3331 Sections 3.3 & 4.7 of [Jia03].
Java On The Web Session 15. Memory Upload JAVA Applets Colors Fonts Drawing Methods Posting your Applet.
COP 4331 – OOD&P Lecture 6. Review Midterm Review Complete sample application –See SwingColorTest.java.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 2 Elementary Programming.
Abstract Window Toolkit (AWT) The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include:  A rich set.
Lecture 15: Intro to Graphics Yoni Fridman 7/25/01 7/25/01.
Applets & Graphics. Applets programs that run inside a browser Java platform-independence makes applets possible security restrictions: –cannot read or.
Chapter 7 Graphics. © Daly and Wrigley Objectives Use Graphic Components: ▫ Strings ▫ Lines ▫ Rectangles ▫ Ovals ▫ Arcs Change the color and font of elements.
Java Applets. 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 browser.
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.
Chapter 2: Color and Applets Coming up: Introduction to Graphics.
1 Windows program example import java.awt.*; import java.awt.event.*; public class wpexample extends Frame { public wpexample(String title) { super(title);
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.
(c)2006 E.S.Boese All Rights Reserved.1 Drawing Shapes and Text Chapter 2 – Lecture Slides.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
1 Contents Introduction Applet Vs Application Security Restrictions on Applet A simple example “Hello World!” applet Compiling & Running Applet HTML document.
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 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 Graphics Methods public abstract void drawString(String str, int x, int y): is.
1 Graphics, Fonts and Color Chapter 9. 2 What is in this chapter: l Graphics class and coordinates l graphics primitives (lines,rectangles,ovals and arcs)
CSI 3125, Preliminaries, page 1 AWT. CSI 3125, Preliminaries, page 2 AWT Java AWT (Abstract Windowing Toolkit) is an API to develop GUI or window-based.
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.
1 Introduction to Graphics b The last one or two sections of each chapter of the textbook focus on graphical issues b Most computer programs have graphical.
CHAPTER Agenda Applets Servelets Browsers HelloWorld.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Break Time! Graphical User Interface (GUI) NO EXAM….ONLY PROJECT!
Intro to Graphics from Chapter 2 of Java Software Solutions
Sachin Malhotra Saurabh Choudhary
Graphics Applets By Mr. Dave Clausen
Chapter 8 Graphics.
Object Oriented Programming
CSC 1051 – Data Structures and Algorithms I
Applets In Java Visit for more Learning Resources 1.
Building Java Programs
Graphics Applets By Mr. Dave Clausen
Chapter 10 Graphics.
Java Applets.
4.14 GUI and Graphics Case Study: Creating Simple Drawings (Cont.)
APPLETS.
Chapter 8 Graphics.
Presentation transcript:

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. Applet can't access system resources on the local computer. Applets are used to make the web site more dynamic and entertaining.

Jdk provides us with a special tool called AppletViewer. Applet class is defined in java.applet package. Applet execution doesnot begin at main. Applet appear within a Html page & contain GUI controls like buttons,list,boxes etc. When user interacts with these controls an event is genetated.

init(): This method is called to initialized an applet. start() : This method is called after the initialization of the applet.It is called when user returns to the HTMl page. stop(): This method can be called multiple times in the life cycle of an Applet moves out of the HTMl page. destroy(): This method is called only once in the life cycle of the applet when applet is unloaded from the memory. paint():it is called each time applets o/p is drawn

public void paint(Graphics g){ This method is drawing method. This method draws anything that is in the applet,to the screen. An instance(g) of the Class Graphics is passed to it. It takes a String and an x and a y coordinate as it’s argument.

The repaint() Method The repaint() method is the one invoked by a program to do drawing. repaint() ==> update() ==> paint() repaint() does not invoke paint() directly. It schedules a call to an intermediate method, update(). Finally, update() calls paint(). update() Clears screen Sets back & foreground colors Invokes paint() method

public void showStatus(String msg) Outputs a message string in the "status window". URL getDocumentBase() Returns the URL of the HTML file in which the applet is embedded. URL getCodeBase() Returns the URL of the class file that contains applet.

The java.awt package “awt” stands for “Abstract Window Toolkit” The java.awt package includes classes for: Drawing lines and shapes Drawing letters Setting colors Choosing fonts If it’s drawn on the screen, then java.awt is probably involved.

Java’s coordinate system Java uses an (x, y) coordinate system (0, 0) is the top left corner (50, 0) is 50 pixels to the right of (0, 0) (0, 20) is 20 pixels down from (0, 0) (w - 1, h - 1) is just inside the bottom right corner, where w is the width of the window and h is its height (0, 0) (0, 20) (50, 0) (50, 20) (w-1, h-1)

The Graphics class contains drawing methods drawLine(x1,y1,x2,y2) g.drawLine(100,100,420,312); drawRect(x,y,width,height); g.drawRect(72,160,200,35); drawOval (x, y, width, height) g.drawOval(300,120,100,75);

drawArc (int x, int y, int width, int height, int startAngle, int arcAngle) drawArc(100,100,80,60,45,120); Draws the outline of a circular or elliptical arc covering the specified rectangle. fillArc() Fills a circular or elliptical arc covering the specified rectangle drawPolyline (int[] xPoints, int[] yPoints, int nPoints)

fillPolygon(int[], int[], int points), drawPolyline(int[], int[], int points): Draws a closed polygon defined by arrays of x and y coordinates draw3DRect(x,y,width,height,boolean raised): Draws a 3-D highlighted outline of the specified rectangle. The edges of the rectangle are highlighted so that they appear to be beveled and lit from the upper left corner.

g.drawLine( x1, y1, x2, y2 ); g.drawOval( left, top, width, height ); g.fillOval( left, top, width, height ); g.drawRoundRect( left, top, width, height ); g.fillRoundRect( left, top, width, height ); g.drawArc( left, top, width, height, startAngle, arcAngle ); g.drawString( string, x, y );

Colors: To use a color, g.setColor(Color.RED); The java.awt package defines a class named Color There are 13 predefined Color.BLACK Color.PINK Color.GREEN Color.RED Color.DARK_GRAY Color.CYAN Color.GRAYColor.ORANGE Color.BLUE Color.LIGHT_GRAY Color.YELLOW Color.WHITE Color.MAGENTA Every color is a mix of red, green, and blue To make your own colors: Amounts range from 0 to 255 new Color( red, green, blue ) Black is (0, 0, 0), white is (255, 255, 255)

setBackground (Color c)-sets background color; setForeground (Color c)-sets foreground color; Color getBackground();gets Background color; Color getForeground(); gets Foreground color;

Font (String name, int style, int size) Creates a new Font from the specified name, style and point size. PLAIN:0 BOLD:1 ITALIC:2 To create a FontMetrics object, where g is a Graphics object and f is a Font object: FontMetrics fm = g.getFontMetrics(f);

int getAscent() Determines the font ascent of the Font described by this FontMetrics object. Int getDescent() Determines the font descent of the Font described by this FontMetrics object. Font getFont() Gets the Font described by this FontMetrics object. intgetHeight() Gets the standard height of a line of text in this font. int getLeading() Determines the standard leading of the Font described by this FontMetrics object