Project 2: Thoughts Problems/Solutions Multiple Vectors vs. One Vector + easy to draw, - z order Shape can draw itself +separation.

Slides:



Advertisements
Similar presentations
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
Advertisements

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.
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.
 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.
Graphics Programming. In this class, we will cover: The difference between AWT and Swing Creating a frame Frame positioning Displaying information in.
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.
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.
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.
1 L44 Introduction to Java Applets. 2 OBJECTIVES  To differentiate between applets and applications.  To observe some of Java's exciting capabilities.
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.
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.
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 3 - Introduction to Java Applets Outline 3.1Introduction 3.2Thinking About Objects 3.4A Simple Java Applet: Drawing a String 3.5Two More Simple.
28-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.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
Swing Graphics ● Empty Swing containers have no visual appearance except for a background color ● Every JComponent must have a paintComponent method that.
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.
Applets  The Applet Class  The HTML Tag F Passing Parameters to Applets.
Applets Java API.
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.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
Applets Chapter 17.  Java’s big splash onto the scene came in the mid 90’s. The people at Sun Microsystems had managed to work java programs into Web.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
JAPPLET.
Learn about the types of Graphics that are available Develop a basic Graphics applet Develop a basic Graphics application Review the Java API and use.
COP 4331 – OOD&P Lecture 6. Review Midterm Review Complete sample application –See SwingColorTest.java.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 28 - Java Graphics and Java2D Outline 28.1Introduction.
Chapter 28 - Java Graphics and Java2D Outline 28.1Introduction 28.2Graphics Contexts and Graphics Objects 28.3Color Control 28.4Font Control 28.5Drawing.
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 10: Applets and Advanced Graphics The Applet Class The Applet Class The HTML Tag The HTML Tag Passing Parameters to Applets Passing Parameters.
Graphics and Java 2D. 2 Introduction Java’s graphics capabilities –Drawing 2D shapes –Controlling colors –Controlling fonts Java 2D API –More sophisticated.
Applets & Graphics. Applets programs that run inside a browser Java platform-independence makes applets possible security restrictions: –cannot read or.
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.
Introduction to Java Applets Sangeetha Parthasarathy 05/21/2001.
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,
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved COS240 O-O Languages AUBG,
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.
CSC 205 – Java Programming II Applet. Types of Java Programs Applets Applications Console applications Graphics applications Applications are stand-alone.
Pravin Yannawar, DOCS, NMU Jalgaon Basic Java : Applets 2 Objectives of This Session Identify the need for Applets Distinguish between Applets and Applications.
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.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
Introduction to Java Chapter 8 - Introduction to Java Graphics1 Chapter 8 Introduction to Java Graphics.
Applets, Images, and Audio Chapter 14 CSCI CSCI 1302 – Applets, Images, and Audio2 Outline Introduction The Applet Class –The init Method –The start.
Creating a Java Application and Applet
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.
CHAPTER Agenda Applets Servelets Browsers HelloWorld.
1 Java Applet Basics Chapter Eight. 2 Applets vs. Applications l Applications: Stand alone Java programs run by interpreter l Applets WWW browser embedded.
1 Applets Programming. Introduction Java programs are divided into two main categories, applets and applications. An application is an ordinary Java program.
Projects: not limited to spec Error checking File filters Create multiple file formats Polygons Filled shapes Etc.
Lecture 09 Applets.
Java Graphics CS 2511.
Java Applets.
Distributed Computing, M. L. Liu
Distributed Computing, M. L. Liu
UNIT-5.
Java Applets.
Java applets 1/3/2019.
Applet in Java.
11.1 Applets & graphics.
Handout-14 Applets and Graphics
JAVA APPLET PREPARED BY Mr. Jahanzaib Ahmed
Advanced GUIs and Graphics
Presentation transcript:

Project 2: Thoughts Problems/Solutions Multiple Vectors vs. One Vector + easy to draw, - z order Shape can draw itself +separation

Graphics & Applets Applet Material was modified from:

Graphics Abstract class No instantiation Graphics g = someComponent.getGraphics()

Graphics API Graphics (1.1) Available fonts Lines drawn with a single-pixel width Shapes painted solid colors only

Java 1.1 Graphics public void paint(Graphics g) { // Set pen parameters g.setColor(someColor); g.setFont(someLimitedFont); // Draw a shape g.drawRect(...); // outline g.drawPolygon(...); // outline g.drawOval(...); // outline... } Example: Graphics 1.1

Graphics extended (1.2) Graphics2D Colors and patterns: gradient fills, fill patterns tiled images transparency Local fonts Pen thicknesses, dashing patterns, & segment connection styles Coordinate transformations Rotations & shearing

Java 2D: Common Methods public void drawString(String s, flt x, flt y) drawString(s, 2.0f, 3.0f) public void rotate(double theta) rotation of theta radians public void rotate(dbl theta, dbl x, dbl y) theta radians, point of rotation (x, y).

Continued public void scale(double xscale, yscale) Values greater than 1.0 expand the axis Values less than 1.0 shrink the axis public void setPaint(Paint paint) Solid Color, a GradientPaint, & TexturePaint public void setStroke(Stroke pen) Line thickness around object

Optional: modify drawing parameters g2d.setPaint(fillColorOrPattern); g2d.setStroke(penThicknessOrPattern); g2d.setComposite(someAlphaComposite); g2d.setFont(someFont); g2d.rotate(...); g2d.scale(...); g2d.setTransform(someAffineTransform);

Drawing a shape Call paintComponent method of superclass maintains the component look and feel clears off-screen pixmap (Swing implements double buffering) public void paint(Graphics){ super.paint(g); ….

Graphics 2D: Cast public void paint(Graphics g) { super.paint(g); Graphics2D g2d = (Graphics2D)g; …stuff here… }

Drawing Shape Objects public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D)g; // Assume x, y, and diameter are instance variables. Ellipse2D.Double circle = new Ellipse2D.double(x, y, diameter, diameter); g2d.fill(circle);... } There is double and float…idea being performance

Other shapes… Arc2D Ellipse2D GeneralPath, Line2D Rectangle2D, & RoundRectangle2D

Complex Constructors public Arc2D.Double( x, y, width, height, startAngle, deltaAngle, closure) A lot of built in functionality and methods ARC2D.OPEN ARC2D.PIE ARC2D.CHORD

General paths: Custom Shapes GeneralPath path = new GeneralPath(); path.moveTo(50, 50); path.lineTo(150, 150); path.quadTo(200, 200, 250, 150); path.curveTo(250, 250, 150, 250, 150, 200); path.closePath(); g.draw(path);

Creating…

Some Examples… Graphics Assortment of shapes Graphics 2D Added functionality Fonts Using fonts

APPLETS Compare/contrast applets and applications Explain applet basics Create simple applets Embed applets in web pages

APPLETS VS. APPLICATIONS APPLICATION: Free-standing programs Can be run from command line APPLET: Must be run from a Web browser Reference to applet is placed on Web page via special HTML tags Allows applet to be downloaded and executed on system with browser (“local system”). What are the issues running it locally?

SUPPORT FEATURES Applets have use of browser-provided features: an existing window, event-handling, graphics context, and a user interface Applications can also create these features, but they are NOT necessary The components and containers available in an applet can be placed in an application, but graphical context is not inherited as it is in an applet.

RESTRICTIONS ON APPLETS Reason for restrictions: necessary to protect integrity and security of client system downloading applet Some restrictions : Can’t read/write with client’s file system except for specific folders specified by client. Can’t run any programs on client Can’t run programs native to the local platform (e.g., shared libraries and DLLs).

ADDITIONAL PRECAUTIONS The compiler and interpreter have additional security and consistency checks built-in Check to ensure the.class file is a.class file Parity checks, cyclic redundancy checks (CRC) All of the foregoing minimizes accidents and hacking, but is no guarantee.

APPLET BASICS Basic features and behaviors of an applet? From the Applet class: any applet is a subclass of this class public class myAppClass extends JApplet {…} NOTE: Java requires the keyword “public” Allows the applet to be used by any agency outside the class, such as the users on the internet.

APPLETS VS. APPLICATIONS: EXECUTION APPLICATION: main() APPLET: Upon starting an instance of the applet class is created. It calls a series of methods that have been inherited from java.applet.Applet. Note: 2 versions of the same applet use different instances of the applet’s class so that there is no conflict.

THE MAJOR BEHAVIORS/METHODS OF AN APPLET The behavior of Applets is more complex than that of application. An application’s behavior depends just on main(). An applet starts, there is a series of methods that are executed corresponding to the applet’s major behaviors: initialization, starting, stopping, destroying, and painting

APPLET INITIALIZATION Occurs just once when applet is loaded Can include creation of objects needed by applet, setting initial state, loading images/fonts To specify initialization behavior, just overload default init() method: public void init(){…} a constructor

APPLET STARTING Applet is started after it’s initialized. Starting can occur if applet was previously stopped Example: Reader follows a link off the page and then returns. To define startup behavior, overload the start method: public void start(){…} Useful start actions: start a thread, send a message to a helper object, tell the applet to begin running Note: can start an applet many times, although it’s initialized only once.

STOPPING Occurs when reader leaves a page holding a running applet. Can also stop an applet via call, stop() DEFAULT: When reader leaves a page, any running threads continue to run. To specify stop actions overload the following: public void stop(){…} Note: We could override stop and stop these thread when page is left, then restart them when we return to page.

DESTROYING Purpose: to free resource just before browser exits or applet finishes Normally, destroy() is not used unless there are resources to free explicitly To control cleanup after an applet override the destroy() method: public void destroy() {…} Similar to automatic garbage Collection

PAINTING This method controls the drawing of anything to the screen The paint() method is invoked often: if applet is started; if applet is moved or moved on top of another page item; if one is doing animation. Graphics parm is created and passed to paint() by the browser It is almost guaranteed that you will need to override the paint() method in an applet.

A SIMPLE APPLET import javax.swing.JApplet; import java.awt.*; public class ASimpleApplet extends Applet { Font f = new Font("TimesRoman", Font.BOLD, 36); public void paint(Graphics g) { g.setFont(f); g.setColor(Color.red); g.drawString(“A simple applet example!", 5, 50); }//end paint method }//end class

COMMENTS ON A SIMPLE APPLET Only one method is overridden: paint() The applet is too simple to need any other method. f is an instance variable for the font to be used inside the graphics context, g. Action of paint(): Font f is added to the graphics context Next, color of the text is set to Color.red--a final class variable for red(i.e., a constant). Finally, the string, “A simple applet example!” is drawn 5 and 50 are the x,y coordinates of the bounding box’s lower left hand corner.

EMBEDDING AN APPLET ON A WEB PAGE IDEA: Browser is made to execute an applet via info within special HTML tags on the Web page. EXAMPLE: Can you have images in your applet?

COMMENTS ON SIMPLE APPLET’S HTML All info regarding applet is embedded in the and pair Features of the applet tags: CODE: name and extension of class file of applet to be run Note: It’s assumed that class file is in same folder as HTML file CODEBASE: file is in a different folder; it gives the name of the folder. WIDTH and HEIGHT: too small and parts of applet may be lost. Text between APPLET tags: displayed by browsers that cannot work with Java. (HTMLConverter)

Demo grade applet What is meant by Signing an applet? How to sign an applet What are the advantages/disadvantages?

1.Generate the key to sign the applet keytool -genkey -alias prompt for cert info and keystore,cert password 2.Siginig the jar file jarsigner -signedjar (target) (source) (cert name) Finally, make sure you include archive = "signedjar.jar" in the html file 3.Convert HTML for plugin HtmlConverter

Project 3 What is project 2 missing?

Next Week… Project 3 in more detail The logic of the mouse listeners Drawing Selection SplitPanes, Tabbed Panes