go to previous page   go to home page   go to next page highlighting

Answer:

Color.TRANSPARENT

This color is needed if you want an open figure, just the perimeter of a circle, for example. The default fill color for most Shapes in JavaFX is Color.BLACK. The default stroke color is null (no color).


RGB

Overlapping colored circles.

If you want more control over the color, use

new Color(double red, double green, double blue, double opacity) 

This creates a color with the specified red, green, blue, and opacity values in the range (0.0 to 1.0). A color value of 0.0 corresponds to none of that color. A color value of 1.0 corresponds to the maximum amount of that color. All the colors a monitor can produce are made by mixing various values for these three colors.

The opacity of a color determines how much of an underlying color is allowed to show through. An opacity of 1.0 allows none of the underlying color to show through. An opacity of 0.5 allows half of the underlying color to show through. And an opacity of 0.0 is completely transparent. The predefined colors have opacity 1.0.

The values for Red, Green, and Blue are often called RGB values. The values for Red, Green, Blue, and opacity are often called RGBA values. Here, the "A" stands for "Alpha," which is another name for the opacity.

There are many other means in this class for creating a custom color.

Here is the previous program modified to display two overlapping circles. The opacity of the fill colors is set to 0.5 so where the circles overlap the color is an even mix.

import javafx.application.*;  
import javafx.stage.*;        
import javafx.scene.Scene;   
import javafx.scene.shape.*; 
import javafx.scene.paint.*;  
import javafx.scene.layout.*;

public class CircleOverlap extends Application  
{
  public void start( Stage primaryStage ) 
  {
    Circle circleA = new Circle( 75.0, 75.0, 50.0 ); 
    circle.setFill( new Color( 0.0, 1.0, 0.0, 0.5 ) );  // Red-Green-Blue-Opacity
    circle.setStroke( Color.BLACK );

    Circle circleB = new Circle( 150.0, 75.0, 50.0 ); 
    circle.setFill( new Color( 0.0, 0.0, 1.0, 0.5 ) );  // Red-Green-Blue-Opacity
    circle.setStroke( Color.BLACK );
    
    Pane pane = new pane( circleA, circleB );  
    Scene scene = new Scene( pane, 300.0, 200.0, Color.LIGHTYELLOW ); 
    
    primaryStage.setTitle("Overlapping Circles");
    primaryStage.setScene( scene );   
    primaryStage.show();
  }
}

You can create a Color as a separate object and use it for each of several graphics objects:

   
    Color  myGreen = new Color( 0.2, 0.89, 0.2, 0.75 );
    Color  myBlue  = new Color( 0.1, 0.3, 0.8, 0.85 );
    
    Circle circleA = new Circle( 75.0, 75.0, 50.0 ); 
    circleA.setFill(  myGreen );   
    circleA.setStroke( myBlue );

    Circle circleB = new Circle( 150.0, 75.0, 50.0 ); 
    circleB.setFill(  myGreen );  
    circleB.setStroke( myBlue );

A Color object is immutable. Once it has been created, it can't be changed.

Java throws an Exception if you try to construct a Color with a RGB value out of range (less than zero or more than one).


QUESTION 11:

What RGB values correspond to Color.WHITE ?

Color myWhite = new Color( , , , );

What RGB values correspond to Color.BLACK ?

Color myBlack = new Color( , , , );

Make the above colors totally opaque.


go to previous page   go to home page   go to next page