Java Reference
In-Depth Information
thus making things look more hip or modern. As you begin to create the media player,
you'll notice in the start() method that you prepare the Stage object by initializ-
ing the style using StageStyle.TRANSPARENT . After you initialize the style to
StageStyle.TRANSPARENT , the window will be undecorated, with the entire win-
dow area's opaque value set to zero (invisible). The following code shows you how to
create a transparent window without a title bar or windowed borders:
primaryStage.initStyle(StageStyle.TRANSPARENT);
With the invisible stage, you create a rounded rectangular region that will be the ap-
plication's surface or main content area. Next, notice the width and height of the rect-
angle bound to the scene object in case the window is resized. Because the window
isn't going to be resized, the bind isn't necessary (it will be needed, however, in Recipe
16-2, when you get a chance to enlarge your video screen to take on a full-screen
mode).
After creating a black, semitransparent, rounded rectangular area ( applica-
tionArea ), you'll be creating a simple Group object to hold all the randomly
colored Circle nodes that will show off graphical visualizations while the audio is
being played. Later, you will see how the phaseNodes ( Group ) variable is updated
based on sound information using an AudioSpectrumListener .
Next, you add EventHandler<MouseEvent> instances to the Scene object
(the example uses lambda expressions) to monitor mouse events as the user drags the
window around the screen. The first event in this scenario is a mouse press, which will
save the cursor's current (X, Y) coordinates to the variable anchorPt . The following
code is adding an EventHandler to the mouse-press property of the Scene :
// starting initial anchor point
scene.setOnMousePressed((MouseEvent event) -> {
anchorPt = new Point2D(event.getScreenX(),
event.getScreenY());
});
After implementing the mouse-press event handler, you can create an
EventHandler to the Scene 's mouse-drag property. The mouse-drag event handler
will update and position the application window ( Stage ) dynamically, based on the
previous window's location (upper-left corner) along with the anchorPt variable.
Shown here is an event handler responsible for the mouse-drag event on the Scene
object:
Search WWH ::




Custom Search