Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Graphics ikt403 – Object-Oriented Software Development.

Slides:



Advertisements
Similar presentations
Chapter 13 Graphics.
Advertisements

Custom Painting Gestione della Grafica customizzata Vedi anche:
Applets and Graphics.
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.
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.
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.
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 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.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Topics  Applets  Classes used for graphics Graphics Point Dimension.
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.
 2005 Pearson Education, Inc. All rights reserved Graphics and Java 2D™
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.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 16 : Swing VI Graphics King Fahd University of Petroleum & Minerals College of Computer.
Topics AWT Classes Window Fundamentals Working with Frame Windows Creating a Frame Window in an Applet Creating a Windowed Program Displaying Information.
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 and Multimedia. Introduction The language contains many sophisticated drawing capabilities as part of namespace System.Drawing and the other.
Chapter 16: Graphics. Objectives Learn about the paint() and repaint() methods Use the drawString() method to draw String s using various fonts and colors.
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.
Modernās Programmēšanas Tehnoloģijas (Advanced Programming Technologies) Edgars Celms, Mārtiņš Opmanis Latvijas Universitātes Matemātikas.
(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.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved CheckWriter Application Introducing Graphics and Printing.
Chapter 6: Graphics Java Programming FROM THE BEGINNING Copyright © 2000 W. W. Norton & Company. All rights reserved. 1 Chapter 6 Graphics.
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.
Graphics Copyright © 2015 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved. Java Methods Object-Oriented Programming and Data.
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.
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
Introduction to Java Chapter 8 - Introduction to Java Graphics1 Chapter 8 Introduction to Java Graphics.
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 ________.
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 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Getting Started with GUI Programming Chapter 10 CSCI 1302.
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.
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.
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.
Intro to Graphics from Chapter 2 of Java Software Solutions
12 Graphics and Java 2D™.
Chapter 8 Graphics.
Graphics Chapter 6 Copyright © 2000 W. W. Norton & Company.
JAVA 2 Design and programming of GUI
Chapter 10 Graphics.
4.14 GUI and Graphics Case Study: Creating Simple Drawings (Cont.)
Graphics -- Introduction
12 Graphics and Java 2D™.
Chapter 8 Graphics.
Presentation transcript:

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Graphics ikt403 – Object-Oriented Software Development

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Introduction Java contains support for graphics that enable programmers to visually enhance applications Java contains many more sophisticated drawing capabilities as part of the Java 2D API Classes –Color –Font, FontMetrics –Graphics2D –Polygon –BasicStroke –GradientPaint, TexturePaint –Java 2D shape classes

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Introduction Java coordinate system –Upper-left corner of a GUI component has the coordinates (0, 0) –Contains x-coordinate (horizontal coordinate) - horizontal distance moving right from the left of the screen –Contains y-coordinate (vertical coordinate) - vertical distance moving down from the top of the screen Coordinate units are measured in pixels. A pixel is a display monitor’s smallest unit of resolution.

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Java coordinate system. Units are measured in pixels.

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Graphics Contexts and Graphics Objects A Java graphics context enables drawing on the screen Class Graphics –Manages a graphics context and draws pixels on the screen –An abstract class – contributes to Java’s portability Method paintComponent –Used to draw graphics –Member of class JComponent, subclass of Component –Graphics object passed to paintComponent by the system when a lightweight Swing component needs to be repainted –If programmer needs to have paintComponent execute, a call is made to method repaint

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Color Control Class Color declares methods and constants for manipulating colors in a Java program Every color is created from a red, a green and a blue component – RGB values

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Color constants and their RGB values.

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Color methods and color-related Graphics methods.

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Outline Method paintComponent paints JPanel Set current drawing color with method setColor Draw filled rectangle using current color Draw text value of current colorSet current drawing color, specify float arguments to Color constructor Set current drawing color using Color constant

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Outline Retrieving RGB values using methods getRed, getGreen and getBlue

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Outline

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Font Control Class Font –Constructor takes three arguments—the font name, font style and font size Font name – any font currently supported by the system on which the program is running Font style – Font.PLAIN, Font.ITALIC or Font.BOLD. Font styles can be used in combination Font sizes – measured in points. A point is 1/72 of an inch. –Methods getName, getStyle and getSize retrieve information about Font object –Graphics methods getFont and setFont retrieve and set the current font, respectively

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Font-related methods and constants.

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Font-related methods and constants.

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Outline Creating Font objects Font nameFont style Font size

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Outline Combining styles Retrieve font name and size of Graphics object’s current Font

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Outline

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE 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

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Graphics methods that draw lines, rectangles and ovals.

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Graphics methods that draw lines, rectangles and ovals.

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Outline Draw a straight lineDraw an empty rectangleDraw a filled rectangle

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Outline 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

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Outline

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Outline fillRoundRect drawRoundRect drawOval fillOval drawLine drawRect fillRect draw3DRect fill3DRect

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE 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

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Positive and negative arc angles.

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Graphics methods for drawing arcs.

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Outline x- and y-coordinates for upper left corner of bounding rectangle Width and height of bounding rectangle Starting angle Sweep angle Draw empty arcs

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Outline Draw filled arcs Negative values indicate arc should sweep clockwise

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Outline

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Outline

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE 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

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Graphics methods for polygons and class Polygon methods.

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Graphics methods for polygons and class Polygon methods.

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Outline Create Polygon object from sets of x- and y-coordinates Draw an empty Polygon Draw polyline from sets of x- and y-coordinates

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Outline Draw polygon from sets of x- and y-coordinates, without creating Polygon object Add coordinates to Polygon with method addPoint

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Outline

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Outline Result of line 28 Result of line 37 Result of line 23 Result of line 18

Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE