Java Reference
In-Depth Information
changeFillButton = new Button("Change Fill");
changeStrokeButton = new Button("Change Stroke");
buttonHBox = new HBox(10, changeFillButton, changeStrokeButton);
buttonHBox.setPadding(new Insets(10, 10, 10, 10));
buttonHBox.setAlignment(Pos.CENTER);
BorderPane root = new BorderPane(rectangle, null, null, buttonHBox, null);
root.setPadding(new Insets(10, 10, 10, 10));
scene = new Scene(root);
}
}
}
This class stands up a simple UI with a rectangle with a pronounced Color.DARKGRAY stroke and a Color.LIGHTGRAY
fill in the center of a BorderPane , and two buttons at the bottom labeled “Change Fill” and “Change Stroke.” The
“Change Fill” button is supposed to toggle the fill of the rectangle between Color.LIGHTGRAY and Color.GRAY . The
“Change Stroke” button is supposed to toggle the stroke of the rectangle between Color.DARKGRAY and Color.BLACK .
When we run the program in Listing 7-8, the GUI in Figure 7-6 is displayed on the screen.
Figure 7-6. The UnresponsiveUIExample program
However, this program has a bug in the event handler of the “Change Fill” button:
@Override
public void handle(ActionEvent actionEvent) {
final Paint fillPaint = model.getFillPaint();
if (fillPaint.equals(Color.LIGHTGRAY)) {
model.setFillPaint(Color.GRAY);
} else {
model.setFillPaint(Color.LIGHTGRAY);
}
 
Search WWH ::




Custom Search