Merge branch 'master' of github.com:Selebrator/omp-ha-2019

master
Selebrator 7 years ago
commit 66905d4f0e

@ -1,10 +1,16 @@
apply plugin: 'java' plugins {
apply plugin: 'idea' id 'java'
id 'idea'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.7'
}
compileJava.options.encoding = 'UTF-8' compileJava.options.encoding = 'UTF-8'
project.ext.junitVersion = '5.3.1' project.ext.junitVersion = '5.3.1'
mainClassName = '_9._2.Lights'
sourceCompatibility = 1.8 sourceCompatibility = 1.8
repositories { repositories {
@ -16,12 +22,17 @@ dependencies {
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion" testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
} }
javafx {
version = "12.0.1"
modules = [ 'javafx.controls' ]
}
test { test {
useJUnitPlatform() useJUnitPlatform()
} }
task abgabe(type: Zip) { task abgabe(type: Zip) {
if(project.hasProperty("n")) { if (project.hasProperty("n")) {
includeEmptyDirs = false includeEmptyDirs = false
from(".") from(".")
from("src/main/") { from("src/main/") {
@ -32,7 +43,7 @@ task abgabe(type: Zip) {
} }
include "java/_$n/**/*" include "java/_$n/**/*"
include "resources/$n/**/*" include "resources/$n/**/*"
if(!project.hasProperty("p")) { if (!project.hasProperty("p")) {
include "README.md" include "README.md"
include "java/provided/*" include "java/provided/*"
include "java/provided/_$n/**/*" include "java/provided/_$n/**/*"

@ -0,0 +1,50 @@
package _9._1;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Slider;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
public class ColorMixer extends Application {
@Override
public void start(Stage stage) {
VBox vBox = new VBox(10);
vBox.setAlignment(Pos.TOP_CENTER);
vBox.setPadding(new Insets(10));
Rectangle rectangle = new Rectangle(200, 200);
Slider red = colorSlider(Color.RED);
Slider green = colorSlider(Color.GREEN);
Slider blue = colorSlider(Color.BLUE);
red.valueProperty().addListener((observable, oldValue, newValue) -> rectangle.setFill(Color.rgb(newValue.intValue(), (int) green.getValue(), (int) blue.getValue())));
green.valueProperty().addListener((observable, oldValue, newValue) -> rectangle.setFill(Color.rgb((int) red.getValue(), newValue.intValue(), (int) blue.getValue())));
blue.valueProperty().addListener((observable, oldValue, newValue) -> rectangle.setFill(Color.rgb((int) red.getValue(), (int) green.getValue(), newValue.intValue())));
vBox.getChildren().addAll(rectangle, red, green, blue);
Scene scene = new Scene(new StackPane(vBox), 600, 360);
stage.setScene(scene);
stage.setTitle("Color-Mixer");
stage.setResizable(false);
stage.show();
}
private Slider colorSlider(Paint fill) {
Slider slider = new Slider(0, 255, 0);
slider.setShowTickLabels(true);
slider.setShowTickMarks(true);
slider.setBackground(new Background(new BackgroundFill(fill, CornerRadii.EMPTY, Insets.EMPTY)));
return slider;
}
public static void main(String[] args) {
launch();
}
}

@ -0,0 +1,90 @@
package _9._2;
import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import java.util.Optional;
public class Lights extends Application {
private static final int DEFAULT_SIZE = 4;
private static final int GAP = 2;
private static final Paint ON = Color.YELLOW;
private static final Paint OFF = Color.WHITE;
@Override
public void start(Stage primaryStage) throws Exception {
final int size = Optional.ofNullable(this.getParameters().getNamed().get("size"))
.map(Integer::parseInt).orElse(DEFAULT_SIZE);
GridPane grid = new GridPane();
Scene scene = new Scene(grid, 600, 600);
scene.setFill(Color.BLACK);
grid.setHgap(GAP);
grid.setVgap(GAP);
for(int x = 0; x < size; x++) {
for(int y = 0; y < size; y++) {
Rectangle rec = new Rectangle(150, 150);
rec.heightProperty().bind(scene.heightProperty().subtract(size * GAP).divide(size));
rec.widthProperty().bind(scene.widthProperty().subtract(size * GAP).divide(size));
rec.setFill(OFF);
grid.add(rec, x, y);
}
}
for(int x = 0; x < size; x++) {
for(int y = 0; y < size; y++) {
Rectangle rec = getNodeByRowColumnIndex(x, y, grid);
assert rec != null;
Rectangle up = getNodeByRowColumnIndex(x, y - 1, grid);
Rectangle down = getNodeByRowColumnIndex(x, y + 1, grid);
Rectangle left = getNodeByRowColumnIndex(x - 1, y, grid);
Rectangle right = getNodeByRowColumnIndex(x + 1, y, grid);
rec.setOnMouseClicked(event -> {
toggle(rec);
toggle(up);
toggle(down);
toggle(left);
toggle(right);
});
}
}
primaryStage.setScene(scene);
primaryStage.setTitle("Lights");
primaryStage.show();
}
private void toggle(Rectangle rec) {
if(rec == null) {
return;
}
Paint color = rec.getFill();
if(color == ON) {
rec.setFill(OFF);
} else if(color == OFF) {
rec.setFill(ON);
} else {
throw new IllegalStateException();
}
}
public static <T extends Node> T getNodeByRowColumnIndex(final int column, final int row, GridPane gridPane) {
ObservableList<Node> children = gridPane.getChildren();
for(Node node : children) {
if(GridPane.getRowIndex(node) == row && GridPane.getColumnIndex(node) == column) {
return (T) node;
}
}
return null;
}
public static void main(String[] args) {
launch(args);
}
}
Loading…
Cancel
Save