Initial Commit
This commit is contained in:
commit
18c1e33942
43
src/application/Main.java
Normal file
43
src/application/Main.java
Normal file
@ -0,0 +1,43 @@
|
||||
package application;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.Alert.AlertType;
|
||||
import javafx.scene.control.ButtonType;
|
||||
|
||||
public class Main extends Application {
|
||||
public void start(Stage primaryStage) {
|
||||
try {
|
||||
RootFlowPane root = new RootFlowPane();
|
||||
Scene scene = new Scene(root, 700, 500);
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.setTitle("GUI-Uebung 3");
|
||||
primaryStage.show();
|
||||
} catch (Exception e) {
|
||||
showAlert(AlertType.ERROR, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static void showAlert(AlertType alertType, String message) {
|
||||
if (message != null) {
|
||||
Alert alert = new Alert(alertType, message, ButtonType.OK);
|
||||
alert.setHeaderText(null);
|
||||
if (alertType == AlertType.WARNING)
|
||||
alert.setTitle("Warnung");
|
||||
else
|
||||
alert.setTitle("Hinweis-Meldung");
|
||||
alert.showAndWait();
|
||||
} else {
|
||||
Alert alert = new Alert(alertType, "Bitte waehlen Sie \"Weiter\" aus", ButtonType.NEXT);
|
||||
alert.setHeaderText(null);
|
||||
alert.setTitle("Hinweis-Meldung");
|
||||
alert.showAndWait();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
}
|
83
src/application/RootFlowPane.java
Normal file
83
src/application/RootFlowPane.java
Normal file
@ -0,0 +1,83 @@
|
||||
package application;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.CheckBox;
|
||||
import javafx.scene.control.RadioButton;
|
||||
import javafx.scene.control.ToggleGroup;
|
||||
import javafx.scene.control.Alert.AlertType;
|
||||
import javafx.scene.layout.FlowPane;
|
||||
|
||||
public class RootFlowPane extends FlowPane {
|
||||
private CheckBox cb;
|
||||
private RadioButton rb1, rb2, rb3;
|
||||
private Button btOk, btBeenden;
|
||||
private ToggleGroup tgRadios;
|
||||
|
||||
public RootFlowPane() {
|
||||
initComponents();
|
||||
addComponents();
|
||||
addHandlers();
|
||||
}
|
||||
|
||||
private void initComponents() {
|
||||
cb = new CheckBox("Waehle mich");
|
||||
|
||||
rb1 = new RadioButton("RB1");
|
||||
rb2 = new RadioButton("RB2");
|
||||
rb3 = new RadioButton("RB3");
|
||||
|
||||
tgRadios = new ToggleGroup();
|
||||
|
||||
btOk = new Button("OK");
|
||||
btOk.setPrefWidth(100);
|
||||
btBeenden = new Button("Beenden");
|
||||
btBeenden.setPrefWidth(100);
|
||||
|
||||
setAlignment(Pos.CENTER);
|
||||
setHgap(20);
|
||||
setVgap(20);
|
||||
}
|
||||
|
||||
private void addComponents() {
|
||||
tgRadios.getToggles().addAll(rb1, rb2, rb3);
|
||||
tgRadios.selectToggle(rb1);
|
||||
|
||||
getChildren().addAll(cb, rb1, rb2, rb3, btOk, btBeenden);
|
||||
}
|
||||
|
||||
private void addHandlers() {
|
||||
|
||||
btOk.setOnAction(event -> okClicked());
|
||||
btBeenden.setOnAction(event -> beenden());
|
||||
|
||||
setOnMouseClicked(event -> flowPaneClicked()); // this = RootFlowPane -> das sind wir
|
||||
}
|
||||
|
||||
// ------------------------ handlers ---------------------
|
||||
|
||||
private void okClicked() {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Auswertung zu den Buttons:\n");
|
||||
sb.append("Checkbox ist ");
|
||||
if (!cb.isSelected())
|
||||
sb.append("nicht ");
|
||||
sb.append("selected;\n");
|
||||
|
||||
sb.append("Ausgewaehlter RadioButton: ");
|
||||
RadioButton rbSelected = (RadioButton) tgRadios.getSelectedToggle();
|
||||
sb.append(rbSelected.getText());
|
||||
|
||||
Main.showAlert(AlertType.INFORMATION, sb.toString());
|
||||
}
|
||||
|
||||
private void beenden() {
|
||||
Platform.exit();
|
||||
}
|
||||
|
||||
private void flowPaneClicked() {
|
||||
Main.showAlert(AlertType.WARNING, "Es wurde irgendwo ins Fenster mit der Maus geklickt");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user