COMP 14: Applets June 21, 2000 Nick Vallidis. Announcements zP6 is due Friday.

Slides:



Advertisements
Similar presentations
LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class.
Advertisements

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Outline Graphics Applets Drawing Shapes Components and Containers Images.
ITEC220 GUI Lecture – Part 2 References  Java Software Solutions,” by Lewis & Loftus  Chapter 7  Chapter 8  Chapter 9  Java Foundations-Introduction.
© 2004 Pearson Addison-Wesley. All rights reserved2-1 Introduction to Graphics The last few sections of each chapter of the textbook focus on graphics.
©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.
Event Handling Events and Listeners Timers and Animation.
Lecture 24 Applets. Introduction to Applets Applets should NOT have main method but rather init, stop, paint etc They should be run through javac compiler.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Topics  Applets  Classes used for graphics Graphics Point Dimension.
Primitive Types vs. Reference Types Variables of primitive types hold the values of the primitive types directly. Variables of reference types hold references.
©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.
1 Applets Chapter 1 To understand:  why applets are used to extend the capabilities of Web pages  how an applet is executed and know about the restrictions.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 2 “ Data and Expressions”
Chapter Day 10. © 2007 Pearson Addison-Wesley. All rights reserved4-2 Agenda Day 10 Questions from last Class?? Problem set 2 posted  10 programs from.
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.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Chapter 5 Graphics. Topics Applets Classes used for graphics –Graphics –Point –Dimension –Color.
Chapter Day 9. © 2007 Pearson Addison-Wesley. All rights reserved4-2 Agenda Day 8 Questions from last Class?? Problem set 2 posted  10 programs from.
ELC 312 Day 16. © 2004 Pearson Addison-Wesley. All rights reserved Agenda Questions? Capstone Proposals Due Problem set 3 Corrected  Poor performance.
INTRODUCTION TO HTML5 Drag and Drop in HTML5. Browsers Support  Currently, most of the major HTML5 desktop web browsers support the new HTML5 drag-and-drop.
©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.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 16: Java Applets & AWT Fundamentals of Web Programming.
Chapter 12 Applets and Advanced Graphics  The Applet Class  The HTML Tag F Passing Parameters to Applets F Conversions Between Applications and Applets.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
Chapter 5: Enhancing Classes
Chapter 12 Applets and Advanced GUI  The Applet Class  The HTML Tag F Passing Parameters to Applets F Conversions Between Applications and Applets F.
Chapter 5: Enhancing Classes Presentation slides for Java Software Solutions Foundations of Program Design Second Edition by John Lewis and William Loftus.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Event Driven Programming, The.
C H A P T E R T E N Event-Driven Programming Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
Java GUI’s are event driven, meaning they generate events when the user interacts with the program. Typical events are moving the mouse, clicking a mouse.
Chapter 10: Applets and Advanced Graphics The Applet Class The Applet Class The HTML Tag The HTML Tag Passing Parameters to Applets Passing Parameters.
Ch 3-4: GUI Basics Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Coming up: GUI Components.
Intro to Applets August 19, 2008 Mrs. C. Furman. Java Applets vs. Java Applications Java Applet: a program that is intended for use on the web. Java Applet:
Chapter 2: Color and Applets Coming up: Introduction to Graphics.
Graphics & Applets CSC 1051 – Data Structures and Algorithms I
Chapter 10: Applets and Advanced Graphics The Applet Class The Applet Class The HTML Tag The HTML Tag Passing Parameters to Applets Passing Parameters.
Chapter 14 Applets and Advanced GUI  The Applet Class  The HTML Tag F Passing Parameters to Applets F Conversions Between Applications and Applets F.
Object Oriented Programming.  Interface  Event Handling.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
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.
Lecture 18: Events; Cool Applets Yoni Fridman 7/30/01 7/30/01.
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.
CSI 3125, Preliminaries, page 1 Event Handling. CSI 3125, Preliminaries, page 2 Event Handling An Event Change in the state of an object is known as event.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Jaeki Song ISQS6337 JAVA Lecture 10 Applets. Jaeki Song ISQS6337 JAVA Applet Applets run within the Web browser environment –Applets bring dynamic interaction.
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.
12-Jun-16 Event loops. 2 Programming in prehistoric times Earliest programs were all “batch” processing There was no interaction with the user Input Output.
10/20/2005week71 Graphics, mouse and mouse motion events, KeyEvent Agenda Classes in AWT for graphics Example java programs –Graphics –Mouse events –Mouse.
Chapter 5: Enhancing Classes Presentation slides for Java Software Solutions Foundations of Program Design Second Edition by John Lewis and William Loftus.
Intro to Graphics from Chapter 2 of Java Software Solutions
Chapter 02 Data and Expressions.
Lecture 09 Applets.
CSC 1051 – Data Structures and Algorithms I
Miscellaneous Topics #6: Polygons GUI Components and Event Handlers
Chap 7. Building Java Graphical User Interfaces
Graphical User Interfaces -- Introduction
Event loops 17-Jan-19.
Outline Character Strings Variables and Assignment
JAVA APPLET PREPARED BY Mr. Jahanzaib Ahmed
ITEC220 GUI Lecture – Part 2 References
APPLET PROGRAMMING.
Presentation transcript:

COMP 14: Applets June 21, 2000 Nick Vallidis

Announcements zP6 is due Friday

Applets  A Java application is a stand-alone program with a main method zAn applet is a Java program that is intended to be transported over the web and executed using a web browser  An applet can also be executed using jview /a on the command line

Applets  An applet doesn't have a main method zInstead, there are several special methods that serve specific purposes  paint method -- automatically executed and is used to draw the applets contents

Applets  The paint method accepts a parameter that is an object of the Graphics class  A Graphics object defines a graphics context on which we can draw shapes and text  The Graphics class has several methods for drawing shapes zThe class that defines the applet extends the Applet class zSee Einstein.java (page 93)

Applets zAn applet is embedded into an HTML file using the tag that references the bytecode file (nameOfClass.class) of your applet yEinstein.html zIt is actually the bytecode version of the program that is transported across the web zThe applet is executed by a Java interpreter that is part of the browser

Drawing Shapes  Graphics class is defined in the java.awt package ydrawArc ydrawLine ydrawOval ydrawRect ydrawString yfillArc yfillOval yfillRect ygetColor ysetColor

Drawing Shapes zA shape can be filled or unfilled, depending on which method is invoked zThe method parameters specify coordinates and sizes zMany shapes with curves, like an oval, are drawn by specifying its bounding rectangle zAn arc can be thought of as a section of an oval

Drawing a Line X Y page.drawLine (10, 20, 150, 45); page.drawLine (150, 45, 10, 20); or

Drawing a Rectangle X Y page.drawRect (50, 20, 100, 40);

Drawing an Oval X Y page.drawOval (175, 20, 50, 80); boundingrectangle

The Color Class  A color is defined in a Java program using an object created from the Color class (defined in the java.awt package) ycontains several static predefined colors yFigure 2.19 page 99 zEvery graphics context has a current foreground color zEvery drawing surface has a background color zSee Snowman.java (page )

More Drawing Techniques zConditionals and loops can greatly enhance our ability to control graphics zSee Bullseye.java (page 157) zSee Boxes.java (page 159) zSee BarHeights.java (page 162)

Applet Methods  In previous examples we've used the paint method of the Applet class to draw on an applet  The Applet class has several methods that are invoked automatically at certain points in an applet's life  init - executed only once when the applet is initially loaded  start - called when applet becomes active (when browser loads / returns to the page)  stop - called when applet becomes inactive (when browser leaves the page)

Applet Methods  The Applet class also contains other methods that generally assist in applet processing (Figure 4.6, page 211) ygetCodeBase ygetDocumentBase ygetAudioClip ygetImage

Graphical Objects zAny object we define by writing a class can have graphical elements  The object must simply obtain a graphics context (a Graphics object) in which to draw zAn applet can pass its graphics context to another object just as it can any other parameter zSee LineUp.java (page 212) zSee StickFigure.java (page 215)

Events zAn event is an object that represents some activity to which we may want to respond zWe may want our program to perform some action when the following occurs: ythe mouse is moved ya mouse button is clicked ythe mouse is dragged ya graphical button is clicked ya keyboard key is pressed ya timer expires

Events zThe Java standard class library contains several classes that represent typical events zCertain objects, such as an applet or a graphical button, generate (fire) an event when it occurs zOther objects, called a listeners, respond to events zWe can write listener objects to do whatever we want when an event occurs

Events and Listeners Generator This object may generate an event Listener This object waits for and responds to an event Event When an event occurs, the generator calls the appropriate method of the listener, passing an object that describes the event

Listener Interfaces zWe can create a listener object by writing a class that implements a particular listener interface zThe Java standard class library contains several interfaces that correspond to particular event categories  For example, the MouseListener interface contains methods that correspond to mouse events zAfter creating the listener, we add the listener to the component that might generate the event to set up a formal relationship between the generator and listener

Mouse Events zThe following are mouse events: ymouse pressed - button is pressed down ymouse released - button is released ymouse clicked - button is pressed and released ymouse entered - pointer is moved over a particular component ymouse exited - pointer is moved off of a particular component zAny given program can listen for some, none, or all of these zSee Dots.java (page 246) zSee DotsMouseListener.java (page 248)

Mouse Motion Events zThe following are called mouse motion events: ymouse moved - the mouse is moved ymouse dragged - the mouse is moved while the mouse button is held down  There is a corresponding MouseMotionListener interface zOne class can serve as both a generator and a listener zOne class can serve as a listener for multiple event types zSee RubberLines.java (page 249)

More Applet Examples zScribble.java zAnimatedMsg.java