lecture17

lecture17 - PIC 20A Lecture 17: Colors, Fonts, Applets...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
PIC 20A Lecture 17: Colors, Fonts, Applets
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Colors • modeled by the java.awt.Color class • can define a color by specifying an RGB value (Red, Green, Blue) • every color can be represented uniquely as combination of these primary colors • each primary color component gets a weight from 0 to 1, with 1 being the highest amount of that color present • no set methods in class Color to change the characteristics of the current color
Background image of page 2
Color Examples Color red = new Color(1.0F, 0.0F, 0.0F); Color green = new Color(0.0F, 1.0F, 0.0F); Color blue = new Color(0.0F, 0.0F, 1.0F); Color black = new Color(0.0F, 0.0F, 0.0F); Color white = new Color(1.0F, 1.0F, 1.0F); • must use the suffix F to identify the decimal as a float
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Color static constants • Predefined colors exist as public static constants of the Color class Eg R G B Color.CYAN 0 1 1 Color.MAGENTA 1 0 1 Color.YELLOW 1 1 0 Color.ORANGE 1 0.8 1 Color.PINK 1 0.7 0.7 Color.GRAY .5 .5 .5
Background image of page 4
How to draw with colors • use the setColor() method of the Graphics object • black is the default color // setting the brush color to magenta g.setColor(new Color(1.0F, 0.0F, 1.0F)); // draw a string in magenta g.drawString(“Magenta is cool”, 25, 25);
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/12/2010 for the course PIC PIC 20A taught by Professor Keithouellette during the Spring '09 term at UCLA.

Page1 / 22

lecture17 - PIC 20A Lecture 17: Colors, Fonts, Applets...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online