Java Reference
In-Depth Information
private static void swingMain(String[] args) {
Model model = new Model();
View view = new View(model);
Controller controller = new Controller(model, view);
controller.mainLoop();
}
private static class Model {
private ObjectProperty<Color> fill = new SimpleObjectProperty<>(Color.LIGHTGRAY);
private ObjectProperty<Color> stroke = new SimpleObjectProperty<>(Color.DARKGRAY);
public final Color getFill() {
return fill.get();
}
public final void setFill(Color value) {
this.fill.set(value);
}
public final Color getStroke() {
return stroke.get();
}
public final void setStroke(Color value) {
this.stroke.set(value);
}
public final ObjectProperty<Color> fillProperty() {
return fill;
}
public final ObjectProperty<Color> strokeProperty() {
return stroke;
}
}
private static class View {
public JFrame frame;
public JFXPanel canvas;
public JButton changeFillButton;
public JButton changeStrokeButton;
private View(final Model model) {
frame = new JFrame("JavaFX in Swing Example");
canvas = new JFXPanel();
canvas.setPreferredSize(new Dimension(210, 210));
Platform.runLater(new Runnable() {
@Override
public void run() {
final Rectangle rectangle = new Rectangle(200, 200);
rectangle.setStrokeWidth(10);
rectangle.fillProperty().bind(model.fillProperty());
Search WWH ::




Custom Search