Java Reference
In-Depth Information
rectangle.strokeProperty().bind(model.strokeProperty());
final VBox vBox = new VBox(rectangle);
final Scene scene = new Scene(vBox);
canvas.setScene(scene);
}
});
FlowLayout canvasPanelLayout = new FlowLayout(FlowLayout.CENTER, 10, 10);
JPanel canvasPanel = new JPanel(canvasPanelLayout);
canvasPanel.add(canvas);
changeFillButton = new JButton("Change Fill");
changeStrokeButton = new JButton("Change Stroke");
FlowLayout buttonPanelLayout = new FlowLayout(FlowLayout.CENTER, 10, 10);
JPanel buttonPanel = new JPanel(buttonPanelLayout);
buttonPanel.add(changeFillButton);
buttonPanel.add(changeStrokeButton);
frame.add(canvasPanel, BorderLayout.CENTER);
frame.add(buttonPanel, BorderLayout.SOUTH);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationByPlatform(true);
frame.pack();
}
}
private static class Controller {
private View view;
private Controller(final Model model, final View view) {
this.view = view;
this.view.changeFillButton.addActionListener(e -> {
Platform.runLater(() -> {
final Paint fillPaint = model.getFill();
if (fillPaint.equals(Color.LIGHTGRAY)) {
model.setFill(Color.GRAY);
} else {
model.setFill(Color.LIGHTGRAY);
}
});
});
this.view.changeStrokeButton.addActionListener(e -> {
Platform.runLater(() -> {
final Paint strokePaint = model.getStroke();
if (strokePaint.equals(Color.DARKGRAY)) {
model.setStroke(Color.BLACK);
} else {
model.setStroke(Color.DARKGRAY);
}
});
});
}
Search WWH ::




Custom Search