Java Reference
In-Depth Information
Scene scene = new Scene(root);
return scene;
}
public static void main(String[] args) {
launch(args);
}
}
This program loads the EarthRise
Image
from a URL, and puts it and a
TextArea
into the scene, and then obtains
a
PixelReader
from it. Every time the mouse is clicked on the image, the color of the pixel is appended to the
text
in the
TextArea
. When the program in Listing 10-13 is run, after a few clicks on the image, the ImageOps Example
window in Figure
10-16
is displayed.
Figure 10-16.
The ImageOpsExample program
The program in Listing 10-14 creates a
WritableImage
, draws the Mandelbrot set on it, then draws the image onto
a
Canvas
, and finally puts the
Canvas
in a scene. The drawing of the Mandelbrot set is done by calculating the color of
each pixel and setting the color for the pixel.
Listing 10-14.
MandelbrotSetExample.java
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.PixelWriter;
import javafx.scene.image.WritableImage;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
Search WWH ::
Custom Search