Chapter 5 Graphics. Topics Applets Classes used for graphics –Graphics –Point –Dimension –Color.

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.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 5 Selection Statements.
© 2004 Pearson Addison-Wesley. All rights reserved2-1 Introduction to Graphics The last few sections of each chapter of the textbook focus on graphics.
GUI and Swing, part 2 The illustrated edition. Scroll bars As we have previously seen, a JTextArea has a fixed size, but the amount of text that can be.
2 Data and Expressions Software Solutions Lewis & Loftus java
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.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
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.
©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”
COMP 14: Applets June 21, 2000 Nick Vallidis. Announcements zP6 is due Friday.
Chapter Day 4. © 2007 Pearson Addison-Wesley. All rights reserved2-2 Agenda Day 4 Return Signed Contracts Questions from last Class?? Problem set 1 Posted.
©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.
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
Drawing pictures with Java. JFrame: the basic Java window The swing package contains classes, objects and methods that can be used to create a consistent.
Java Programs u 1 project file –with an extension of.mcp –contains information that CodeWarrior needs to run the program u >= 1 source files –have an extension.
Applets Java API.
©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.
Agenda For Feb Finish up Unit 3 Exercises on page Unit 4 Exercises on page 33. Question #2 3. Create a Happy Face Java Applet (due next class).
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Standard Graphics in Java,
Java Software Solutions Lewis and Loftus Chapter 7 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphics -- Introduction The.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 2 Elementary Programming.
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.
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:
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,
1 Objects and Primitive Data  Now we can explore some more fundamental programming concepts  Chapter 2 focuses on: predefined objects primitive data.
Chapter 2: Color and Applets Coming up: Introduction to Graphics.
Chapter 2 Data and Expressions Part Two. 2-2/30 Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive.
Chapter 2 Data and Expressions. © 2004 Pearson Addison-Wesley. All rights reserved2-2 Data and Expressions Let's explore some other fundamental programming.
Graphics & Applets CSC 1051 – Data Structures and Algorithms I
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
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.
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 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 2 Data and Expressions. © 2004 Pearson Addison-Wesley. All rights reserved2-2 Data and Expressions Let's explore some other fundamental programming.
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.
Chapter 2 Data and Expressions 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design © 2007 Pearson Addison-Wesley. All rights.
Basic Graphics 03/03/16 & 03/07/16 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
6.1 Coordinates The screen of a computer is a grid of little squares called pixels. The color of each pixel can be set individually, and drawing on the.
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 02 Data and Expressions.
Object Oriented Programming
CSC 1051 – Data Structures and Algorithms I
Objects and Classes A class An object (the concept) (the realization)
Graphics Applets By Mr. Dave Clausen
title = "Java Software Solutions";
Chapter 5 Selection Statements
Graphics -- Introduction
Applet in Java.
Data and Expressions Part Two
Outline Character Strings Variables and Assignment
Presentation transcript:

Chapter 5 Graphics

Topics Applets Classes used for graphics –Graphics –Point –Dimension –Color

Applets A Java application is a stand-alone program with a main method (like the ones we've seen so far) A Java applet is a program that is intended to transported over the Web and executed using a web browser –An applet also can be executed using the appletviewer tool of the Java Software Development Kit –An applet doesn't have a main method –Instead, there are several special methods that serve specific purposes

Applets The paint method, for instance, is executed automatically and is used to draw the applet’s contents The paint method accepts a parameter that is an object of the Graphics class

Applets The class that defines an applet extends the Applet class 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

The HTML applet Tag The Einstein Applet

Graphics Classes We introduce four standard classes related to drawing geometric shapes on a window: –java.awt.Graphics –java.awt.Color –java.awt.Point –java.awt.Dimension

Graphics Class Frames and windows 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 has several methods for drawing shapes We can draw geometric shapes on a frame window by calling appropriate methods of the java.awt.Graphics class.

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

drawRect How the position of the rectangle is determined by the drawRect method. g.drawRect(50, 50, 100, 30);

Graphics Methods

Drawing an Oval X Y g.drawOval (175, 20, 50, 80); bounding rectangle

Drawing an Arc An arc is a part of an oval To draw you need to specify –the bounding rectangle for the entire oval –the starting angle (measured from the x-axis in degrees –the angle the arc subtends g.drawArc (175, 20, 50, 80, 20, 90);

Color Class The java.awt.Color class allows us to designate the color of an object. The RGB scheme combines three values ranging from 0 to 255 for red, green, and blue. Color pinkColor; pinkColor = new Color(255,175,175)

RGB Color The Color class also contains several static predefined colors, including: Object Color.black Color.blue Color.cyan Color.orange Color.white Color.yellow RGB Value 0, 0, 0 0, 0, 255 0, 255, , 200, 0 255, 255, , 255, 0

Color Class There are public class constants defined in the Color class for common colors: –Color.black –Color.blue –Color.green –Color.magenta –Color.orange

The Color Class Every drawing surface has a background color g.setBackground(Color.white); Every graphics context has a current foreground color –The most recently set foreground color is what is used for drawing g.setColor(Color.blue); g.drawRect(50, 50, 100, 30);

Point class A java.awt.Point object designates a point in two-dimensional space. The Point class has public instance variables To assign the position (10, 20) to a Point: Point pt = new Point(); pt.x = 10; pt.y = 20;

Dimension Class The java.awt.Dimension class can be used to create bounding rectangles that surround shapes. Dimension dim = new Dimension(); dim.width = 40; dim.height = 70; Bounding rectangles