Java Reference
In-Depth Information
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
public class UnresponsiveUIExample extends Application {
private Model model;
private View view;
public static void main(String[] args) {
launch(args);
}
public UnresponsiveUIExample() {
model = new Model();
}
@Override
public void start(Stage stage) throws Exception {
view = new View(model);
hookupEvents();
stage.setTitle("Unresponsive UI Example");
stage.setScene(view.scene);
stage.show();
}
private void hookupEvents() {
view.changeFillButton.setOnAction(actionEvent -> {
final Paint fillPaint = model.getFillPaint();
if (fillPaint.equals(Color.LIGHTGRAY)) {
model.setFillPaint(Color.GRAY);
} else {
model.setFillPaint(Color.LIGHTGRAY);
}
// Bad code, this will cause the UI to be unresponsive
try {
Thread.sleep(Long.MAX_VALUE);
} catch (InterruptedException e) {
// TODO properly handle interruption
}
});
view.changeStrokeButton.setOnAction(actionEvent -> {
final Paint strokePaint = model.getStrokePaint();
if (strokePaint.equals(Color.DARKGRAY)) {
model.setStrokePaint(Color.BLACK);
Search WWH ::




Custom Search