Compare commits
No commits in common. "LabWork01" and "master" have entirely different histories.
2
pom.xml
2
pom.xml
@ -75,7 +75,7 @@
|
||||
<!-- Default configuration for running with: mvn clean javafx:run -->
|
||||
<id>default-cli</id>
|
||||
<configuration>
|
||||
<mainClass>dmt.projectairbus/dmt.projectairbus.ApplicationAirbus</mainClass>
|
||||
<mainClass>dmt.projectairbus/dmt.projectairbus.HelloApplication</mainClass>
|
||||
<launcher>app</launcher>
|
||||
<jlinkZipName>app</jlinkZipName>
|
||||
<jlinkImageName>app</jlinkImageName>
|
||||
|
@ -1,30 +0,0 @@
|
||||
package dmt.projectairbus;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ApplicationAirbus extends Application {
|
||||
@Override
|
||||
public void start(Stage stage) throws IOException {
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(ApplicationAirbus.class.getResource("View.fxml"));
|
||||
Scene scene = new Scene(fxmlLoader.load(), 900, 500);
|
||||
|
||||
String stylesheet = Objects.requireNonNull(getClass().getResource("Style.css")).toExternalForm();
|
||||
scene.getStylesheets().add(stylesheet);
|
||||
|
||||
stage.setTitle("Аэробус");
|
||||
stage.setScene(scene);
|
||||
stage.setResizable(false);
|
||||
|
||||
stage.show();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch();
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package dmt.projectairbus;
|
||||
|
||||
/**
|
||||
* Направление перемещения
|
||||
*/
|
||||
public enum DirectionType {
|
||||
/**
|
||||
* Вверх
|
||||
*/
|
||||
Up(1),
|
||||
|
||||
/**
|
||||
* Вниз
|
||||
*/
|
||||
Down(2),
|
||||
|
||||
/**
|
||||
* Влево
|
||||
*/
|
||||
Left(3),
|
||||
|
||||
/**
|
||||
* Вправо
|
||||
*/
|
||||
Right(4);
|
||||
|
||||
private final int value;
|
||||
|
||||
DirectionType(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
@ -1,172 +0,0 @@
|
||||
package dmt.projectairbus;
|
||||
|
||||
import javafx.scene.paint.Color;
|
||||
import java.awt.*;
|
||||
|
||||
import javafx.scene.shape.*;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.util.Duration;
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
import javafx.scene.paint.Color;
|
||||
import java.awt.Stroke;
|
||||
|
||||
public class DrawningAirbus {
|
||||
private EntityAirbus entityAirbus;
|
||||
private Integer pictureWidth;
|
||||
private Integer pictureHeight;
|
||||
private Integer startPosX;
|
||||
private Integer startPosY;
|
||||
private DrawningWindows drawningWindows;
|
||||
|
||||
private final int drawningAirbusWidth = 155;
|
||||
private final int drawningAirbusHeight = 70;
|
||||
|
||||
public EntityAirbus getEntityAirbus() {
|
||||
return entityAirbus;
|
||||
}
|
||||
|
||||
public DrawningWindows getDrawningWindows() {
|
||||
return drawningWindows;
|
||||
}
|
||||
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, boolean passengerSection, boolean engines, boolean windows) {
|
||||
entityAirbus = new EntityAirbus();
|
||||
entityAirbus.Init(speed, weight, bodyColor, additionalColor, passengerSection, engines, windows);
|
||||
drawningWindows = new DrawningWindows();
|
||||
pictureWidth = null;
|
||||
pictureHeight = null;
|
||||
startPosX = null;
|
||||
startPosY = null;
|
||||
}
|
||||
|
||||
public boolean setPictureSize(int width, int height) {
|
||||
if (drawningAirbusWidth <= width && drawningAirbusHeight <= height) {
|
||||
pictureHeight = height;
|
||||
pictureWidth = width;
|
||||
if (startPosX != null && startPosY != null) {
|
||||
if (startPosX + drawningAirbusWidth > pictureWidth) {
|
||||
startPosX = pictureWidth - drawningAirbusWidth;
|
||||
}
|
||||
if (startPosY + drawningAirbusHeight > pictureHeight) {
|
||||
startPosY = pictureHeight - drawningAirbusHeight;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void setPosition(int x, int y) {
|
||||
if (pictureHeight == null || pictureWidth == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (x + drawningAirbusWidth > pictureWidth) {
|
||||
startPosX = pictureWidth - drawningAirbusWidth;
|
||||
} else if (x < 0) {
|
||||
startPosX = 0;
|
||||
} else {
|
||||
startPosX = x;
|
||||
}
|
||||
|
||||
if (y + drawningAirbusHeight > pictureHeight) {
|
||||
startPosY = pictureHeight - drawningAirbusHeight;
|
||||
} else if (y < 0) {
|
||||
startPosY = 0;
|
||||
} else {
|
||||
startPosY = y;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean moveTransport(DirectionType direction) {
|
||||
if (entityAirbus == null || startPosX == null || startPosY == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (direction) {
|
||||
case Left:
|
||||
if (startPosX - entityAirbus.getStep() > 0) {
|
||||
startPosX -= entityAirbus.getStep();
|
||||
}
|
||||
return true;
|
||||
case Up:
|
||||
if (startPosY - entityAirbus.getStep() > 0) {
|
||||
startPosY -= entityAirbus.getStep();
|
||||
}
|
||||
return true;
|
||||
case Right:
|
||||
if (startPosX + entityAirbus.getStep() + drawningAirbusWidth < pictureWidth) {
|
||||
startPosX += entityAirbus.getStep();
|
||||
}
|
||||
return true;
|
||||
case Down:
|
||||
if (startPosY + entityAirbus.getStep() + drawningAirbusHeight < pictureHeight) {
|
||||
startPosY += entityAirbus.getStep();
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void drawTransport(GraphicsContext g) {
|
||||
if (entityAirbus == null || startPosX == null || startPosY == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
g.clearRect(0, 0, pictureWidth, pictureHeight);
|
||||
|
||||
g.setStroke(Color.BLACK);
|
||||
g.setLineWidth(3);
|
||||
g.setFill(entityAirbus.getAdditionalColor());
|
||||
|
||||
double[] pointsSectionX = { startPosX + 45, startPosX + 65, startPosX + 95, startPosX + 115 };
|
||||
double[] pointsSectionY = { startPosY + 30, startPosY + 20, startPosY + 20, startPosY + 30 };
|
||||
|
||||
if (entityAirbus.getPassengerSection()) {
|
||||
g.fillPolygon(pointsSectionX, pointsSectionY, pointsSectionX.length);
|
||||
g.strokePolygon(pointsSectionX, pointsSectionY, pointsSectionX.length);
|
||||
}
|
||||
|
||||
double[] pointsWingX = { startPosX + 1, startPosX + 1, startPosX + 45, startPosX + 45, startPosX + 25 };
|
||||
double[] pointsWingY = { startPosY + 1, startPosY + 44, startPosY + 44, startPosY + 33, startPosY + 33 };
|
||||
|
||||
double[] pointsWindowX = { startPosX + 115, startPosX + 115, startPosX + 155 };
|
||||
double[] pointsWindowY = { startPosY + 33, startPosY + 40, startPosY + 40 };
|
||||
|
||||
g.strokeLine(startPosX, startPosY, startPosX, startPosY + 47);
|
||||
g.strokeLine(startPosX, startPosY + 30, startPosX + 90, startPosY + 30);
|
||||
g.strokeLine(startPosX + 25, startPosY + 30, startPosX, startPosY);
|
||||
g.strokeArc(startPosX, startPosY + 30, 152, 32, -170, 250, ArcType.OPEN);
|
||||
|
||||
g.setFill(entityAirbus.getBodyColor());
|
||||
g.fillOval(startPosX + 1, startPosY + 31, 149, 29);
|
||||
g.fillPolygon(pointsWingX, pointsWingY, pointsWingX.length);
|
||||
g.strokeLine(startPosX + 45, startPosY + 55, startPosX + 100, startPosY + 55);
|
||||
|
||||
/// Шасси
|
||||
g.strokeLine(startPosX + 35, startPosY + 60, startPosX + 35, startPosY + 70);
|
||||
g.strokeLine(startPosX + 110, startPosY + 60, startPosX + 110, startPosY + 70);
|
||||
g.strokeRect(startPosX + 26, startPosY + 68, 8, 8);
|
||||
g.strokeRect(startPosX + 36, startPosY + 68, 8, 8);
|
||||
g.strokeRect(startPosX + 101, startPosY + 68, 8, 8);
|
||||
g.strokeRect(startPosX + 111, startPosY + 68, 8, 8);
|
||||
|
||||
/// Окно
|
||||
g.setFill(Color.LIGHTBLUE);
|
||||
g.fillPolygon(pointsWindowX, pointsWindowY, pointsWindowX.length);
|
||||
g.strokeLine(startPosX + 115, startPosY + 33, startPosX + 115, startPosY + 40);
|
||||
g.strokeLine(startPosX + 115, startPosY + 40, startPosX + 150, startPosY + 40);
|
||||
g.strokeLine(startPosX + 150, startPosY + 40, startPosX + 115, startPosY + 33);
|
||||
|
||||
if (entityAirbus.getEngines()) {
|
||||
g.fillOval(startPosX, startPosY + 30, 35, 15);
|
||||
g.strokeOval(startPosX, startPosY + 30, 35, 15);
|
||||
}
|
||||
|
||||
if(entityAirbus.getWindows()) {
|
||||
drawningWindows.drawWindows(g, startPosX + 40, startPosY + 35, entityAirbus.getAdditionalColor());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
package dmt.projectairbus;
|
||||
|
||||
import javafx.scene.paint.Color;
|
||||
|
||||
/**
|
||||
* Класс-сущность "Аэробус"
|
||||
*/
|
||||
public class EntityAirbus {
|
||||
/**
|
||||
* Скорость
|
||||
*/
|
||||
private int speed;
|
||||
public int getSpeed() {
|
||||
return speed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Вес
|
||||
*/
|
||||
private double weight;
|
||||
public double getWeight() {
|
||||
return weight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Основной цвет
|
||||
*/
|
||||
private Color bodyColor;
|
||||
public Color getBodyColor() {
|
||||
return bodyColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Дополнительный цвет (для опциональных элементов)
|
||||
*/
|
||||
private Color additionalColor;
|
||||
public Color getAdditionalColor() {
|
||||
return additionalColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Признак(опция) наличия доп. пассажирского отсека
|
||||
*/
|
||||
private boolean passengerSection;
|
||||
public boolean getPassengerSection() {
|
||||
return passengerSection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Признак(опция) наличия доп. двигателей
|
||||
*/
|
||||
private boolean engines;
|
||||
public boolean getEngines() {
|
||||
return engines;
|
||||
}
|
||||
|
||||
private boolean windows;
|
||||
public boolean getWindows() {
|
||||
return windows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Шаг перемещения аэробуса
|
||||
*/
|
||||
public int getStep() {
|
||||
return (int)(speed * 100 / weight);
|
||||
}
|
||||
|
||||
/**
|
||||
* Инициализация полей объекта-класса аэробус
|
||||
* @param speed Скорость
|
||||
* @param weight Вес аэробуса
|
||||
* @param bodyColor Основной цвет
|
||||
* @param additionalColor Дополнительный цвет
|
||||
* @param passengerSection Признак(опция) наличия доп. пассажирского отсека
|
||||
* @param engines Признак(опция) наличия доп. двигателей
|
||||
*/
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, boolean passengerSection, boolean engines, boolean windows) {
|
||||
this.speed = speed;
|
||||
this.weight = weight;
|
||||
this.bodyColor = bodyColor;
|
||||
this.additionalColor = additionalColor;
|
||||
this.passengerSection = passengerSection;
|
||||
this.engines = engines;
|
||||
this.windows = windows;
|
||||
}
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
package dmt.projectairbus;
|
||||
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.canvas.Canvas;
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Spinner;
|
||||
import javafx.scene.control.SpinnerValueFactory;
|
||||
import javafx.scene.paint.Color;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class FormAirbus {
|
||||
private DrawningAirbus drawningAirbus;
|
||||
private GraphicsContext graphicsContext;
|
||||
private Random random;
|
||||
|
||||
@FXML
|
||||
private Canvas mainCanvas;
|
||||
|
||||
@FXML
|
||||
private Spinner<Integer> spinnerSelector;
|
||||
|
||||
@FXML
|
||||
private void initialize() {
|
||||
drawningAirbus = new DrawningAirbus();
|
||||
graphicsContext = mainCanvas.getGraphicsContext2D();
|
||||
graphicsContext.setImageSmoothing(false);
|
||||
|
||||
spinnerSelector.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(10, 30, 10, 10));
|
||||
|
||||
random = new Random();
|
||||
}
|
||||
|
||||
private void Draw(){
|
||||
drawningAirbus.drawTransport(graphicsContext);
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void buttonCreate_Click() {
|
||||
drawningAirbus.Init(
|
||||
random.nextInt(100, 300), random.nextInt(1000, 3000),
|
||||
Color.rgb(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)),
|
||||
Color.rgb(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)),
|
||||
random.nextBoolean(), random.nextBoolean(), random.nextBoolean()
|
||||
);
|
||||
drawningAirbus.getDrawningWindows().setSpinnerBlockCount(spinnerSelector.getValue());
|
||||
drawningAirbus.setPictureSize((int) mainCanvas.getWidth(), (int) mainCanvas.getHeight());
|
||||
drawningAirbus.setPosition(random.nextInt(10, 100), random.nextInt(10, 100));
|
||||
|
||||
Draw();
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void buttonMove_Click(ActionEvent event) {
|
||||
String name = ((Button) event.getSource()).getId();
|
||||
|
||||
boolean result = switch (name) {
|
||||
case "buttonUp" -> drawningAirbus.moveTransport(DirectionType.Up);
|
||||
case "buttonDown" -> drawningAirbus.moveTransport(DirectionType.Down);
|
||||
case "buttonLeft" -> drawningAirbus.moveTransport(DirectionType.Left);
|
||||
case "buttonRight" -> drawningAirbus.moveTransport(DirectionType.Right);
|
||||
default -> false;
|
||||
};
|
||||
|
||||
if (result)
|
||||
{
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
}
|
23
src/main/java/dmt/projectairbus/HelloApplication.java
Normal file
23
src/main/java/dmt/projectairbus/HelloApplication.java
Normal file
@ -0,0 +1,23 @@
|
||||
package dmt.projectairbus;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class HelloApplication extends Application {
|
||||
@Override
|
||||
public void start(Stage stage) throws IOException {
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));
|
||||
Scene scene = new Scene(fxmlLoader.load(), 320, 240);
|
||||
stage.setTitle("Hello!");
|
||||
stage.setScene(scene);
|
||||
stage.show();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch();
|
||||
}
|
||||
}
|
14
src/main/java/dmt/projectairbus/HelloController.java
Normal file
14
src/main/java/dmt/projectairbus/HelloController.java
Normal file
@ -0,0 +1,14 @@
|
||||
package dmt.projectairbus;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Label;
|
||||
|
||||
public class HelloController {
|
||||
@FXML
|
||||
private Label welcomeText;
|
||||
|
||||
@FXML
|
||||
protected void onHelloButtonClick() {
|
||||
welcomeText.setText("Welcome to JavaFX Application!");
|
||||
}
|
||||
}
|
@ -4,7 +4,6 @@ module dmt.projectairbus {
|
||||
|
||||
requires org.controlsfx.controls;
|
||||
requires com.dlsc.formsfx;
|
||||
requires java.desktop;
|
||||
|
||||
opens dmt.projectairbus to javafx.fxml;
|
||||
exports dmt.projectairbus;
|
||||
|
@ -1,31 +0,0 @@
|
||||
#buttonLeft
|
||||
{
|
||||
-fx-background-image: url("arrowLeft.png");
|
||||
-fx-background-size: 85%;
|
||||
-fx-background-position: center;
|
||||
-fx-background-repeat: space;
|
||||
}
|
||||
|
||||
#buttonUp
|
||||
{
|
||||
-fx-background-image: url("arrowUp.png");
|
||||
-fx-background-size: 85%;
|
||||
-fx-background-position: center;
|
||||
-fx-background-repeat: space;
|
||||
}
|
||||
|
||||
#buttonDown
|
||||
{
|
||||
-fx-background-image: url("arrowDown.png");
|
||||
-fx-background-size: 85%;
|
||||
-fx-background-position: center;
|
||||
-fx-background-repeat: space;
|
||||
}
|
||||
|
||||
#buttonRight
|
||||
{
|
||||
-fx-background-image: url("arrowRight.png");
|
||||
-fx-background-size: 85%;
|
||||
-fx-background-position: center;
|
||||
-fx-background-repeat: space;
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.canvas.Canvas?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Spinner?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
|
||||
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0" prefWidth="900.0" xmlns="http://javafx.com/javafx/null" xmlns:fx="http://javafx.com/fxml/1" fx:controller="dmt.projectairbus.FormAirbus">
|
||||
<children>
|
||||
<Canvas fx:id="mainCanvas" height="500.0" width="900.0" />
|
||||
<Button layoutX="14.0" layoutY="461.0" mnemonicParsing="false" onAction="#buttonCreate_Click" prefHeight="32.0" prefWidth="74.0" text="Создать" AnchorPane.bottomAnchor="14.0" AnchorPane.leftAnchor="14.0">
|
||||
<font>
|
||||
<Font size="13.0" />
|
||||
</font></Button>
|
||||
<Button id="buttonRight" layoutX="766.0" layoutY="452.0" mnemonicParsing="false" onAction="#buttonMove_Click" prefHeight="35.0" prefWidth="35.0" AnchorPane.bottomAnchor="12.799999999999997" AnchorPane.rightAnchor="14.40000000000002" />
|
||||
<Button id="buttonUp" layoutX="807.0" layoutY="452.0" mnemonicParsing="false" onAction="#buttonMove_Click" prefHeight="35.0" prefWidth="35.0" AnchorPane.bottomAnchor="55.199999999999974" AnchorPane.rightAnchor="57.600000000000065" />
|
||||
<Button id="buttonLeft" layoutX="764.0" layoutY="452.0" mnemonicParsing="false" onAction="#buttonMove_Click" prefHeight="35.0" prefWidth="35.0" AnchorPane.bottomAnchor="12.800000000000011" AnchorPane.rightAnchor="100.79999999999995" />
|
||||
<Button id="buttonDown" layoutX="807.0" layoutY="452.0" mnemonicParsing="false" onAction="#buttonMove_Click" prefHeight="35.0" prefWidth="35.0" AnchorPane.bottomAnchor="12.800000000000011" AnchorPane.rightAnchor="57.799999999999955" />
|
||||
<Spinner fx:id="spinnerSelector" layoutX="15.0" layoutY="415.0" prefHeight="26.0" prefWidth="74.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
Binary file not shown.
Before Width: | Height: | Size: 4.6 KiB |
Binary file not shown.
Before Width: | Height: | Size: 4.6 KiB |
Binary file not shown.
Before Width: | Height: | Size: 4.6 KiB |
Binary file not shown.
Before Width: | Height: | Size: 4.6 KiB |
16
src/main/resources/dmt/projectairbus/hello-view.fxml
Normal file
16
src/main/resources/dmt/projectairbus/hello-view.fxml
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
|
||||
<?import javafx.scene.control.Button?>
|
||||
<VBox alignment="CENTER" spacing="20.0" xmlns:fx="http://javafx.com/fxml"
|
||||
fx:controller="dmt.projectairbus.HelloController">
|
||||
<padding>
|
||||
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0"/>
|
||||
</padding>
|
||||
|
||||
<Label fx:id="welcomeText"/>
|
||||
<Button text="Hello!" onAction="#onHelloButtonClick"/>
|
||||
</VBox>
|
Loading…
x
Reference in New Issue
Block a user