CSC1401 Drawing in Java - 2. Reminder from last class How do you save your modified picture? String filename = …; Picture stevePicture = new Picture(filename);

Slides:



Advertisements
Similar presentations
Applets and Graphics.
Advertisements

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 2010 by Pearson Education Building Java Programs More Graphics reading: Supplement 3G.
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.
Laboratory Study II October, Java Programming Assignment  Write a program to calculate and output the distance traveled by a car on a tank of.
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?
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.
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.
Graphics CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Georgia Institute of Technology Drawing in Java – part 2 Barb Ericson Georgia Institute of Technology September 2005.
Java Two Dimensional Graphics with Affine Transforms
Graphics Programming. In this class we will cover: Drawing lines, rectangles, and ellipses Copying an area Drawing an image.
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.
Building Java Programs Supplement 3G Graphics Copyright (c) Pearson All rights reserved.
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 L37 Graphics and Java 2D™ (2). 2 OBJECTIVES To use methods of class Graphics to draw lines,  rectangles,  rectangles with rounded corners,  three-dimensional.
May 11, 1998CS102-02Lecture 7-1 More Graphics in Java CS Lecture 7-1 A picture's worth a thousand words.
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
Copyright 2008 by Pearson Education Building Java Programs Graphics reading: Supplement 3G videos: Ch. 3G #1-2.
1 L38 Graphics and Java 2D™ (3). 2 OBJECTIVES In this chapter you will learn:  To understand graphics contexts and graphics objects.  To understand.
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.
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.
Agenda For Feb Discussion (Assignments & Rubric) 2. PowerPoint Presentation (Drawing Basic Shapes). 4.Read Unit 3 carefully (pages ) then.
2D Graphics: Rendering Details
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.
Advanced User Interfaces with Java SD’98 - Session 3206 Ted Faison Faison Computing Inc.
Drawing-Turtle-and-AWT1 Drawing in Java Barb Ericson Georgia Institute of Technology Sept 21, 2009.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
1 Building Java Programs Supplement 3G: Graphics These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may not be rehosted, sold,
Aim: What is Adobe Illustrator?. Adobe Illustrator is a vector based drawing program.
Georgia Institute of Technology Drawing in Java Barb Ericson Georgia Institute of Technology August 2005.
Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Graphics ikt403 – Object-Oriented Software Development.
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 ________.
Georgia Institute of Technology Drawing in Java – part 3 Barb Ericson Georgia Institute of Technology September 2006.
Introductory Graphics Chapter Three. Computer Graphics §Full motion pictures (“Star Wars”) l animated films §Virtual reality §Games §Simulators (air craft.
Introduction to Graphics. Graphical objects To draw pictures, we will use three classes of objects: –DrawingPanel : A window on the screen. –Graphics.
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.
Georgia Institute of Technology Drawing in Java – part 1 Barb Ericson Georgia Institute of Technology September 2005.
Basic Graphics 03/03/16 & 03/07/16 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
Georgia Institute of Technology Drawing in Java – part 2 Dr Usman Saeed Assistant Professor Faculty of Computing and Information Technology North Jeddah.
CS202 Java Object Oriented Programming GUI Programming – Color and Drawing Methods Chengyu Sun California State University, Los Angeles.
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.
Barb Ericson Georgia Institute of Technology September 2005
Advanced AWT The Rendering Pipeline
Intro to Graphics from Chapter 2 of Java Software Solutions
Eleventh Graphics in Java.
12 Graphics and Java 2D™.
MS Paint A simple drawing tool that can be used to create simple or elaborate drawings. These drawings can be either black-and-white or color, and can.
Graphics Chapter 6 Copyright © 2000 W. W. Norton & Company.
Basic Graphics Chapter 5 3/19/15 Thursday Section Only
JAVA 2 Design and programming of GUI
Workshop for Programming And Systems Management Teachers
Java Graphics The basic rendering mechanism is the drawing system that controls when and how programs can draw on a graphics component. When a component.
4.14 GUI and Graphics Case Study: Creating Simple Drawings (Cont.)
Building Java Programs
Workshop for Programming And Systems Management Teachers
CSC1401 Viewing a picture as a 2D image - 2
Barb Ericson Georgia Institute of Technology September 2005
Presentation transcript:

CSC1401 Drawing in Java - 2

Reminder from last class How do you save your modified picture? String filename = …; Picture stevePicture = new Picture(filename); … // modify the picture stevePicture.write(“modifiedPicture.jpg”); Please note that by not specifying a directory, java saves the picture in the same directory as your java program

Learning Goals Understand at a conceptual and practical level How to draw more simple shapes with java.awt.Graphics Arcs Rectangles How to use a java.awt.Graphics2D class How to convert the Graphics class to it How to set the color How to set the paint How to set the stroke (paint brush) How to paint the object

Drawing Arcs Arcs Outlined Arc g.drawArc(topLeftX, topLeftY, width, height, startAngle, arcAngle); Filled Arc g.fillArc((topLeftX, topLeftY, width, height, startAngle, arcAngle);

Drawing Rectangles Rectangle Outlined Rectangle g.drawRect(topLeftX, topLeftY, width, height); Filled Rectangle g.fillRect(topLeftX,topLeftY,width,height); Outlined Rounded Rectangle g.drawRoundRect(topLeftX,topLeftY,width,height,arcWidth,arcHeight); Filled Rounded Rectangle g.fillRoundRect(topLeftX,topLeftY,width,height,arcWidth,arcHeight);

Drawing on a Blank Picture You can make pictures from the “blank” files They will have all white pixels 640x480.jpg 7inX95in.jpg You can also create a “blank” picture with a width and height They will also have all white pixels Picture blankPicture = new Picture(width,height);

Java 2D Graphics – java.awt Newer drawing classes More object-oriented Instead of drawOval() or fillOval() you create a Ellipse2D object and ask a 2d graphics object to draw or fill it Geometric shapes are in the java.awt.geom package Advanced Drawing Support for different types of brushes Line thickness, dashed lines, etc Supports cubic curves and general paths Drawing of gradients and textures Move, rotate, scale and shear text and graphics Create composite images

How To Use Java 2D Cast the Graphics class to Graphics2D Graphics2D g2 = (Graphics2D) gObj; Set up the stroke if desired (type of pen) g2.setStroke(new BasicStroke(widthAsFloat)); Set up a Color g2.setPaint(Color.blue); Create a geometric shape Line2D line2D = new Line2D.Double(0.0,0.0,100.0,100.0); Draw the outline of a geometric shape g2.draw(line2d); Fill a geometric shape g2.fill(rectangle2d);

Graphics2D inherits from Graphics Inherits basic drawing ability from Graphics Adds more advanced drawing ability Graphics Graphics2D

Drawing Lines Exercise Create a new method (drawWideX) for adding two wide crossed lines to a picture Using a passed color Using a passed line width Set up the stroke to make the lines thicker g2.setStroke(new BasicStroke(width)); Draw the lines

Using a Graphics Object to Copy an Image public void copy (Picture source, int x, int y) { // get the graphics object Graphics g = this.getGraphics(); // copy the image g.drawImage(source.getImage(),x,y,null); } Note: This method goes into our Picture class

Using Graphics2D to Copy an Image public void copy2D(Picture source, int x, int y) { // get the graphics object Graphics g = this.getGraphics(); Graphics g2 = (Graphics2D) g; // copy the image g2.drawImage(source.getImage(),x,y,null); }

Testing the Copy Method Picture p1 = new Picture(FileChooser.getMediaPath("beach.jpg")); Picture p2 = new Picture(FileChooser.getMediaPath("turtle.jpg")); p1.copy(p2,194,304); p1.show();

Summary You can use the original Graphics class for simple 2d drawing Lines, rectangles, ovals, polygons, strings, images You can use the Graphics2D class for more advanced drawing Width of paint brush, paint geometric objects Graphics2D inherits from Graphics Means it can do the same methods But also adds others

Assignment Read Media Computation Chapter 7, Sections