May 11, 1998CS102-02Lecture 7-1 More Graphics in Java CS 102-02 Lecture 7-1 A picture's worth a thousand words.

Slides:



Advertisements
Similar presentations
Applets and Graphics.
Advertisements

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.
LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class.
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 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.
 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 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.
May 13, 1998CS102-02Lecture 7-2 The End of Graphics in Java CS Lecture 7-2 A picture's worth a thousand words.
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.
CS324e - Elements of Graphics and Visualization Java2D Graphics.
Graphics. Graphics Features in Java Topics to be covered Topics to be covered Graphics Basics Graphics Basics Coordinate System Coordinate System Graphics,
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.
2D Graphics: Rendering Details
© 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 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.
Applets & Graphics. Applets programs that run inside a browser Java platform-independence makes applets possible security restrictions: –cannot read or.
Drawing and Filling Geometric Shapes. Java comes with more than just points and lines. Within the Graphics2D class, there are also methods for drawing.
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.
1 Chapter 3 2D Graphics: Rendering Details  Color spaces, paints stroke types  Affine transforms including translation, rotation, scaling, shearing,
(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.
1 Graphics, Fonts and Color Chapter 9. 2 What is in this chapter: l Graphics class and coordinates l graphics primitives (lines,rectangles,ovals and arcs)
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.
Basic Graphics 03/03/16 & 03/07/16 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
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,
CS202 Java Object Oriented Programming GUI Programming – Color and Drawing Methods Chengyu Sun California State University, Los Angeles.
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.
12 Graphics and Java 2D™.
Chapter 8 Graphics.
Graphics Chapter 6 Copyright © 2000 W. W. Norton & Company.
Barb Ericson Georgia Institute of Technology September 2005
Graphics Applets By Mr. Dave Clausen
JAVA 2 Design and programming of GUI
Chapter 10 Graphics.
CS 106A, Lecture 12 More Graphics
Workshop for Programming And Systems Management Teachers
4.14 GUI and Graphics Case Study: Creating Simple Drawings (Cont.)
Graphics Chapter 6 Copyright © 2000 W. W. Norton & Company.
Graphics -- Introduction
12 Graphics and Java 2D™.
Workshop for Programming And Systems Management Teachers
Chapter 8 Graphics.
Presentation transcript:

May 11, 1998CS102-02Lecture 7-1 More Graphics in Java CS Lecture 7-1 A picture's worth a thousand words

May 11, 1998CS102-02Lecture 7-1 Agenda Fonts Lines Rectangles Ovals Arcs

May 11, 1998CS102-02Lecture 7-1 Logical Fonts Different systems have different fonts Java uses logical fonts –Maps logical fonts into system-specific fonts

May 11, 1998CS102-02Lecture 7-1 Specifying Fonts Font name –Serif, Sans Serif, Dialog, DialogInput and Monospaced Sans Serif With Serif Font style –Bold, italic and plain Font size –Point size (1pt = 1/72nd of an inch)

May 11, 1998CS102-02Lecture 7-1 Font Names Listed names are guaranteed, but there might be more –From my Win NT 4.0 machine: Dialog, SansSerif, Serif, Monospaced, Helvetica, TimesRoman, Courier, DialogInput, ZapfDingbats

May 11, 1998CS102-02Lecture 7-1 Getting the List Use the Toolkit Toolkit is the link between Java and the specific system String fonts[] = Toolkit.getDefaultToolkit().getFontList();

May 11, 1998CS102-02Lecture 7-1 Constant Styles Font class includes constants for setting style –Font.BOLD, Font.ITALIC, Font.PLAIN –Combine them with +, as in Font.BOLD+Font.ITALIC gives a bold, italic font

May 11, 1998CS102-02Lecture 7-1 What Does Size Mean? Every font has many sizes associated with it Different sizes are the font's metrics Font's size (in points) is a rough gauge of the overall size

May 11, 1998CS102-02Lecture 7-1 Font Metrics From the Java Tutorial

May 11, 1998CS102-02Lecture 7-1 How High? getAscent(), getMaxAscent() –Number of pixels between the ascender line and the baseline Ascender line represents the typical height of capital letters (chosen by the font's designer to represent the correct text "color") Ascent typically provides enough room for almost all of the characters in the font, except perhaps for accents on capital letters getMaxAscent() method accounts for these exceptionally tall characters.

May 11, 1998CS102-02Lecture 7-1 How Low Can You Go? getDescent(), getMaxDescent() –Number of pixels between the baseline and the descender line –In most fonts, all characters fall within the descender line at their lowest point –Use the getMaxDescent() method to get a distance guaranteed to encompass all characters.

May 11, 1998CS102-02Lecture 7-1 Font Height getHeight() –Returns the number of pixels normally found between the baseline of one line of text and the baseline of the next line of text –Includes an allowance for leading.

May 11, 1998CS102-02Lecture 7-1 Leading getLeading() –Returns the suggested distance (in pixels) between one line of text and the next –Leading is the distance between the descender line of one line of text and the ascender line of the next line of text.

May 11, 1998CS102-02Lecture 7-1 Will the Real Size Please Stand Up? Font size (returned by the Font class getSize() method) is an abstract measurement –In theory: corresponds to the ascent plus the descent –Reality: font designer decides exactly how tall a "12 point" font (for example) is 12-point Times is often slightly shorter than 12- point Helvetica.

May 11, 1998CS102-02Lecture 7-1 Font Measurements Use a FontMetrics object –Call methods such as getAscent() and getDescent() from a FontMetrics object int ascent = g.getFontMetrics().getAscent(); When text is drawn at (x,y), the specified point is used as the reference point Baseline

May 11, 1998CS102-02Lecture 7-1 Drawing Lines Use the drawLine() method of the Graphics class drawLine(int x1, int y1, int x2, int y2) Specify four coordinates x1, y1 x2, y2

May 11, 1998CS102-02Lecture 7-1 Drawing Rectangles Two dimensions gives more options –Filled and unfilled –Fill color is the current color -- not an argument to the method Just a rectangle drawRect( int x,// top-left int y,// coordinate int width, int height)

May 11, 1998CS102-02Lecture 7-1 Filled & Unfilled x, y width heightheight

May 11, 1998CS102-02Lecture 7-1 Rectangle Flavors Outline rectangle drawRect() Filled (in current foreground color) rectangle fillRect() Filled (in background color) rectangle clearRect()

May 11, 1998CS102-02Lecture 7-1 Rounded Rectangles To draw a rounded rectangle drawRoundRect(x, y, width, height, arcWidth, arcHeight) Rounded rectangles can also be filled fillRoundRect() arcWidth arcHeight width heightheight x, y

May 11, 1998CS102-02Lecture 7-1 Drawing 3-D Rectangles Draw a 3-D highlighted outline of the specified rectangle –Edges of the rectangle are highlighted so that they appear to be beveled –Lit from the upper left corner draw3DRect(int x, int y, int width, int height, boolean raised)

May 11, 1998CS102-02Lecture D Highlighting Colors used for the highlighting effect are based on the current color Resulting rectangle covers an area that is width + 1 pixels wide by height + 1 pixels tall Filled 3D rectangles with fill3DRect()

May 11, 1998CS102-02Lecture 7-1 Drawing Ovals Drawing ovals is similar to drawing rectangles because you specify the bounding box for the oval For an unfilled oval: drawOval( int x,// top-left int y,// coordinate int width, int height)

May 11, 1998CS102-02Lecture 7-1 A Filled Oval and Its Box x, y width heightheight

May 11, 1998CS102-02Lecture 7-1 Drawing Arcs Draws the outline of a circular or elliptical arc covering the specified rectangle (filled arcs too) startAngle arcAngle + startAngle

May 11, 1998CS102-02Lecture 7-1 Arc Parameters Resulting arc begins at startAngle and extends for arcAngle degrees, using the current color –Angles are interpreted such that 0 degrees is at the 3 o'clock position –Positive value indicates a counter- clockwise rotation while a negative value indicates a clockwise rotation

May 11, 1998CS102-02Lecture 7-1 More Arc Parameters Center of the arc is the center of the rectangle whose origin is (x, y) Size is specified by the width and height arguments Resulting arc covers an area width + 1 pixels wide by height + 1 pixels tall