Unformatted text preview:

Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 81Java2D Graphics3/19/20092Opening Discussion■Let's look at solutions to the interclass problem.■Making a linked list in C.■Think of an iterator as an object that encapsulates the elements you need to make a for loop.■Do you have any questions about the assignment?■Do you have any questions about the reading?3Graphics in Java■You can do lots of things with the standard GUI elements in Swing. We've been able to set up quite a bit of a GUI using that. However, no GUI can predict everything that you will want to do and we want to be able to add custom drawing to our application.■For this we will rely on the Java2D library. Java2D was added about the same time Swing was and it is fundamentally based on the Graphics2D class. There is also a Graphics class that provides more basic custom graphics capabilities. Graphics2D inherits from Graphics so it can do all the same things and more.4Making Custom Drawn Components■There are three steps to making a component class that we can do custom drawing to.Make a new class and have it inherit from JComponent or a subtype of it. We'll use JPanel.Override the paintComponent method in your class.Draw with the Graphics object that was passed into the paintComponent method.■Let's look a bit at the Graphics2D class to see what some of the possibilities might be for what we can draw.■Now we can do these steps in our program to make a central panel we can draw to.5Settings■There are several things that we can set on the Graphics2D object that are used when we draw things. Here are some:Paint – could be a color, but there are also gradients and texturesStroke – determines how lines are drawnFont – how you want text to appearTransform – AffineTransform allows translate, rotate, scale, or shearComposite – how colors combine when you draw over old stuffClip – where your drawings will appearRender hints – other things like antialiasing6More General Drawing■Of course, Graphics2D objects aren't limited to just drawing on components.■The Image class (and it's subtype BufferedImage) will let you get Graphics objects that you can draw to and what you draw will be on the image.■We'll typically do this even if we are drawing to a component to implement buffering which reduces flicker.7Coding■Let's play with our panel some to experiment with the drawing options.8Minute Essay■What do you think we should try adding to our drawing program given that we now know how to draw?■Interclass Problem – Write a simple drawing program similar to Paint. Use buttons for selecting at least rectangles, ellipses, and lines. Use the mouse to draw things. Have color options with


View Full Document

TRINITY CSCI 1321 - Java 2D Graphics

Documents in this Course
Recursion

Recursion

11 pages

Iterators

Iterators

10 pages

Actors

Actors

9 pages

Recursion

Recursion

15 pages

Recursion

Recursion

10 pages

Threads

Threads

7 pages

Trees

Trees

11 pages

Load more
Download Java 2D Graphics
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Java 2D Graphics and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Java 2D Graphics 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?