Docsity

Java GUIs and Color: AWT, Swing, Java2D, and RGB - Prof. Douglas J. Wokoun, Quizzes of Computer Science

Partial preview of the text

Download Java GUIs and Color: AWT, Swing, Java2D, and RGB - Prof. Douglas J. Wokoun and more Quizzes Computer Science in PDF only on Docsity!

CS251 Intermediate Programming

Lecture 9

GUIs

  • Quiz 2 Wednesday on object orientation

User Interfaces in Java

Thearen't used much anymore.collection of widgets (buttons, scroll bars, sliders, etc.) thatwith mouse events, keyboard events, and others; and aoperating system's windowing system; classes for dealingAWT contains classes for interacting with the hostfoundational graphics framework for Java.AWT is the Java Abstract Window Toolkit, which is theGUIs in Java: AWT, Swing, and Java2D. We’ll be talking about three related frameworks for doing

(^) java.awt

(^) package and sub-packages make up the AWT.

User Interfaces in Java (3)

Thequality.operating system can employ tricks to enhance graphicsJava2D is based on a real number coordinate system, so thetransformations that can be done to them. Java2D is a system for describing shapes, images, and (^) java.awt.geom

(^) package and several others make up

Java2D.

Color

the visible spectrum. In Physics, color is associated with a certain wavelength on Yellow light is EM radiation at about 600nm wavelength.

three cone types are stimulated by the light.The human eye perceives color by the degree to which thesensitive to a different range of the color spectrum.The human eye has three types of cone cells that are each blue cones is seen as yellow.Light that stimulates the red and green cones but not the

400nm

500nm

600nm



700nm



violet

blue

cyan

green

yellow

red

Color (3)

 color that can be displayed onscreen.are levels of red, green, and blue light, you get the "universe" ofIf you construct a three-dimensional space where the axesalmost all of the visible spectrum can be simulated.^ By emitting differing ratios of red, blue, and green light, 400nm

500nm

600nm



700nm



violet

blue

cyan

green

yellow

red

This shows the color values of the corners of the colorspace.

+r

+g

+b

(0,0,0) (1,1,1)

Magenta (Red + Blue)

Yellow (Red + Green)

(Green + Blue) Cyan

(1,0,1)

(1,1,0)

(0,1,1)

(0,0,1) Blue

(0,1,0) Green White

Black

(1,0,0) Red

( 0.5 component is half way bet ween the minimum and the maximumThis is another slice of the colorspace, taken where the blue

).

+r

+g

+b

(1,1,1)

(1,0,1)

(1,1,0)

(0,1,1)

(0,0,1) Blue

(0,1,0) Green White

PurpleGray

(1,0,0) Red

Magenta (Red + Blue)

Yellow (Red + Green)

(Green + Blue) Cyan

at its maximum (This is a slice of the colorspace taken where the blue component is

1.

).

+r

+g

+b

(1,1,1)

(1,0,1)

(1,1,0)

(0,1,1)

(0,0,1) Blue

(0,1,0) Green White

(1,0,0) Red

Magenta (Red + Blue)

Yellow (Red + Green)

(Green + Blue) Cyan

gray.components have the same value, the resulting color is a shade ofthe color saturation (makes it more gray). When all 3Moving the 3 color components closer together in value reduces R

G B = R G B =

color.Altering the ratio of the color components changes the hue of the R

G B = R G B =

g

α (^) = 0.

α (^) = 0.

α (^) = 0.

α (^) = 0.

α (^) = 1.

Color in Java

The class

(^) java.awt.Color

(^) allows you to de

fine a color to use

You construct afor painting shapes.

(^) Color

(^) object with RGB or RGBA parameters,

or use one of the prede

fined colors.

Each component can be speciyields a 32-bit color value.limits of human perception). The addition of alpha (8-bits)24-bits of color or 16,777,216 colors (generally beyond theeach of the red, green, and blue components, for a total ofMost modern display hardware supports 8-bit parameters for

fied as a fraction of full

intensity (

0.0f

(^) - (^) 1.0f

) or as an 8-bit unsigned value (

(^0)

255

).

are usually positive numbers.from standard mathematical coordinates. Graphics coordinatesof CRTs (left-to-right, top-to-bottom) and have a Y-axis invertedCoordinates in computer graphics are based on the raster pattern

+x

+y

+x

+y

-y

-x

(20.0,10.0)

(20.0,10.0)

Math

Computer Graphics

Here are the coordinates of a line drawn bet ween t wo points.

g

+x

+y (20.0,10.0)

(70.0,30.0)