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.

Slides:



Advertisements
Similar presentations
Chapter 13 Graphics.
Advertisements

Custom Painting Gestione della Grafica customizzata Vedi anche:
Applets and Graphics.
Chapter 15 Graphics. To paint, you need to specify where to paint. Each component has its own coordinate system with the origin (0, 0) at the upper-left.
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
AWT Components. 2 Using AWT Components 4 Component –Canvas –Scrollbar –Button –Checkbox –Label –List –Choice –TextComponent –TextArea –TextField 4 Component.
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?
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.
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 1 Chapter 2 2D Graphics: Basics.
LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class.
Chapter 9 Color, Sound and Graphics
COMPUTER PROGRAMMING I Objective 8.03 Apply Animation and Graphic Methods in a Windows Form (4%)
Graphics CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Georgia Institute of Technology Drawing in Java – part 2 Barb Ericson Georgia Institute of Technology September 2005.
CSC1401 Drawing in Java - 2. Reminder from last class How do you save your modified picture? String filename = …; Picture stevePicture = new Picture(filename);
Draw Shapes Introduction to simple graphics. What is a graphics context? An instance of the Graphics class Graphics is ABSTRACT! You can extend Graphics.
Java Graphics Section 1 - Multi-File Graphics Programs Section 2 - The Coordinate System and Graphics Context g Section 3 - The Java Drawing and Painting.
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 Chapter 15 l Basic Figures l Colors l Fonts and Other Text Details Graphics Objects.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Topics  Applets  Classes used for graphics Graphics Point Dimension.
May 11, 1998CS102-02Lecture 7-1 More Graphics in Java CS Lecture 7-1 A picture's worth a thousand words.
 2005 Pearson Education, Inc. All rights reserved Graphics and Java 2D™
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
©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.
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.
Graphics in Android 1 Fall 2012 CS2302: Programming Principles.
Chapter 16: Graphics. Objectives Learn about the paint() and repaint() methods Use the drawString() method to draw String s using various fonts and colors.
Agenda For Feb Discussion (Assignments & Rubric) 2. PowerPoint Presentation (Drawing Basic Shapes). 4.Read Unit 3 carefully (pages ) then.
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.
Chapter 11 - Graphics and Java 2D Outline 11.1 Introduction 11.2 Graphics Contexts and Graphics Objects 11.3 Color Control 11.4 Font Control 11.5 Drawing.
Modernās Programmēšanas Tehnoloģijas (Advanced Programming Technologies) Edgars Celms, Mārtiņš Opmanis Latvijas Universitātes Matemātikas.
DHTML: Structured Graphics ActiveX Control
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.
Chapter 6: Graphics Java Programming FROM THE BEGINNING Copyright © 2000 W. W. Norton & Company. All rights reserved. 1 Chapter 6 Graphics.
Chapter 15Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 15 l Basic Figures l Colors l Fonts and Other Text Details.
Graphics & Java 2D Drawing Two Dimensional Shapes Controlling Fonts Controlling Colors.
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.
Tkinter Canvas.
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Graphics ikt403 – Object-Oriented Software Development.
Painting (Chapter 12) Java Certification Study Group January 25, 1999 Mark Roth.
Creating Graphics in Java CSE301 University of Sunderland Harry R Erwin, PhD.
Chapter 2: Graphics In Java Basics of classes –instance variables –methods –overriding methods Graphics class (drawing routines) Other classes –Color –Font.
Graphics and Java2D Chapter Java Coordinate System Origin is in _____________ corner –Behind title bar of window X values increase to the ________.
Introductory Graphics Chapter Three. Computer Graphics §Full motion pictures (“Star Wars”) l animated films §Virtual reality §Games §Simulators (air craft.
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.
Graphics and Multimedia. OUTLINE Font Control Drawing Lines, Rectangles and Ovals Drawing Arcs Drawing a General Path.
Graphics in Android 1 CS7030: Mobile App Development.
Getting Started with GUI Programming Chapter 10 CSCI 1302.
(PART III) Graphics and Multimedia 16/02/1437 Lect6 CT
CPCS 391 Computer Graphics Lab One. Computer Graphics Using Java What is Computer Graphics: Computer graphics are graphics created using computers and,
Chapter 7 Introduction to High-Level Language Programming.
Graphics Drawing Things With Java. Today's Topics Course Updates Java Graphics –Java 1.1 versus Java 1.2 (Java 2) Drawing Lines Drawing Shapes.
Java Graphics and Java2D
Intro to Graphics from Chapter 2 of Java Software Solutions
12 Graphics and Java 2D™.
Graphics Chapter 6 Copyright © 2000 W. W. Norton & Company.
JAVA 2 Design and programming of GUI
4.14 GUI and Graphics Case Study: Creating Simple Drawings (Cont.)
Graphics in Android Fall 2012 CS2302: Programming Principles.
Graphics -- Introduction
12 Graphics and Java 2D™.
slides courtesy of Eric Roberts
Presentation transcript:

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 rectangles,  ovals,  arcs  and polygons.

Drawing Lines, Rectangles and Ovals Graphics methods for drawing lines, rectangles and ovals – fillRoundRect and drawRoundRect – draw rectangles with rounded corners – bounding rectangle—the area in which a rounded rectangle or oval will be drawn – draw3DRect and fill3DRect – draw a 3D rectangle that is either raised or lowered – drawOval and fillOval – draw ovals

4 Fig | Graphics methods that draw lines, rectangles and ovals. (Part 1 of 2)

5 Fig | Graphics methods that draw lines, rectangles and ovals. (Part 2 of 2)

6 Outline LinesRectsOvals JPanel.java (1 of 2) Draw a straight lineDraw an empty rectangleDraw a filled rectangle

7 Outline LinesRectsOvals JPanel.java (2 of 2) Draw a filled rectangle with rounded cornersDraw an empty rectangle with rounded cornersDraw an empty rectangle that is raisedDraw a filled rectangle that is loweredDraw an empty ovalDraw a filled oval

8 Outline LinesRectsOvals.java (1 of 2)

9 Outline LinesRectsOvals.java (1 of 2) fillRoundRect drawRoundRect drawOval fillOval drawLine drawRect fillRect draw3DRect fill3DRect

10 Fig | Arc width and arc height for rounded rectangles.

11 Fig | Oval bounded by a rectangle.

Drawing Arcs An arc is drawn as a portion of an oval Arcs sweep (i.e., move along a curve) from a starting angle by the number of degrees specified by their arc angle – Counterclockwise sweep measured in positive degrees – Clockwise sweep measured in negative degrees Graphics methods drawArc and fillArc are used to draw arcs

13 Fig | Positive and negative arc angles.

14 Fig | Graphics methods for drawing arcs.

15 Outline ArcsJPanel.java (1 of 2) x- and y-coordinates for upper left corner of bounding rectangle Width and height of bounding rectangle Starting angle Sweep angle Draw empty arcs

16 Outline ArcsJPanel.java (2 of 2) Draw filled arcs Negative values indicate arc should sweep clockwise

17 Outline DrawArcs.java (1 of 2)

18 Outline DrawArcs.java (2 of 2)

Drawing Polygons and Polylines Polygons – Closed multisided shapes composed of straight line segments – Graphics methods drawPolygon and fillPolygon to display polygons – Polygons can be represented using class Polygon – class contains method addPoint to add points to a Polygon Polylines – Sequences of connected points – Graphics method drawPolyline to display polylines

20 Fig | Graphics methods for polygons and class Polygon methods. (Part 1 of 2)

21 Fig | Graphics methods for polygons and class Polygon methods. (Part 2 of 2)

22 Outline PolygonsJPanel.java (1 of 2) Create Polygon object from sets of x- and y-coordinates Draw an empty Polygon Draw polyline from sets of x- and y-coordinates

23 Outline PolygonsJPanel.java (2 of 2) Draw polygon from sets of x- and y-coordinates, without creating Polygon object Add coordinates to Polygon with method addPoint

24 Outline DrawPolygons.java (1 of 2)

25 Outline DrawPolygons.java (2 of 2) Result of line 28 Result of line 37 Result of line 23 Result of line 18