Graphics Programming. In this class we will cover: Drawing lines, rectangles, and ellipses Copying an area Drawing an image.

Slides:



Advertisements
Similar presentations
Chapter 13 Graphics classes Bjarne Stroustrup
Advertisements

Lesson One: The Beginning
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.
PHP Sample Application Simple graphics and database.
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.
Cosc 5/4730 Blackberry Drawing. Screen size With Blackberry devices, they have a known screen size in pixels. If you are programming for specific device.
Graphics Programming. Introduction GOAL: Build the Indexer Client Event-driven vs. Sequential programs Terminology – Top-level windows are called “frame.
Introduction to shapes
Copyright © 2004 ProsoftTraining, All Rights Reserved. Lesson 8: Image Techniques ©2007 Prosoft Learning Corporation All rights reserved ITD 110 Web Page.
Python Programming, 2/e1 CS177: Programming in Multimedia Objects Recitation Topic: Graphics Library.
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Applets Graphical Java programs Run inside web browser Platform-neutral Easy deployment--loads when needed Secure.
Georgia Institute of Technology Drawing in Java – part 2 Barb Ericson Georgia Institute of Technology September 2005.
Chapter 4 (Horstmann’s Book) Interface Types and Polymorphism: Graphics, Timer, Animation Hwajung Lee.
CSC1401 Drawing in Java - 2. Reminder from last class How do you save your modified picture? String filename = …; Picture stevePicture = new Picture(filename);
Image Maps and Graphics Internet Basics and Far Beyond! Mrs. Wilson.
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.
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. 4 th Ed Chapter Java Applets What is an Applet? How do you create.
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 Applets and Graphics.
Georgia Institute of Technology Drawing in Java part 1 Barb Ericson Georgia Institute of Technology September 2006.
Chapter 16: Graphics. Objectives Learn about the paint() and repaint() methods Use the drawString() method to draw String s using various fonts and colors.
©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.
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.
Default Fill & Stroke D Swap Fill & Stroke Shift X None / Gradient > Color < Stroke X Fill (Click to activate) X More about Fill and Stroke:
Introduction to Flash. Topics What is Flash? What can you do with it? Simple animation Complex interactive web application, such as an online store. Starting.
Digital Media Dr. Jim Rowan ITEC Vector Graphics Elegant way to construct digital images that –have a compact representation –are scalable –are.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved CheckWriter Application Introducing Graphics and Printing.
Lecture 15: Intro to Graphics Yoni Fridman 7/25/01 7/25/01.
Working with Objects. Objectives Create an object Transform an object Arrange and lock an object Step and repeat an object Use Live Distribute Use the.
Creating Art With Simple Shapes By carefully implementing simple shapes to an HTML canvas we can create useful graphics. With enough time, lines, ellipses.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
Digital Media Dr. Jim Rowan ITEC So far… We have compared bitmapped graphics and vector graphics We have discussed bitmapped images, some file formats.
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
Graphics and Java2D Chapter Java Coordinate System Origin is in _____________ corner –Behind title bar of window X values increase to the ________.
CS 325 Introduction to Computer Graphics 04 / 12 / 2010 Instructor: Michael Eckmann.
Georgia Institute of Technology Drawing in Java – part 3 Barb Ericson Georgia Institute of Technology September 2006.
Digital Media Dr. Jim Rowan ITEC Vector Graphics Elegant way to construct digital images that –have a compact representation –are scalable –are.
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.
Digital Media Lecture 5: Vector Graphics Georgia Gwinnett College School of Science and Technology Dr. Jim Rowan.
Adobe InDesign CS5 – Illustrated Unit C: Working with Objects.
+ This step by step tutorial demonstrates drawing a keyboard illustration using rectangles, grids, move and transform effects.
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
CSC1401 Drawing in Java - 1. Goals Understand at a conceptual and practical level How to use the Turtle class to draw on a picture How to use the java.awt.Graphics.
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.
Georgia Institute of Technology Drawing in Java – part 1 Barb Ericson Georgia Institute of Technology September 2005.
CS 115 Lecture 6 Graphics Taken from notes by Dr. Neil Moore.
Georgia Institute of Technology Drawing in Java – part 2 Dr Usman Saeed Assistant Professor Faculty of Computing and Information Technology North Jeddah.
Main characteristics of Vector graphics  Vector graphics provide an elegant way of constructing digital images (diagrams, technical illustration and.
Barb Ericson Georgia Institute of Technology September 2005
12 Graphics and Java 2D™.
Barb Ericson Georgia Institute of Technology September 2005
Lesson One: The Beginning Chapter 1: Pixels Learning Processing Daniel Shiffman Presentation by Donald W. Smith Graphics from
Graphics Part I Taken from notes by Dr. Neil Moore
Chapter 14 JavaFX Basics Dr. Clincy - Lecture.
CS 106A, Lecture 12 More Graphics
ISC440: Web Programming II Ch14: HTML5 Canvas
4.14 GUI and Graphics Case Study: Creating Simple Drawings (Cont.)
Digital Media Dr. Jim Rowan ITEC 2110.
Exam1 Review CSE113 B.Ramamurthy 11/29/2018 B.Ramamurthy.
Graphics Part I Taken from notes by Dr. Neil Moore
Pictures in 3-D flip book (Intermediate)
Exam1 Review CSE113 B.Ramamurthy 4/17/2019 B.Ramamurthy.
Barb Ericson Georgia Institute of Technology September 2005
JavaScript – Let’s Draw!
Presentation transcript:

Graphics Programming

In this class we will cover: Drawing lines, rectangles, and ellipses Copying an area Drawing an image

Drawing Lines, Rectangles and Ellipses Java2D oraganizes geometric shapes in OO fashion. There are classes to represent lines, rectangles and ellipses. –Line2D –Rectangle2D –Ellipse2D These all implement the Shape interface

Drawing Shapes To draw a shape, you first create an object of a class that implements the Shape interface and then call the draw method of the Graphics2D class. Rectangle 2D rect =...; g2.draw(rect); There are two versions of each Shape class –one with float coordinates (conserves memory) –one with double coordinates (easier to use) Example: Rectangle2D rect = new Rectangle2D.Double(10.0, 25.0, 22.5, 20.0);

Drawing Rectangles Rectangles are simple to construct Requires four arguments –x- and y-coordinates of the upper-left corner –the width and the height The Rectangle2D class has over 20 useful methods including: –get Width –getHeight –getCenterX –getCenterY

Drawing Rectangles Sometimes you don’t have the top-left corner readily available. It is possible to have two diagonal corners of a rectangle that are not the top-left corner and the bottom-right corner. To create a rectangle in this case use the setFrameFromDiagonal method. Rectangle2D rect = new Rectangle2D.Double(); rect.setFrameFromDiagonal(px, py, qx, qy); If you have a Point2D object, you can also create a rectangle by calling Rectangle2D rect = new Rectangle2D.Double(p1, p2);

Drawing Ellipses The class Ellipse2D is inherited from the same Rectangle class that Rectangle2D is. –because of the bounding box surrounding the ellipse So, creating an Ellipse2D object is very similar to creating a Rectangle2D object. Ellipse2D e = new Ellipse2D.Double(px, py, qx, qy) where px, py are the x- and y-coordinates of the top-left corner and qx, qy are the x- and y-coordinates of the bottom-right corner of the bounding box of the ellipse

Drawing Lines To construct a line, simple use the Line2D class. It too, requires 4 arguments (the x and y coordinates of the start and end positions) These coordinates can be 2 Point2D objects or 2 pairs of numbers. Line2D line = new Line2D.Double(start, end) or Line2D line = new Line2D.Double(px, py, qx, qy)

Filling Shapes You can fill the interior of closed shape objects with a color. Simply call the fill instead of draw method on the Graphics object. Rectangle2D rect = new Rectangle2D.Double(x, y, x2, y2); g2.setPaint(Color.red); g2.fill(rect);

Images You can display images on the Graphics object. You can use images stored locally or someplace on the Internet. If an image is stored locally call: String filename = “…”; Image image = ImageIO.read(new File(filename)); If an image is on the Internet, use the url: String filename = “…”; Image image = ImageIO.read(new URL(url); To draw the image: g.drawImage(image, x, y, null)

Copying an Area copyArea() method - Use to copy an area Requires 6 parameters –x-coordinate and y-coordinate of the upper-left corner of the area to be copied –Width and height of the area to be copied –The horizontal and vertical displacement of the destination of the copy

More on Graphics We have just begun to touch on the various graphics shapes available. You can also draw: –arcs –polygons –three-dimensional shpes Java 2D also lets you create higher-quality two- dimensional graphics, images, and text using: –fill patterns such as gradients –strokes that define the width and style of a drawing stroke –anti-aliasing, a graphics technique for producing smoother on-screen graphics For more info see:

Example So, let’s put all of this together in an example: See: hapesTest.java hapesTest.java