Graphics in Java 3-27-2003. Opening Discussion zDo you have any questions about the quiz? zWhat did we talk about last class? zDo you have any questions.

Slides:



Advertisements
Similar presentations
Principle 7: Design for Responsiveness You want the interface to be fast (but not too fast). Sub-second response time is the norm, but if things happen.
Advertisements

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.
Lecture 3 A First Graphic Program. Features of a simple graphic program.
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
1 L36 Graphics and Java 2D™ (1). 2 OBJECTIVES  To understand graphics contexts and graphics objects.  To understand and be able to manipulate colors.
Chapter Day 5. © 2007 Pearson Addison-Wesley. All rights reserved2-2 Agenda Day 5 Questions from last Class?? Problem set 1 Posted  Introduction on developing.
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.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L01 (Chapter 13) Graphics.
ObjectDraw and Objects Early Chris Nevison Barbara Wells.
DrawingPaint What is DrawingPaint ? DrawingPaint operations. What are benefits of DrawingPaint ? Jason Hoang June 2, 2005.
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.
Slide Transitions Slide Show, Slide Transition opens Slide Transition task pane Practice each option setting to select the transition style, its speed,
CS 112 GUI 06 May 2008 Bilkent. Java GUI API Containers: ◦ contain other GUI components. E.g, Window, Panel, Applet, Frame Dialog. Components: ◦ Buttons,
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.
Java Applets. Applets The term Applet refers to a little application. In JAVA the applet is a java program that is embedded within a HTML document and.
Web Design & Development Lecture 18. Java Graphics.
1 Interface Types & Polymorphism & introduction to graphics programming in Java.
1 Graphical User Components (II) Outline JTextArea Creating a Customized Subclass of JPanel JPanel Subclass that Handles Its Own Events Windows: Additional.
METHODS AND SCOPE CSCE More on Methods  This is chapter 6 in Small Java.
Learn about the types of Graphics that are available Develop a basic Graphics applet Develop a basic Graphics application Review the Java API and use.
Chapter 15 Graphics and Java 2D™ Java How to Program, 8/e (C) 2010 Pearson Education, Inc. All rights reserved.
 Pearson Education, Inc. All rights reserved. 1 Ch 12 Graphics and Java 2D In this chapter you will learn:  To understand graphics contexts.
String Processing Opening Discussion zDo you have any questions about the quiz? zWhat did we talk about last class? zDo you have questions.
Graphics and Java 2D. 2 Introduction Java’s graphics capabilities –Drawing 2D shapes –Controlling colors –Controlling fonts Java 2D API –More sophisticated.
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 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.
-Sai Phalgun Tatavarthy. Outline What is a “Graphing Calculator”? Graphics, Graphics2D classes Methods of Graphics object Custom Painting The paintComponent()
Java Graphics Stuart Hansen 11/6/03. What’s Wrong with OpenGL Graphics – not GUI –No real support of text boxes, buttons, etc. Procedural - not OOP –No.
Chapter 2: Color and Applets Coming up: Introduction to Graphics.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
GUIs in Java Opening Discussion zHow did the project work out? How did you decide to tackle the problem? What pieces did you break it into?
Recursion Opening Discussion zWhat did we talk about last class? zDo you have any questions about the assignment? Don’t let problems hang.
Android Graphics Library. Color Android colors are represented with four numbers, one each for alpha, red, green, and blue (ARGB). Each component can.
Creating Your Own Widgets CompSci 230 S Software Construction.
(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.
Java.  In java you can paint your own custom drawing (such as graphs, charts, drawings and, in particular, computer games) because you cannot find standard.
1 GUIs, Layout, Drawing Rick Mercer. 2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces (GUIs)
Graphics Concepts CS 2302, Fall /17/20142 Drawing in Android.
Java Dynamic Graphics.
Graphics and Java2D Chapter Java Coordinate System Origin is in _____________ corner –Behind title bar of window X values increase to the ________.
Java Graphics Opening Discussion zWhat did we talk about last class? zDo you have any questions about the assignment? zOffset between class.
1 Introduction to Graphics b The last one or two sections of each chapter of the textbook focus on graphical issues b Most computer programs have graphical.
Red-Black Trees Opening Discussion zDo you have any questions about the quiz? zWhat did we talk about last class? zDo you have any questions.
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Java Graphics Chris North cs3724: HCI. Presentations peter hou Vote: UI Hall of Fame/Shame?
C Sc 335 Object-Oriented Programming and Design Rick Mercer
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.
Advanced AWT The Rendering Pipeline
12 Graphics and Java 2D™.
Creating Your Own Widgets
Chapter 8 Graphics.
Java Graphics.
Java Graphics CS 2511.
Java Applets.
Basic Graphics Chapter 5 3/19/15 Thursday Section Only
Chapter 10 Graphics.
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.)
Java Applets.
Chapter 8 Graphics.
Presentation transcript:

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 about the assignment?

Drawing on Your Own zSometimes you want to have more control than just using the GUI components provided by the Java libraries. In these situations you might want to have custom control over what gets drawn to the space inhabited by a given component. zThe power and quality of this was enhanced with the Graphics 2D library in Swing.

Overriding the paint Method zThe way that you can control what is drawn on a component is to override the paint method of that component (for Swing use paintComponent). This means that you need to create a subclass of a component. I typically do custom components from JPanels. zThe paint method takes a java.awt.Graphics object. What you draw with that object shows up on the Component.

The Graphics Class zThe Graphics class encapsulates basic drawing operations with the data that tells how they should be drawn. zThere are methods to draw, or fill, basic shapes (lines, ovals, rectangles, polygons) as well as images and strings. zA variety of set methods tell it how to draw those things.

The Graphics2D Class zIf you are using Swing, the Graphics object will actually be an instance of Graphics2D. We’ll talk more about the power of this next class, but with it, you will typically draw with the draw(Shape s) and fill(Shape s) methods. zShape is very powerful and flexible, but they provide some standard shapes in the java.awt.geom package.

Clipping zThe process of clipping is really setting what part of a surface you will draw to. You can set a rectangular region or a shape and anything that would be drawn outside of that region doesn’t get drawn. zNormally the clipping region is set to be the size of the component. You can set it smaller to make sure things are located to a smaller region.

Colors zYou can set what color to draw with. The way you do this is by giving the Graphics object a Color object. With Graphics2D you should instead use setPaint. Color is a subclass of Paint. zThere are a number of predefined Color object for standard colors. You can also define arbitrary colors using constructors that take red, green, and blue values.

Fonts zYou can also set what font you want the Graphics object to use when you draw text to it. zThe potential complexity rises a fair bit here, but you can easily create Font objects by providing a standard font name, style, and size (see API for details). zFinding the size of the strings drawn in the given font requires using LineMetrics objects.

Code zLet’s look at and write some code to create a JPanel that does custom drawing and has some type of interaction with the user.

More Advanced Graphics zNext class we will continue to discuss the more advanced features of Java2D. zThere is also an option Java package called Java3D that allows you to do 3D graphics fairly easily. You can look on the web for details though teaching it is beyond the scope of this class. It also makes code less portable because it is not standard and required either OpenGL or DirectX to run.

Minute Essay zWhat did we talk about today? What do you think about the project and how it is going so far? Is having the large project helping or hindering your ability to learn about object-orientation? zThere will be an open lab today, but we will have to leave for a while at 4:30 for a department meeting.