Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Hazem Abdelnabi 906148

package de.example;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.scene.Group;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;

public class Flagge extends Application {

@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Flagge");
Group root = new Group();
Canvas canvas = new Canvas(250, 250);
root.getChildren().add(canvas);
primaryStage.setScene(new Scene(root, 300, 300));
primaryStage.show();

GraphicsContext gc = canvas.getGraphicsContext2D();
zeichne(gc);
}

public void zeichne(GraphicsContext g) {


int hoehe = 50;
int breite = 300;
int x1 = 20;
int y1 = 20;
int stabBreite = 4;
int stabHoche = 3 * hoehe;

zeichneFeld(g, x1, y1, breite, hoehe, Color.BLACK);


zeichneFeld(g, x1, y1 + hoehe, breite, hoehe, Color.RED);
zeichneFeld(g, x1, y1 + 2 * hoehe, breite, hoehe, Color.GOLD);
zeichneFeld(g, x1 - stabBreite, y1, stabBreite, stabHoche, Color.GRAY);

void zeichneFeld(GraphicsContext g, int x1, int y1, int breite, int hoehe, Color col) {
g.setFill(col);
g.fillRect(x1, y1, breite, hoehe);
g.strokeRect(x1, y1, breite, hoehe);

public static void main(String[] args) {


launch();
}
}

package nh.example;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Polygon;
import javafx.stage.Stage;

public class NikolausHaus extends Application {


@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Nikolaus");
Group root = new Group();
Canvas canvas = new Canvas(200, 220);
root.getChildren().add(canvas);
primaryStage.setScene(new Scene(root));
primaryStage.show();

GraphicsContext gc = canvas.getGraphicsContext2D();
zeichne(gc);
}

public void zeichne(GraphicsContext g) {


int hoehe = 100;
int breite = 100;
int x1 = 50;
int y1 = 2*hoehe;
int x2 = x1;
int y2 = y1 - hoehe;
int x3 = x1 + breite;
int y3 = y2;
int x4 = x1 + breite / 2;
int y4 = y2 - hoehe / 2;
int x5 = x3;
int y5 = y1;
double x[] = {x1, x2, x3, x4, x2, x5, x1, x3, x5};
double y[] = {y1, y2, y3, y4, y2, y5, y1, y3, y5};
double fx[] = {x1, x2, x4, x3, x5};
double fy[] = {y1, y2, y4, y3, y5};
g.setFill(Color.RED);
g.fillPolygon(fx, fy, fx.length);

g.setFill(Color.BLACK);
g.strokePolygon(x, y, x.length);
}

public static void main(String[] args) {


launch(args);
}
}

You might also like