1 Graphical User Components (II) Outline JTextArea Creating a Customized Subclass of JPanel JPanel Subclass that Handles Its Own Events Windows: Additional.

Slides:



Advertisements
Similar presentations
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.
Advertisements

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?
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.
©2004 Brooks/Cole Applets Graphics & GUIs. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Graphical Programs Most applications these days are.
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. Topics  Applets  Classes used for graphics Graphics Point Dimension.
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™
Slides prepared by Rose Williams, Binghamton University Chapter 19 Swing II.
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.
 2003 Prentice Hall, Inc. All rights reserved. 1 Outline 12.1 Introduction 12.2 Graphics Contexts and Graphics Objects 12.3 Color Control 12.4 Font Control.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
Swing Graphics ● Empty Swing containers have no visual appearance except for a background color ● Every JComponent must have a paintComponent method that.
Graphics and Multimedia. Introduction The language contains many sophisticated drawing capabilities as part of namespace System.Drawing and the other.
 2003 Prentice Hall, Inc. All rights reserved. Outline 12.1 Introduction 12.2 Graphics Contexts and Graphics Objects 12.3 Color Control 12.4 Font Control.
Chapter 16: Graphics. Objectives Learn about the paint() and repaint() methods Use the drawString() method to draw String s using various fonts and colors.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
Java Software Solutions Lewis and Loftus Chapter 7 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphics -- Introduction The.
Chapter 11 - Graphics and Java 2D Outline 11.1 Introduction 11.2 Graphics Contexts and Graphics Objects 11.3 Color Control 11.4 Font Control 11.5 Drawing.
Modernās Programmēšanas Tehnoloģijas (Advanced Programming Technologies) Edgars Celms, Mārtiņš Opmanis Latvijas Universitātes Matemātikas.
 2002 Prentice Hall, Inc. All rights reserved. Chapter 11 - Graphics and Java 2D Outline 11.1 Introduction 11.2 Graphics Contexts and Graphics Objects.
(C) 2010 Pearson Education, Inc. All rights reserved. Omer Boyaci.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
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.
Java Graphics Swing 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.
10/24/20151 Java GUI Programming. 10/24/20152 What is a GUI? Java has standard packages for creating custom Graphical User Interfaces Some of the fundamental.
Chapter 7 Graphics. © Daly and Wrigley Objectives Use Graphic Components: ▫ Strings ▫ Lines ▫ Rectangles ▫ Ovals ▫ Arcs Change the color and font of elements.
J McQuillan SE204: 2004/2005: Lecture 4slide 1 The Graphics Class Used when we need to draw to the screen Two graphics classes –Graphics –Graphics2D.
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.
Java Graphics. Review 3 kinds of elements in components API? Layout managers Events Extend vs. Implement.
(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.
Introduction to Java Chapter 8 - Introduction to Java Graphics1 Chapter 8 Introduction to Java Graphics.
Graphics and Java2D Chapter Java Coordinate System Origin is in _____________ corner –Behind title bar of window X values increase to the ________.
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Getting Started with GUI Programming Chapter 10 CSCI 1302.
Graphics in Java Opening Discussion zDo you have any questions about the quiz? zWhat did we talk about last class? zDo you have any questions.
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,
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.
12 Graphics and Java 2D™.
Chapter 8 Graphics.
Graphics Chapter 6 Copyright © 2000 W. W. Norton & Company.
Java Graphics CS 2511.
Basic Graphics Chapter 5 3/19/15 Thursday Section Only
JAVA 2 Design and programming of GUI
Chapter 13: Advanced GUIs and Graphics
Chapter 10 Graphics.
4.14 GUI and Graphics Case Study: Creating Simple Drawings (Cont.)
Graphics -- Introduction
12 Graphics and Java 2D™.
Chapter 8 Graphics.
Chapter 12 - Graphics and Java 2D
Presentation transcript:

1 Graphical User Components (II) Outline JTextArea Creating a Customized Subclass of JPanel JPanel Subclass that Handles Its Own Events Windows: Additional Notes Using Menus with Frames

2 JTextArea –Area for manipulating multiple lines of text –extends JTextComponent..\..\..\212-winter-2005\week11\textarea_18

3 Creating a Customized Subclass of JPanel Extend JPanel to create new components –Dedicated drawing area Method paintComponent of class JComponent..\..\week11\panel_demo_17

4 Windows: Additional Notes JFrame –Windows with title bar and border –Subclass of java.awt.Frame Subclass of java.awt.Window –Heavyweight component –Three operations when user closes window DISPOSE_ON_CLOSE DO_NOTHING_ON_CLOSE HIDE_ON_CLOSE

5 Using Menus with Frames Menus –Allows for performing actions with cluttering GUI –Contained by menu bar JMenuBar –Comprised of menu items JMenuItem..\..\week12\Menu_1

6 Introduction Graphics Contexts and Graphics Objects Color Control Font Control Drawing Lines, Rectangles and Ovals Drawing Arcs Drawing Polygons and Polylines Graphics and Java 2D

Introduction Java’s graphics capabilities –Drawing 2D shapes –Controlling colors –Controlling fonts Java 2D API –More sophisticated graphics capabilities Drawing custom 2D shapes Filling shapes with colors and patterns

8 Classes and interfaces used in this chapter from Java’s original graphics capabilities and from the Java2D API. Classes and interfaces from the Java2D API that appear in package java.awt Object Color Component Font FontMetrics Graphics Polygon Graphics2D interface java.awt.Paint interface java.awt.Shape interface java.awt.Stroke Classes from the Java2D API that appear in package java.awt.geom GradientPaint BasicStroke TexturePaint RectangularShape GeneralPath Line2D RoundRectangle2D Arc2D Ellipse2D Rectangle2D

9 Introduction Java’s coordinate system –Scheme for identifying all points on screen –Upper-left corner has coordinates (0,0) –Coordinate point composed of x-coordinate and y-coordinate

10 Java coordinate system. Units are measured in pixels

11 Graphics Contexts and Graphics Objects Graphics context –Enables drawing on screen –Graphics object manages graphics context Controls how information is drawn –Class Graphics is abstract Cannot be instantiated Contributes to Java’s portability –Class Component method paint takes Graphics object public void paint( Graphics g ) –Called through method repaint

12 Color Control Class Color –Defines methods and constants for manipulating colors –Colors are created from red, green and blue components RGB values

13 Color constants and their RGB values

14 Color methods and color-related Graphics methods..\..\week12\Color_2..\..\week12\Color_3

15 Font Control Class Font –Contains methods and constants for font control –Font constructor takes three arguments Font name –Monospaced, SansSerif, Serif, etc. Font style –Font.PLAIN, Font.ITALIC and Font.BOLD Font size –Measured in points (1/72 of inch)

16 Font -related methods and constants

17 Font -related methods and constants..\..\week12\Fond_4

18 Font Control Font metrics –Height –Descent (amount character dips below baseline) –Ascent (amount character rises above baseline) –Leading (difference between descent and ascent)

19 Font metrics

20 FontMetrics and Graphics methods for obtaining font metrics..\..\week12\FontMetrics_5

21 Drawing Lines, Rectangles and Ovals Class Graphics –Provides methods for drawing lines, rectangles and ovals All drawing methods require parameters width and height

22 Graphics methods that draw lines, rectangles and ovals

23 Graphics methods that draw lines, rectangles and ovals..\..\week12\Lines_6

24 Arc width and arc height for rounded rectangles

25 Oval bounded by a rectangle

26 Drawing Arcs Arc –Portion of oval –Measured in degrees –Sweeps the number of degrees in arc angle –Sweep starts at starting angle Counterclockwise sweep is measure in positive degrees Clockwise sweep is measure in negative degrees

27 Positive and negative arc angles 90° 0°180° 270° 90° 0°180° 270° Positive anglesNegative angles

28 Graphics methods for drawing arcs..\..\week12\Arc_7

29 Drawing Polygons and Polylines Class Polygon –Polygons Multisided shapes –Polylines Series of connected points

30 Graphics methods for drawing polygons and class Polygon methods

31 Graphics methods for drawing polygons and class Polygon methods..\..\week12\Polygons_8

Java2D API Java 2D API –Provides advanced 2D graphics capabilities java.awt java.awt.image java.awt.color java.awt.font java.awt.geom java.awt.print java.awt.image.renderable –Uses class java.awt.Graphics2D Extends class java.awt.Graphics