Graphics & Java 2D Drawing Two Dimensional Shapes Controlling Fonts Controlling Colors.

Slides:



Advertisements
Similar presentations
Custom Painting Gestione della Grafica customizzata Vedi anche:
Advertisements

Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: 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.
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 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.
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.
Building Java Programs Supplement 3G Graphics Copyright (c) Pearson All rights reserved.
Copyright 2008 by Pearson Education Building Java Programs Graphics Reading: Supplement 3G.
©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™
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
2D Graphics in Java COMP53 Nov 14, Applets and Applications Java applications are stand-alone programs – start execution with main() – runs in JVM.
A Simple Applet --- Digital Clock import java.awt.*; import java.util.Calendar; public class DigitalColok extends java.applet.Applet implements Runnable.
Copyright 2008 by Pearson Education Building Java Programs Graphics reading: Supplement 3G videos: Ch. 3G #1-2.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 5 Java Graphics Applets.
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
Topics AWT Classes Window Fundamentals Working with Frame Windows Creating a Frame Window in an Applet Creating a Windowed Program Displaying Information.
1 Drawing Shapes and Text With Applets. 2 Drawing in the paint method import java.awt.*;// access the Graphics object import javax.swing.*;// access to.
1 Graphical objects We will draw graphics in Java using 3 kinds of objects: DrawingPanel : A window on the screen. Not part of Java; provided by the authors.
Graphics. Graphics Features in Java Topics to be covered Topics to be covered Graphics Basics Graphics Basics Coordinate System Coordinate System Graphics,
Agenda For Feb Finish up Unit 3 Exercises on page Unit 4 Exercises on page 33. Question #2 3. Create a Happy Face Java Applet (due next class).
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.
Applets CS 3331 Sections 3.3 & 4.7 of [Jia03].
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.
Line Graphics Summary 1.drawLine(xStart, yStart, xEnd, yEnd); 2.drawRect(x, y, width, height); 3.drawRoundRect(x, y, width, height, cornerWidth, cornerHeight);
Copyright 2010 by Pearson Education Building Java Programs Graphics reading: Supplement 3G.
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.
Lecture 15: Intro to Graphics Yoni Fridman 7/25/01 7/25/01.
Applets & Graphics. Applets programs that run inside a browser Java platform-independence makes applets possible security restrictions: –cannot read or.
Chapter 7 Graphics. © Daly and Wrigley Objectives Use Graphic Components: ▫ Strings ▫ Lines ▫ Rectangles ▫ Ovals ▫ Arcs Change the color and font of elements.
Graphics Copyright © 2015 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved. Java Methods Object-Oriented Programming and Data.
1 Building Java Programs Supplement 3G: Graphics These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may not be rehosted, sold,
(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.
(c)2006 E.S.Boese All Rights Reserved.1 Drawing Shapes and Text Chapter 2 – Lecture Slides.
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.
Building Java Programs Graphics Reading: Supplement 3G.
Introduction to Graphics. Graphical objects To draw pictures, we will use three classes of objects: –DrawingPanel : A window on the screen. –Graphics.
Copyright 2008 by Pearson Education Building Java Programs Graphics reading: Supplement 3G videos: Ch. 3G #1-2.
12 Graphics and Java 2D™.
Chapter 8 Graphics.
Graphics Chapter 6 Copyright © 2000 W. W. Norton & Company.
Java Applets.
JAVA 2 Design and programming of GUI
Chapter 10 Graphics.
Basic Graphics Drawing Shapes 1.
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™.
Java Applets.
HSB Hue-Saturation-Brightness
Chapter 8 Graphics.
Presentation transcript:

Graphics & Java 2D Drawing Two Dimensional Shapes Controlling Fonts Controlling Colors

Java’s Coordinate System The upper-left coordinate (0,0) is behind the title bar of the window. Drawing coordinates should be adjusted to draw inside the borders of a window Java’s Container Class (superclass of all windows in Java) has method getInsets() that determine the drawing area for a window.

Color Control Constants ( ORANGE, PINK, CYAN, MAGENTA, YELLOW, BLACK, WHITE, GRAY, RED, GREEN, BLUE ) Example –g.setColor(Color.MAGENTA); RGB (Red Green Blue Values) –0 to 255 ( 0 no color, 255 full color) –0.0 to 1.0 Example –g.setColor(new Color(255, 0,0)); –g.setColor (new Color (0.0f, 1.0f, 0.0f)

Font Control Java Font Styles (PLAIN, BOLD, ITALIC) Java Fonts –Serif (Times) –Monospaced (Courier) –SanSerif (Helvetica) Examples: –g.setFont(new Font (“Serif”, Font.BOLD, 12)); –g.setFont(new Font(“Monospaced”, Font.ITALIC + Font.BOLD, 24)

Drawing Lines, Rectangles, Ovals Basic Drawing Methods –drawLine (x1, y1, x2, y2) –drawRect (x, y, width, height) –drawOval (x, y, width, height) (x,y) is top-left corner of bounding box of oval Fill Shapes –Call setColor method before filling shapes –fillRect (x, y, width,height) –fillOval(x, y, width, height)

Drawing Polygons and Polylines Polygons -Closed multisided shapes consisting of straight line segments Polylines – a sequence of connected points.

Drawing Polygons and Polylines Graphics Methods for drawing Polygons drawPolygon( int xValues[], int yValues[], int numPoints) drawPolyline (int xValues[], int yValues[], int numPoints) fillPolygon (int xValues[], int yValues[], int numPoints) Example: int xValues[] = {20,30,40}; int yValues[] = {50,50, 60}; g.drawPolygon (xValues, yValues, 3); g.drawPolyline (xValeus, yValues, 3);

Drawing Polygons and Polylines Graphics Methods for drawing Polygons drawPolygon(Polygon p) fillPolygon (Polygon p) Polygon Constructors and Methods Polygon() – creates a new polygon that does not contain any points addPoint (int x, int y) – adds point to polygon Polygon (int xValues[], int yValues[], int numPoints) int xValues[] = {20,30,40}; int yValues[] = {50,50, 60}; Polygon p = new Polygon (xValues, yValues, 3); p.addPoint(30,80); g.fillPolygon (p);