Auslagerung der Methoden zum Formatieren
This commit is contained in:
parent
e25465873b
commit
5378876ff9
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -7,10 +7,13 @@
|
||||
|
||||
<StackPane prefHeight="800.0" prefWidth="700.0" xmlns="http://javafx.com/javafx/11.0.2" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.happy_bird.HappyBird" back >
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
<ImageView>
|
||||
<image>
|
||||
<Image url="@pics/Background.png"></Image>
|
||||
</image>
|
||||
</ImageView>
|
||||
|
||||
>>>>>>> 5db5b6bb195a2b7d1296e7d3f9b98d6c75dba2c2
|
||||
</StackPane>
|
||||
|
Binary file not shown.
@ -1,5 +1,9 @@
|
||||
package com.example.happy_bird;
|
||||
|
||||
public class HappyBird {
|
||||
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TextField;
|
||||
|
||||
public class HappyBird extends HappyBirdMain {
|
||||
|
||||
}
|
||||
|
@ -22,20 +22,46 @@ import java.io.IOException;
|
||||
|
||||
public class HappyBirdMain extends Application {
|
||||
|
||||
private Pane pane = new Pane();
|
||||
private Scene scene = new Scene(pane, 800, 700);
|
||||
|
||||
private Label nameLabel = new Label("NAME");
|
||||
private Label acronymLabel = new Label("KÜRZEL");
|
||||
private Label headline = new Label("HAPPY BIRD");
|
||||
private Label soundLabel = new Label("SOUND");
|
||||
|
||||
private Label labels[] = {nameLabel, acronymLabel, soundLabel};
|
||||
private Label headlineLabels[] = {headline};
|
||||
|
||||
private Button startButton = new Button("START");
|
||||
private Button highscoresButton = new Button("HIGHSCORES");
|
||||
private Button settingsButton = new Button("EINSTELLUNGEN");
|
||||
private Button startGameButton = new Button("SPIEL STARTEN");
|
||||
private Button menuButton = new Button("ZURÜCK");
|
||||
|
||||
private Button[] buttons = {startButton, highscoresButton, settingsButton, startGameButton, menuButton};
|
||||
|
||||
private TextField name = new TextField();
|
||||
private TextField acronym = new TextField();
|
||||
|
||||
private TextField inputFields[] = {name, acronym};
|
||||
|
||||
private Slider soundSlider = new Slider();
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Stage stage) throws IOException {
|
||||
Pane pane = new Pane();
|
||||
|
||||
Scene scene = new Scene(pane, 800, 700);
|
||||
stage.setTitle("Happy Bird");
|
||||
stage.setScene(scene);
|
||||
|
||||
//Backgroundimage
|
||||
/**Bild für Hintergrund erstellen:*/
|
||||
Image image = new Image("file:src/main/resources/com/example/happy_bird/pics/Background.png");
|
||||
|
||||
/**Hintergrund erstellen:*/
|
||||
BackgroundImage backgroundImageImg = new BackgroundImage(
|
||||
image,
|
||||
BackgroundRepeat.NO_REPEAT,
|
||||
@ -44,68 +70,121 @@ public class HappyBirdMain extends Application {
|
||||
BackgroundSize.DEFAULT
|
||||
);
|
||||
|
||||
/**Hintergrund zu Pane hinzufügen:*/
|
||||
Background background = new Background(backgroundImageImg);
|
||||
pane.setBackground(background);
|
||||
|
||||
//Headline-Label
|
||||
Label headline = new Label("Happy Bird");
|
||||
headline.setPrefSize(300, 75);
|
||||
headline.setTextAlignment(TextAlignment.CENTER);
|
||||
headline.setStyle("-fx-background-color: #DED894; " +
|
||||
"-fx-text-fill: #000000; " +
|
||||
"-fx-font-size: 35px; " +
|
||||
"-fx-border-width: 5px;" +
|
||||
"-fx-border-color: #543847;" +
|
||||
"-fx-font-weight: bold;" +
|
||||
"-fx-alignment: center;" +
|
||||
"-fx-background-radius: 20px;" +
|
||||
"-fx-border-radius: 15px;");
|
||||
|
||||
|
||||
/**Labels erstellen:*/
|
||||
|
||||
|
||||
/**Labels in Arrays speichern:*/
|
||||
|
||||
|
||||
/**Labels formatieren:*/
|
||||
labelsFormating(labels, pane);
|
||||
headlineFormating(headlineLabels, pane);
|
||||
|
||||
/**alle labels an ihre Stelle:*/
|
||||
int yPositionLabels = 225;
|
||||
for (Label label : labels) {
|
||||
label.setLayoutX(275);
|
||||
label.setLayoutY(yPositionLabels);
|
||||
yPositionLabels += 150;
|
||||
}
|
||||
|
||||
/**headline an ihre Stelle:*/
|
||||
headline.setLayoutX(250);
|
||||
headline.setLayoutY(100);
|
||||
|
||||
pane.getChildren().add(headline);
|
||||
/**soundLabel an seine Stelle:*/
|
||||
soundLabel.setLayoutY(225);
|
||||
|
||||
//Buttons:
|
||||
Button startButton = new Button("START");
|
||||
Button highscoresButton = new Button("HIGHSCORES");
|
||||
Button settingsButton = new Button("EINSTELLUNGEN");
|
||||
Button startGame = new Button("SPIEL STARTEN");
|
||||
|
||||
Button buttons[] = {startButton, highscoresButton, settingsButton, startGame};
|
||||
Button menuButton = new Button("ZURÜCK");
|
||||
menuButton.setStyle("-fx-background-color: #e86000; " +
|
||||
"-fx-text-fill: #FFFFFF; " +
|
||||
"-fx-font-size: 20px; " +
|
||||
"-fx-border-width: 5px;" +
|
||||
"-fx-border-color: #FFFFFF;" +
|
||||
"-fx-font-weight: bold;" +
|
||||
"-fx-border-radius: 15px;" +
|
||||
"-fx-background-radius: 20px;");
|
||||
pane.getChildren().add(menuButton);
|
||||
menuButton.setPrefSize(200, 50);
|
||||
|
||||
/**Buttons erstellen:*/
|
||||
|
||||
|
||||
/**Buttons in Array speichern:*/
|
||||
|
||||
|
||||
/**Buttons formatieren:*/
|
||||
buttonsFormating(buttons, pane);
|
||||
|
||||
/**alle Buttons an ihre Stelle:*/
|
||||
int yPositionButtons = 225;
|
||||
for (Button button : buttons) {
|
||||
button.setLayoutX(300);
|
||||
button.setLayoutY(yPositionButtons);
|
||||
yPositionButtons += 100;
|
||||
}
|
||||
|
||||
/**menuButton an seine Stelle und vorerst ausblenden:*/
|
||||
menuButton.setLayoutX(575);
|
||||
menuButton.setLayoutY(625);
|
||||
menuButton.setVisible(false);
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
>>>>>>> 6697cdef8e121846595c7e99f811d1088227faa6
|
||||
startGame.setVisible(false);
|
||||
/**startGameButton unsichtbar*/
|
||||
startGameButton.setVisible(false);
|
||||
|
||||
|
||||
//Button buttons[] = {startButton, highscoresButton, settingsButton};
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
>>>>>>> 6697cdef8e121846595c7e99f811d1088227faa6
|
||||
/**Textfelder erstellen:*/
|
||||
|
||||
int yPosition = 225;
|
||||
|
||||
/**Textfelder in Array speichern:*/
|
||||
|
||||
|
||||
/**Textfelder formatieren:*/
|
||||
textfieldsFormating(inputFields, pane);
|
||||
|
||||
/**Textfelder an ihre Position:*/
|
||||
int yPositionInputFields = 290;
|
||||
for (TextField feld : inputFields) {
|
||||
feld.setLayoutX(275);
|
||||
feld.setLayoutY(yPositionInputFields);
|
||||
yPositionInputFields += 150;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**SoundSlider erstellen:*/
|
||||
|
||||
|
||||
/**SoundSlicer anpassen:*/
|
||||
soundSliderFormating(soundSlider, pane);
|
||||
|
||||
|
||||
|
||||
/**ClickEvents:*/
|
||||
startButton.setOnAction(event -> {
|
||||
startButtonClick();
|
||||
});
|
||||
|
||||
settingsButton.setOnAction(event -> {
|
||||
settingsButtonClick();
|
||||
});
|
||||
|
||||
highscoresButton.setOnAction(event -> {
|
||||
highscoresButtonClick();
|
||||
});
|
||||
|
||||
menuButton.setOnAction(event -> {
|
||||
menuButtonClick();
|
||||
});
|
||||
|
||||
stage.show();
|
||||
}
|
||||
|
||||
/***
|
||||
* Formatiert alle Buttons und fügt sie der Pane hinzu
|
||||
* @param buttons ButtonArray mit allen Arrays
|
||||
* @param pane Pane, auf der die Buttons angezeigt werden
|
||||
*/
|
||||
public void buttonsFormating(Button[] buttons, Pane pane) {
|
||||
for (Button button : buttons) {
|
||||
pane.getChildren().add(button);
|
||||
button.setPrefSize(200, 50);
|
||||
button.setLayoutX(300);
|
||||
button.setLayoutY(yPosition);
|
||||
yPosition += 100;
|
||||
|
||||
button.setStyle("-fx-background-color: #e86000; " +
|
||||
"-fx-text-fill: #FFFFFF; " +
|
||||
@ -115,33 +194,20 @@ public class HappyBirdMain extends Application {
|
||||
"-fx-font-weight: bold;" +
|
||||
"-fx-border-radius: 15px;" +
|
||||
"-fx-background-radius: 20px;");
|
||||
|
||||
pane.getChildren().add(button);
|
||||
}
|
||||
}
|
||||
|
||||
startGame.setVisible(false);
|
||||
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
>>>>>>> 6697cdef8e121846595c7e99f811d1088227faa6
|
||||
Label nameLabel = new Label("Name:");
|
||||
Label acronymLabel = new Label("Kürzel:");
|
||||
|
||||
Label startLabels[] = {nameLabel, acronymLabel};
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
>>>>>>> 6697cdef8e121846595c7e99f811d1088227faa6
|
||||
startButton.setOnAction(event -> {
|
||||
headline.setText("Start");
|
||||
for (Button button : buttons) {
|
||||
button.setVisible(false);
|
||||
menuButton.setVisible(true);
|
||||
}
|
||||
});
|
||||
|
||||
int yPositionStartLabels = 225;
|
||||
for (Label label : startLabels) {
|
||||
/***
|
||||
* Formatiert alle kleinen Labels (keine Überschrift) und fügt sie der Pane hinzu
|
||||
* @param labels LabelArray mit allen Labels
|
||||
* @param pane Pane, auf der die Labels angezeigt werden
|
||||
*/
|
||||
public void labelsFormating(Label[] labels, Pane pane) {
|
||||
for (Label label : labels) {
|
||||
label.setPrefSize(250, 50);
|
||||
|
||||
label.setStyle("-fx-background-color: #DED894; " +
|
||||
"-fx-text-fill: #000000; " +
|
||||
"-fx-font-size: 20px; " +
|
||||
@ -152,122 +218,137 @@ public class HappyBirdMain extends Application {
|
||||
"-fx-background-radius: 20px;" +
|
||||
"-fx-border-radius: 15px;");
|
||||
|
||||
label.setLayoutX(275);
|
||||
label.setLayoutY(yPositionStartLabels);
|
||||
yPositionStartLabels += 150;
|
||||
|
||||
pane.getChildren().add(label);
|
||||
|
||||
label.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
TextField name = new TextField();
|
||||
TextField acronym = new TextField();
|
||||
/***
|
||||
* Formatiert alle Überschriften-Labels und fügt sie der Pane hinzu
|
||||
* @param labels LabelArray mit Überschriften-Labels
|
||||
* @param pane Pane, auf der die Labels angezeigt werden
|
||||
*/
|
||||
public void headlineFormating(Label[] labels, Pane pane) {
|
||||
for (Label label : labels) {
|
||||
label.setPrefSize(300, 75);
|
||||
label.setTextAlignment(TextAlignment.CENTER);
|
||||
|
||||
TextField inputFields[] = {name, acronym};
|
||||
label.setStyle("-fx-background-color: #DED894; " +
|
||||
"-fx-text-fill: #000000; " +
|
||||
"-fx-font-size: 35px; " +
|
||||
"-fx-border-width: 5px;" +
|
||||
"-fx-border-color: #543847;" +
|
||||
"-fx-font-weight: bold;" +
|
||||
"-fx-alignment: center;" +
|
||||
"-fx-background-radius: 20px;" +
|
||||
"-fx-border-radius: 15px;");
|
||||
|
||||
int yPositionInputFields = 290;
|
||||
for (TextField feld : inputFields) {
|
||||
feld.setPrefSize(250, 50);
|
||||
feld.setStyle("-fx-font-size: 20px;" +
|
||||
pane.getChildren().add(label);
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
* Formatiert alle Textfelder und fügt sie der Pane hinzu
|
||||
* @param textfields TextFieldArray mit allen Textfeldern
|
||||
* @param pane Pane, auf der die Textfelder angezeigt werden
|
||||
*/
|
||||
public void textfieldsFormating(TextField[] textfields, Pane pane) {
|
||||
for (TextField field : textfields) {
|
||||
field.setPrefSize(250, 50);
|
||||
field.setStyle("-fx-font-size: 20px;" +
|
||||
"-fx-font-weight: bold;");
|
||||
|
||||
feld.setLayoutX(275);
|
||||
feld.setLayoutY(yPositionInputFields);
|
||||
yPositionInputFields += 150;
|
||||
pane.getChildren().add(field);
|
||||
|
||||
pane.getChildren().add(feld);
|
||||
field.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
* Formatiert den soundSlider und fügt ihn der Pane hinzu
|
||||
* @param slider SoundSlider
|
||||
* @param pane Pane, auf der der Slider angezeigt wird
|
||||
*/
|
||||
public void soundSliderFormating(Slider slider, Pane pane) {
|
||||
slider.setPrefSize(200, 5);
|
||||
slider.setLayoutX(300);
|
||||
slider.setLayoutY(295);
|
||||
|
||||
pane.getChildren().add(slider);
|
||||
|
||||
slider.setVisible(false);
|
||||
}
|
||||
|
||||
/***
|
||||
* Hauptmenü wird ausgeblendet, Nameneingabe folgt
|
||||
*/
|
||||
public void startButtonClick() {
|
||||
headline.setText("START");
|
||||
|
||||
for(Button button : buttons) {
|
||||
button.setVisible(false);
|
||||
|
||||
}
|
||||
|
||||
startGameButton.setVisible(true);
|
||||
menuButton.setVisible(true);
|
||||
startGameButton.setLayoutY(520);
|
||||
|
||||
for(TextField feld : inputFields) {
|
||||
feld.setVisible(true);
|
||||
}
|
||||
for (Label label : labels ) {
|
||||
label.setVisible(true);
|
||||
}
|
||||
|
||||
soundLabel.setVisible(false);
|
||||
}
|
||||
|
||||
/***
|
||||
* Hauptmenü wird ausgeblendet, Einstellungen folgen
|
||||
*/
|
||||
public void settingsButtonClick() {
|
||||
headline.setText("EINSTELLUNGEN");
|
||||
startButton.setVisible(false);
|
||||
highscoresButton.setVisible(false);
|
||||
settingsButton.setVisible(false);
|
||||
menuButton.setVisible(true);
|
||||
soundSlider.setVisible(true);
|
||||
soundLabel.setVisible(true);
|
||||
}
|
||||
|
||||
/***
|
||||
* Hauptmenü wird ausgeblendet, Highscores folgen
|
||||
*/
|
||||
public void highscoresButtonClick() {
|
||||
headline.setText("HIGHSCORES");
|
||||
startButton.setVisible(false);
|
||||
highscoresButton.setVisible(false);
|
||||
settingsButton.setVisible(false);
|
||||
menuButton.setVisible(true);
|
||||
}
|
||||
|
||||
/***
|
||||
* Nameneingabe, Einstellungen und Highscores werden ausgeblendet
|
||||
* Erneutes Anzeigen des Hauptmenüs
|
||||
*/
|
||||
public void menuButtonClick() {
|
||||
headline.setText("HAPPY BIRD");
|
||||
startButton.setVisible(true);
|
||||
highscoresButton.setVisible(true);
|
||||
settingsButton.setVisible(true);
|
||||
menuButton.setVisible(false);
|
||||
soundSlider.setVisible(false);
|
||||
soundLabel.setVisible(false);
|
||||
startGameButton.setVisible(false);
|
||||
|
||||
for(TextField feld : inputFields) {
|
||||
feld.setVisible(false);
|
||||
}
|
||||
|
||||
|
||||
startButton.setOnAction(event -> {
|
||||
headline.setText("Start");
|
||||
for(Button button : buttons) {
|
||||
button.setVisible(false);
|
||||
|
||||
}
|
||||
|
||||
startGame.setVisible(true);
|
||||
menuButton.setVisible(true);
|
||||
startGame.setLayoutY(520);
|
||||
|
||||
for(TextField feld : inputFields) {
|
||||
feld.setVisible(true);
|
||||
}
|
||||
for (Label label : startLabels )
|
||||
{
|
||||
label.setVisible(true);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//startGame.setOnAction(event -> {});
|
||||
//startButton.setOnAction(event -> {});
|
||||
|
||||
|
||||
|
||||
//Slider:
|
||||
Slider soundSlider = new Slider();
|
||||
pane.getChildren().add(soundSlider);
|
||||
soundSlider.setPrefSize(200, 5);
|
||||
soundSlider.setLayoutX(300);
|
||||
soundSlider.setLayoutY(295);
|
||||
soundSlider.setVisible(false);
|
||||
|
||||
Label soundLabel = new Label("SOUND");
|
||||
soundLabel.setPrefSize(200, 55);
|
||||
soundLabel.setTextAlignment(TextAlignment.CENTER);
|
||||
soundLabel.setStyle("-fx-background-color: #DED894; " +
|
||||
"-fx-text-fill: #000000; " +
|
||||
"-fx-font-size: 20px; " +
|
||||
"-fx-border-width: 5px;" +
|
||||
"-fx-border-color: #543847;" +
|
||||
"-fx-font-weight: bold;" +
|
||||
"-fx-alignment: center;" +
|
||||
"-fx-background-radius: 20px;" +
|
||||
"-fx-border-radius: 15px;");
|
||||
soundLabel.setLayoutX(300);
|
||||
soundLabel.setLayoutY(225);
|
||||
|
||||
pane.getChildren().add(soundLabel);
|
||||
soundLabel.setVisible(false);
|
||||
|
||||
settingsButton.setOnAction(event -> {
|
||||
headline.setText("EINSTELLUNGEN");
|
||||
startButton.setVisible(false);
|
||||
highscoresButton.setVisible(false);
|
||||
settingsButton.setVisible(false);
|
||||
menuButton.setVisible(true);
|
||||
soundSlider.setVisible(true);
|
||||
soundLabel.setVisible(true);
|
||||
});
|
||||
|
||||
highscoresButton.setOnAction(event -> {
|
||||
headline.setText("HIGHSCORES");
|
||||
startButton.setVisible(false);
|
||||
highscoresButton.setVisible(false);
|
||||
settingsButton.setVisible(false);
|
||||
menuButton.setVisible(true);
|
||||
});
|
||||
|
||||
menuButton.setOnAction(event -> {
|
||||
headline.setText("HAPPY BIRD");
|
||||
startButton.setVisible(true);
|
||||
highscoresButton.setVisible(true);
|
||||
settingsButton.setVisible(true);
|
||||
menuButton.setVisible(false);
|
||||
soundSlider.setVisible(false);
|
||||
soundLabel.setVisible(false);
|
||||
startGame.setVisible(false);
|
||||
for(TextField feld : inputFields) {
|
||||
feld.setVisible(false);
|
||||
}
|
||||
for (Label label : startLabels )
|
||||
{
|
||||
label.setVisible(false);
|
||||
}
|
||||
});
|
||||
|
||||
stage.show();
|
||||
for (Label label : labels ) {
|
||||
label.setVisible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user