Lecture 5B
  Applets 1
  Applets 2
  More Drawing
  Colors
  Fonts
  Images
  Reduce Flicker:
    
Override Update
  
 Clipping
  
 Double Buffer
  Exercises

Lectures

1A: Introduction
1B: Java Intro
2A: BuildingBlocks
2B: Objects
3A: More Objects
3B: Exceptions
       & Threads
4A: Waves
4B: Nuclear &
       Particle
5A: AWT
5B: More AWT
      & Graphics
6A:Detectors &
      Simulation
6B: LHC/Atlas &
     RandomSims    
7A: Swing
7B: Java2D
8A: Java Apps
8B: Dialogs &
    MoreClasses
9A: Java I/O
9B: Utilities,
        Unicode
10A: More
    Threading
10B: File
    Handling
11A: Array,Print,
    Images
11B: SimplePhysics
    Simulation
12A: Tips &
    Techniques
12B: More Tips &
    Techniques
13A: Satellite
    
Simulations
13B: Intro to Java
    Networking
14A: Java Servers
14B: HTTP Server
15A: ServerClient
15B: ServerClient
   Expt.Simulation
16A: Course
          Review
16B: ExerciseTest
        Discussion

    Contacts
    Description
    Exercises
    Index
    Outline
    Q&A
    Resources
    StudentInfoForm
    Student Pages
    What's New

 

Home : Lectures : Lecture 5B : Colors
Colors

Colors are defined by the class

java.awt.Color

RGB, with an alpha transparency factor, is the default colorspace.

Specify a color, for example, in one of the constructors with either int 0-255, or float 0.0-1.0:

Color red = new Color( 0xFF,0,0); // R,G,B
Color blue = new Color(0.0,0.0,1.0);// R,G,B

For convenience, several colors are available as Class constants, e.g. Color.blue,Color.white, etc.

To set the current drawing color in the graphics context:

   g.setColor(Color c);//g = Graphics object

The background and foreground colors of components, e.g. a panel, can be set with

  setBackground(Color c);
  setForeground(Color c);

Similarly, "getter" methods are paired with these methods to obtain the colors:

  Color c = g.getColor();//g = Graphics object

  // In an applet or other Component object:
  Color bg = getBackground();
  Color fg = getForeground();

 

Home Lectures Resources Index Contacts Students


Physics Simulations with JavaTM
KTH, Kurskod: 5A1418
Curator: Clark S. Lindsey