Graphics and Java2D Chapter 12. 2 Java Coordinate System Origin is in _____________ corner –Behind title bar of window X values increase to the ________.

Slides:



Advertisements
Similar presentations
2D Graphics Drawing Things. Graphics In your GUI, you might want to draw graphics E.g. draw lines, circles, shapes, draw strings etc The Graphics class.
Advertisements

Frame Windows A frame object is used to create a graphical frame window. This frame is used to show information in a graphical application. The JFrame.
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?
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
UID – Swing and Graphics Boriana Koleva
1 Graphics -- Introduction zThe use of graphics is common among modern software systems  Java has strong API support for graphics in the java.awt (abstract.
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.
1 L36 Graphics and Java 2D™ (1). 2 OBJECTIVES  To understand graphics contexts and graphics objects.  To understand and be able to manipulate colors.
1 Chapter 15 l Basic Figures l Colors l Fonts and Other Text Details Graphics Objects.
Graphics Programming. In this class, we will cover: The difference between AWT and Swing Creating a frame Frame positioning Displaying information in.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Topics  Applets  Classes used for graphics Graphics Point Dimension.
Slides prepared by Rose Williams, Binghamton University Chapter 19 Swing II.
1 L37 Graphics and Java 2D™ (2). 2 OBJECTIVES To use methods of class Graphics to draw lines,  rectangles,  rectangles with rounded corners,  three-dimensional.
 2005 Pearson Education, Inc. All rights reserved Graphics and Java 2D™
Slides prepared by Rose Williams, Binghamton University Chapter 19 Swing II.
©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.
1 L38 Graphics and Java 2D™ (3). 2 OBJECTIVES In this chapter you will learn:  To understand graphics contexts and graphics objects.  To understand.
©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.
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.
Graphics Images – PictureBox control Drawing graphics - Graphics object Multimedia controls PictureBox control Image property – select image Choose how.
Java Software Solutions Lewis and Loftus Chapter 7 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphics -- Introduction The.
1 Graphical User Components (II) Outline JTextArea Creating a Customized Subclass of JPanel JPanel Subclass that Handles Its Own Events Windows: Additional.
(C) 2010 Pearson Education, Inc. All rights reserved. Omer Boyaci.
Chapter 15 Graphics and Java 2D™ Java How to Program, 8/e (C) 2010 Pearson Education, Inc. All rights reserved.
© 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.
 Pearson Education, Inc. All rights reserved. 1 Ch 12 Graphics and Java 2D In this chapter you will learn:  To understand graphics contexts.
Lecture 15: Intro to Graphics Yoni Fridman 7/25/01 7/25/01.
Graphics and Java 2D. 2 Introduction Java’s graphics capabilities –Drawing 2D shapes –Controlling colors –Controlling fonts Java 2D API –More sophisticated.
Chapter 15Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 15 l Basic Figures l Colors l Fonts and Other Text Details.
Chapter 7 Graphics. © Daly and Wrigley Objectives Use Graphic Components: ▫ Strings ▫ Lines ▫ Rectangles ▫ Ovals ▫ Arcs Change the color and font of elements.
Graphics & Java 2D Drawing Two Dimensional Shapes Controlling Fonts Controlling Colors.
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.
Graphics Copyright © 2015 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved. Java Methods Object-Oriented Programming and Data.
Java Graphics. Review 3 kinds of elements in components API? Layout managers Events Extend vs. Implement.
Introduction to Java Simple Graphics. Objects and Methods Recall that a method is an action which can be performed by an object. –The action takes place.
Agenda Java Coordinate Systems. Graphics Class. Drawing on Panels. Drawing Shapes.
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
Attributes of drawing elements
Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Graphics ikt403 – Object-Oriented Software Development.
Paint Application in Java Clark Jayson Cacal Aveline Germar Jose Sison Christopher Valera.
Introduction to Java Chapter 8 - Introduction to Java Graphics1 Chapter 8 Introduction to Java Graphics.
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 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.
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Graphics in Java Opening Discussion zDo you have any questions about the quiz? zWhat did we talk about last class? zDo you have any questions.
Basic Graphics 03/03/16 & 03/07/16 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
Projects: not limited to spec Error checking File filters Create multiple file formats Polygons Filled shapes Etc.
CPCS 391 Computer Graphics Lab One. Computer Graphics Using Java What is Computer Graphics: Computer graphics are graphics created using computers and,
Graphics JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin, Gary Litvin, and Skylight.
10/20/2005week71 Graphics, mouse and mouse motion events, KeyEvent Agenda Classes in AWT for graphics Example java programs –Graphics –Mouse events –Mouse.
Eleventh Graphics in Java.
12 Graphics and Java 2D™.
Chapter 8 Graphics.
Basic Graphics Chapter 5 3/19/15 Thursday Section Only
Java Programming: Guided Learning with Early Objects
JAVA 2 Design and programming of GUI
Chapter 10 Graphics.
Basic Graphics Drawing Shapes 1.
Chapter 14 JavaFX Basics Dr. Clincy - Lecture.
4.14 GUI and Graphics Case Study: Creating Simple Drawings (Cont.)
Graphics -- Introduction
12 Graphics and Java 2D™.
Chapter 8 Graphics.
Presentation transcript:

Graphics and Java2D Chapter 12

2 Java Coordinate System Origin is in _____________ corner –Behind title bar of window X values increase to the ________ ________ increase down the screen Coordinate units are in __________

3 Graphics Contexts & Objects A Java graphics enables drawing on the screen A Graphics object –Manages a graphics context –Draws pixels that represent ___________ Graphics objects have methods for –Drawing –Font and ___________ manipulation

4 The Graphics Class The paint() Method Graphics is an _____________ class –Cannot be instantiated Class Component has method ________ –Takes a ___________ object as an argument public void paint (Graphics g) Component also has –public void ___________() –public void update (Graphics g) We focus on the paint method in this chapter

5 The paint Method A Swing GUI needs to paint itself –The ___________ time –In response to becoming _____________ –Because it needs to reflect a change in the program's state Starts with the highest component that needs to be repainted –Works its way down the containment __________________. Sun tutorial on the paint methodSun tutorial

6 Color Control Class Color has – –Used to manipulate ______________ Colors created from mix of red, green, blue components –Specified in range from 0 to 255 (or floating point values 0.0 to 1.0) Methods include –Constructors, get (for R, G, B, and color), set

7 Color Methods

8 Color Control Note Figure 12.5 –Draws color __________ –Draws ___________ in color –Gets color values for use Note Figure 12.6 –Demonstrates the JColorChooser GUI component –Note the ___________ of the component for specifying the color in different ways

9 Graphics Applications As always the program "is a _________" This time –The class (program) extends _____________ –We have a constructor for the class –That ___________ does most of the activity The ___________ function does very little –Creates an instance of the class that is the program This instantiation calls the constructor –Sets up the exit call

10 Font Control Methods

11 Font Control Font class constructor arguments – View demonstration of font control –Figure 12.9Figure 12.9 Note, to change the font –Must create a ________________________ –Font objects are ______________ – no set methods

12 Font Metrics Methods

13 Font Metrics Sometimes necessary to get info about current drawing font –Name, style, font size –Class _________________ has methods for accessing Note further measurements (metrics) concerning fonts View Figure 12.12, program to manipulate font metricsFigure 12.12

14 Graphics Methods for Lines, Rectangles, Ovals

15 Graphics Methods for Lines, Rectangles, Ovals

16 Drawing Lines, Rectangles, Ovals Methods to manage: –Lines –Rectangles (_____________ or ____________) –Round cornered rectangles –3D renditions of rectangles –Ovals Note height and width specs for ovals

17 Drawing Lines, Rectangles, Ovals View sample program, Figure 12.14Figure –Note use of ________________________() from Graphics class

18 Graphics Methods for Drawing Arcs

19 Drawing Arcs Definition of an arc –A portion of an ________ –Measured in _________ Arguments for arc methods –Coordinates for upper _____ corner –Height, width –________ for start of sweep –Number of degrees for ________ View Figure 12.19, drawing arcsFigure 12.19

20 Graphics Methods for Drawing Polygons

21 Graphics Methods for Drawing Polygons

22 Polygons and Polylines Polygon –Multisided shape –Composed of _________________ Polyline –Sequence of ______________ points Note Polygon class, pg 592 –Constructors View Figure 12.21, a program to draw polygons and polylinesFigure 12.21

23 Java2D API Advanced two-dimensional graphics Drawing accomplished with instance of Graphics2D –An abstract _____________ of Graphics –Must cast ____________________ passed to paint into a Graphics2D reference Graphics2D g2d = (Graphics2D) g;

24 Java2D API Note capabilities –New __________ added to shapes drawn –____________ –Fill with graphic –_____________ lines View Figure which created this outputFigure 12.22

25 Java2D API General path : a shape constructed from –___________ lines and –Complex ____________ View Figure 12.23Figure –Uses GeneralPath package