©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter 5 - 1 Java Applets What is an Applet? How do you create.

Slides:



Advertisements
Similar presentations
Laboratory Study II October, Java Programming Assignment  Write a program to calculate and output the distance traveled by a car on a tank of.
Advertisements

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.
Java Graphics Section 1 - Multi-File Graphics Programs Section 2 - The Coordinate System and Graphics Context g Section 3 - The Java Drawing and Painting.
© 2004 Pearson Addison-Wesley. All rights reserved2-1 Introduction to Graphics The last few sections of each chapter of the textbook focus on graphics.
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.
Chapter Day 5. © 2007 Pearson Addison-Wesley. All rights reserved2-2 Agenda Day 5 Questions from last Class?? Problem set 1 Posted  Introduction on developing.
 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.
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.
Java Applets. Road Map Introduction to Java Applets Review applets that ship with JDK Make our own simple applets –Introduce inheritance –Introduce the.
©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.
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.
Chapter 3 - Introduction to Java Applets Outline 3.1Introduction 3.2Thinking About Objects 3.4A Simple Java Applet: Drawing a String 3.5Two More Simple.
A Simple Applet.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 4 Image Slides.
Object Oriented Programming (OOP) LAB # 5 TA. Maram & TA. Mubaraka TA. Kholood & TA. Aamal.
Chapter 5 Graphics. Topics Applets Classes used for graphics –Graphics –Point –Dimension –Color.
Program Design With Methods And Graphics / Chapter 4 1 Abstract Window Toolkit.
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.
Java Applets. Lecture Objectives  Learn about Java applets.  Know the differences between Java applets and applications.  Designing and using 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.
Computer Science [3] Java Programming II - Laboratory Course Lab 6: Introduction to Java Applets Sample Applets from the Java Simple Java Applet: Drawing.
 2002 Prentice Hall. All rights reserved. 1 Chapter 3 - Introduction to Java Applets Outline 3.1 Introduction 3.2 Sample Applets from the Java 2 Software.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Standard Graphics in Java,
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
Java On The Web Session 15. Memory Upload JAVA Applets Colors Fonts Drawing Methods Posting your Applet.
JAPPLET.
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.
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.
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.
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.
Chapter 7 © 2005 by Addison Wesley Longman, Inc Introduction - Applets are relatively small Java programs whose execution is triggered by a browser.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved COS240 O-O Languages AUBG,
Chapter 2: Color and Applets Coming up: Introduction to Graphics.
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 - Introduction to Java Applets Outline 3.1Introduction 3.2Thinking About Objects 3.3Sample.
Graphics & Applets CSC 1051 – Data Structures and Algorithms I
(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.
Classes Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
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 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.
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.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Please open JCreator and follow these steps: 1)Configure  Options 2)JDK Tools 3)Choose Run Applet from drop-down 4)Click Default, then Edit 5)Click the.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 - Introduction to Java Applets Will not cover Section 3.7 Thinking About Objects: Identifying.
Basic Graphics 03/03/16 & 03/07/16 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
CPCS 391 Computer Graphics Lab One. Computer Graphics Using Java What is Computer Graphics: Computer graphics are graphics created using computers and,
Intro to Graphics from Chapter 2 of Java Software Solutions
Graphics Applets By Mr. Dave Clausen
Chapter 02 Data and Expressions.
Object Oriented Programming
CSC 1051 – Data Structures and Algorithms I
Java Applets.
Graphics Applets By Mr. Dave Clausen
Java Applets.
Java Applets.
Java Applets.
Outline Character Strings Variables and Assignment
Presentation transcript:

©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 an Applet?

©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter What is an Applet A Java applet is a program that is intended to transported over the Web and executed using a web browser –An applet is embedded into an HTML file using a tag that references the bytecode file of the applet class The bytecode version of the program is transported across the web and executed by a Java interpreter that is part of the browser –An applet also can be executed using the appletviewer tool of the Java Software Development Kit

©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Applet Classes For applets, there are two classes that can be used for creating applets. –Applet - draw directly on the applet –JApplet - create an object (derived from JPanel) to draw on Your third programming assignment will be an Applet

©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Applets The class that defines an applet extends the Applet class Applets have several methods that the browser calls –The init method is called once when the applet starts up –The paint method is used to draw the applet’s contents accepts a parameter that is an object of the Graphics class You need to write the body of these methods to make the applet look the way you want it to

©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Viewing Applets In order to view an applet, you need an html file which references the class file In a browser, put in the URL of the html page Use the appletviewer tool to look at the applet appletviewer myApplet.html –appletviewer shows only the applet and ignores any other content

©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter The HTML applet Tag My Applet <applet code="MyApplet.class" width=350 height=175>

©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Graphics Class Frames and Applets have a graphics context associated with them. A Graphics object defines a graphics context on which we can draw shapes and text. The Graphics class is in the java.awt package. The state of a Graphics object includes such properties as height, width, foreground color and font. Positions within the Graphics context are measured from the upper left corner and they have units of pixels.

©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Graphics Class Accessor methods are provided for getting height, width, color, font, … Mutator methods are also provided for these properties. The Graphics class has several methods for drawing shapes There is a method for displaying text. You can also display images.

©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Drawing a Line X Y g.drawLine (10, 20, 150, 45); g.drawLine (150, 45, 10, 20); or

©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter The Effect of drawRect

©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Drawing an Oval X Y g.drawOval (175, 20, 50, 80); bounding rectangle

©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Displaying a String The drawString method can be used to display text in a Graphics context. void drawString( String text, int x, int y; *The position of the text relative to x and y is shown in the figure

©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Color Class The java.awt.Color class allows us to create a color object. Color class has public constants for common colors: –Gray scale: Color.black –Primary colors: Color.red Color.green Color.blue –Secondary colors: Color.yellow Color.cyan Color.magenta –Others: Color.orange Create custom colors by specifying three values ranging from 0 to 255 for red, green, and blue. Color pinkColor; pinkColor = new Color(255,175,175)‏