Compare commits
4 Commits
main
...
LabWork_01
Author | SHA1 | Date | |
---|---|---|---|
e8368ccba9 | |||
5929ff30b4 | |||
d886c58e2a | |||
efe0d59e2c |
7
ProjectLiner/.vscode/settings.json
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"java.project.sourcePaths": ["src"],
|
||||||
|
"java.project.outputPath": "bin",
|
||||||
|
"java.project.referencedLibraries": [
|
||||||
|
"lib/**/*.jar"
|
||||||
|
]
|
||||||
|
}
|
18
ProjectLiner/README.md
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
## Getting Started
|
||||||
|
|
||||||
|
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
|
||||||
|
|
||||||
|
## Folder Structure
|
||||||
|
|
||||||
|
The workspace contains two folders by default, where:
|
||||||
|
|
||||||
|
- `src`: the folder to maintain sources
|
||||||
|
- `lib`: the folder to maintain dependencies
|
||||||
|
|
||||||
|
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
|
||||||
|
|
||||||
|
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
|
||||||
|
|
||||||
|
## Dependency Management
|
||||||
|
|
||||||
|
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
|
19
ProjectLiner/src/CanvasLiner.java
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class CanvasLiner extends JComponent {
|
||||||
|
public DrawningLiner _drawingLiner;
|
||||||
|
|
||||||
|
public CanvasLiner() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void paintComponent(Graphics g) {
|
||||||
|
if (_drawingLiner == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
super.paintComponents(g);
|
||||||
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
_drawingLiner.DrawTransport(g2d);
|
||||||
|
super.repaint();
|
||||||
|
}
|
||||||
|
}
|
6
ProjectLiner/src/CountDeck.java
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
public enum CountDeck {
|
||||||
|
One,
|
||||||
|
Two,
|
||||||
|
Three,
|
||||||
|
Four;
|
||||||
|
}
|
6
ProjectLiner/src/DirectionType.java
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
public enum DirectionType {
|
||||||
|
Up,
|
||||||
|
Down,
|
||||||
|
Left,
|
||||||
|
Right
|
||||||
|
}
|
42
ProjectLiner/src/DrawningDeck.java
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawningDeck {
|
||||||
|
private CountDeck _deck;
|
||||||
|
|
||||||
|
public CountDeck getCount() {
|
||||||
|
return _deck;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetCount(int count) {
|
||||||
|
switch (count) {
|
||||||
|
case 1:
|
||||||
|
_deck = CountDeck.One;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
_deck = CountDeck.Two;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
_deck = CountDeck.Three;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Draw(Graphics2D g, int _StartPosX, int _StartPosY) {
|
||||||
|
if (_deck == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_deck == CountDeck.One) {
|
||||||
|
g.fillRect(_StartPosX + 50, _StartPosY + 70, 100, 10);
|
||||||
|
}
|
||||||
|
if (_deck == CountDeck.Two) {
|
||||||
|
g.fillRect(_StartPosX + 50, _StartPosY + 70, 100, 10);
|
||||||
|
g.fillRect(_StartPosX + 60, _StartPosY + 60, 80, 15);
|
||||||
|
}
|
||||||
|
if (_deck == CountDeck.Three) {
|
||||||
|
g.fillRect(_StartPosX + 50, _StartPosY + 70, 100, 10);
|
||||||
|
g.fillRect(_StartPosX + 60, _StartPosY + 60, 80, 15);
|
||||||
|
g.fillRect(_StartPosX + 70, _StartPosY + 50, 60, 15);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
131
ProjectLiner/src/DrawningLiner.java
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class DrawningLiner extends JPanel {
|
||||||
|
public EntityLiner EntityLiner;
|
||||||
|
public DrawningDeck _deck = null;
|
||||||
|
private Integer picture_width;
|
||||||
|
private Integer picture_height;
|
||||||
|
private Integer _StartPosX;
|
||||||
|
private Integer _StartPosY;
|
||||||
|
private int drawningLinerWidth = 160;
|
||||||
|
private int drawningLinerHeight = 120;
|
||||||
|
|
||||||
|
public void Init(int speed, double weight, Color bodycolor, Color additionalcolor, boolean pipe, boolean anchor) {
|
||||||
|
EntityLiner = new EntityLiner();
|
||||||
|
EntityLiner.Init(speed, weight, bodycolor, additionalcolor, pipe, anchor);
|
||||||
|
picture_width = null;
|
||||||
|
picture_height = null;
|
||||||
|
_StartPosX = null;
|
||||||
|
_StartPosY = null;
|
||||||
|
_deck = new DrawningDeck();
|
||||||
|
Random rand = new Random();
|
||||||
|
int randomNum = rand.nextInt(3);
|
||||||
|
_deck.SetCount(randomNum);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean SetPictureSize(int width, int height) {
|
||||||
|
if (width < drawningLinerWidth || height < drawningLinerHeight)
|
||||||
|
return false;
|
||||||
|
picture_width = width;
|
||||||
|
picture_height = height;
|
||||||
|
if (_StartPosX != null || _StartPosY != null) {
|
||||||
|
if (_StartPosX + drawningLinerWidth > picture_width) {
|
||||||
|
_StartPosX = _StartPosX - (_StartPosX + drawningLinerWidth - picture_width);
|
||||||
|
} else if (_StartPosX < 0)
|
||||||
|
_StartPosX = 0;
|
||||||
|
if (_StartPosY + drawningLinerHeight > picture_height) {
|
||||||
|
_StartPosY = _StartPosY - (_StartPosY + drawningLinerHeight - picture_height);
|
||||||
|
} else if (_StartPosY < 0)
|
||||||
|
_StartPosY = 0;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetPosition(int x, int y) {
|
||||||
|
if (!(picture_width != null && picture_height != null))
|
||||||
|
return;
|
||||||
|
if (x + drawningLinerWidth > picture_width) {
|
||||||
|
_StartPosX = x - (x + drawningLinerWidth - picture_width);
|
||||||
|
} else if (x < 0)
|
||||||
|
_StartPosX = 0;
|
||||||
|
else
|
||||||
|
_StartPosX = x;
|
||||||
|
if (y + drawningLinerHeight > picture_height) {
|
||||||
|
_StartPosY = y - (y + drawningLinerHeight - picture_height);
|
||||||
|
} else if (y < 0)
|
||||||
|
_StartPosY = 0;
|
||||||
|
else
|
||||||
|
_StartPosY = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean MoveTransport(DirectionType direction) {
|
||||||
|
if (EntityLiner == null || _StartPosX == null || _StartPosY == null)
|
||||||
|
return false;
|
||||||
|
switch (direction) {
|
||||||
|
case Left:
|
||||||
|
if (_StartPosX - EntityLiner.Step > -40) {
|
||||||
|
_StartPosX -= (int) EntityLiner.Step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case Up:
|
||||||
|
if (_StartPosY - EntityLiner.Step > -40) {
|
||||||
|
_StartPosY -= (int) EntityLiner.Step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case Right:
|
||||||
|
if (_StartPosX + drawningLinerWidth + (int) EntityLiner.Step < picture_width
|
||||||
|
- EntityLiner.Step) {
|
||||||
|
_StartPosX += (int) EntityLiner.Step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case Down:
|
||||||
|
if (_StartPosY + drawningLinerHeight + (int) EntityLiner.Step < picture_height
|
||||||
|
- EntityLiner.Step) {
|
||||||
|
_StartPosY += (int) EntityLiner.Step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DrawTransport(Graphics2D g) {
|
||||||
|
|
||||||
|
if (EntityLiner == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
g.setColor(EntityLiner.getAdditionalColor());
|
||||||
|
_deck.Draw(g, _StartPosX, _StartPosY);
|
||||||
|
g.setColor(EntityLiner.getBodyColor());
|
||||||
|
|
||||||
|
int[] xPoints = { _StartPosX + 40, _StartPosX + 60, _StartPosX + 60 };
|
||||||
|
int[] yPoints = { _StartPosY + 80, _StartPosY + 80, _StartPosY + 120 };
|
||||||
|
g.drawPolygon(xPoints, yPoints, 3);
|
||||||
|
g.fillPolygon(xPoints, yPoints, 3);
|
||||||
|
|
||||||
|
xPoints = new int[] { _StartPosX + 40 + 100, _StartPosX + 60 + 100, _StartPosX + 40 + 100 };
|
||||||
|
yPoints = new int[] { _StartPosY + 80, _StartPosY + 80, _StartPosY + 120 };
|
||||||
|
g.drawPolygon(xPoints, yPoints, 3);
|
||||||
|
g.fillPolygon(xPoints, yPoints, 3);
|
||||||
|
|
||||||
|
g.drawRect(_StartPosX + 60, _StartPosY + 80, 80, 40);
|
||||||
|
g.fillRect(_StartPosX + 60, _StartPosY + 80, 80, 40);
|
||||||
|
|
||||||
|
if (EntityLiner.getAnchor()) {
|
||||||
|
g.setColor(EntityLiner.getAdditionalColor());
|
||||||
|
g.drawLine(_StartPosX + 70, _StartPosY + 85, _StartPosX + 70, _StartPosY + 110);
|
||||||
|
g.drawLine(_StartPosX + 60, _StartPosY + 90, _StartPosX + 80, _StartPosY + 90);
|
||||||
|
g.drawLine(_StartPosX + 60, _StartPosY + 100, _StartPosX + 70, _StartPosY + 110);
|
||||||
|
g.drawLine(_StartPosX + 70, _StartPosY + 110, _StartPosX + 80, _StartPosY + 100);
|
||||||
|
}
|
||||||
|
// отрисовка шлюпок
|
||||||
|
if (EntityLiner.getBoats()) {
|
||||||
|
g.setColor(EntityLiner.getAdditionalColor());
|
||||||
|
g.fillOval(_StartPosX + 80, _StartPosY + 80, 30, 20);
|
||||||
|
g.fillOval(_StartPosX + 120, _StartPosY + 80, 30, 20);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
37
ProjectLiner/src/EntityLiner.java
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class EntityLiner {
|
||||||
|
private int Speed;
|
||||||
|
private double Weight;
|
||||||
|
private Color BodyColor;
|
||||||
|
private Color AdditionalColor;
|
||||||
|
private boolean Boats;
|
||||||
|
private boolean Anchor;
|
||||||
|
public double Step;
|
||||||
|
|
||||||
|
public Color getBodyColor() {
|
||||||
|
return BodyColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Color getAdditionalColor() {
|
||||||
|
return AdditionalColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getBoats() {
|
||||||
|
return Boats;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getAnchor() {
|
||||||
|
return Anchor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Init(int Speed, double Weight, Color Bodycolor, Color Additionalcolor, boolean Boats, boolean Anchor) {
|
||||||
|
this.Speed = Speed;
|
||||||
|
this.Weight = Weight;
|
||||||
|
this.BodyColor = Bodycolor;
|
||||||
|
this.AdditionalColor = Additionalcolor;
|
||||||
|
this.Boats = Boats;
|
||||||
|
this.Anchor = Anchor;
|
||||||
|
Step = Speed * 100 / Weight;
|
||||||
|
}
|
||||||
|
}
|
138
ProjectLiner/src/FormLiner.java
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.ComponentAdapter;
|
||||||
|
import java.awt.event.ComponentEvent;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class FormLiner extends JFrame {
|
||||||
|
private String title;
|
||||||
|
private Dimension dimension;
|
||||||
|
private int Width, Height;
|
||||||
|
private CanvasLiner canvasLiner = new CanvasLiner();
|
||||||
|
private JButton CreateButton = new JButton("Создать");;
|
||||||
|
private JButton UpButton = new JButton();
|
||||||
|
private JButton DownButton = new JButton();;
|
||||||
|
private JButton LeftButton = new JButton();;
|
||||||
|
private JButton RightButton = new JButton();
|
||||||
|
|
||||||
|
public FormLiner(String title, Dimension dimension) {
|
||||||
|
this.title = title;
|
||||||
|
this.dimension = dimension;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Init() {
|
||||||
|
setTitle(title);
|
||||||
|
setMinimumSize(dimension);
|
||||||
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
Width = getWidth() - 15;
|
||||||
|
Height = getHeight() - 35;
|
||||||
|
|
||||||
|
Dimension dimen = new Dimension(50, 50);
|
||||||
|
|
||||||
|
CreateButton.setName("CREATE");
|
||||||
|
Icon iconUp = new ImageIcon(
|
||||||
|
"E:\\Проекты\\ООП Java\\Pibd_13_Fathutdinov.A.I_Hard\\ProjectLiner\\src\\images\\up.png");
|
||||||
|
UpButton.setIcon(iconUp);
|
||||||
|
UpButton.setName("UP");
|
||||||
|
UpButton.setPreferredSize(dimen);
|
||||||
|
DownButton.setName("DOWN");
|
||||||
|
Icon iconDown = new ImageIcon(
|
||||||
|
"E:\\Проекты\\ООП Java\\Pibd_13_Fathutdinov.A.I_Hard\\ProjectLiner\\src\\images\\down.png");
|
||||||
|
DownButton.setIcon(iconDown);
|
||||||
|
LeftButton.setName("LEFT");
|
||||||
|
Icon iconLeft = new ImageIcon(
|
||||||
|
"E:\\Проекты\\ООП Java\\Pibd_13_Fathutdinov.A.I_Hard\\ProjectLiner\\src\\images\\left.png");
|
||||||
|
LeftButton.setIcon(iconLeft);
|
||||||
|
RightButton.setName("RIGHT");
|
||||||
|
Icon iconRight = new ImageIcon(
|
||||||
|
"E:\\Проекты\\ООП Java\\Pibd_13_Fathutdinov.A.I_Hard\\ProjectLiner\\src\\images\\right.png");
|
||||||
|
RightButton.setIcon(iconRight);
|
||||||
|
|
||||||
|
CreateButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
int StartPositionX = (int) (Math.random() * 90 + 10);
|
||||||
|
int StartPositionY = (int) (Math.random() * 90 + 10);
|
||||||
|
int speed = (int) (Math.random() * 300 + 100);
|
||||||
|
double weight = (double) (Math.random() * 3000 + 1000);
|
||||||
|
Color bodyColor = new Color((int) (Math.random() * 255 + 0), (int) (Math.random() * 255 + 0),
|
||||||
|
(int) (Math.random() * 255 + 0));
|
||||||
|
Color additionalColor = new Color((int) (Math.random() * 255 + 0), (int) (Math.random() * 255 + 0),
|
||||||
|
(int) (Math.random() * 255 + 0));
|
||||||
|
;
|
||||||
|
boolean tower = new Random().nextBoolean();
|
||||||
|
boolean radar = new Random().nextBoolean();
|
||||||
|
;
|
||||||
|
canvasLiner._drawingLiner = new DrawningLiner();
|
||||||
|
canvasLiner._drawingLiner.Init(speed, weight, bodyColor, additionalColor, tower,
|
||||||
|
radar);
|
||||||
|
canvasLiner._drawingLiner.SetPictureSize(Width, Height);
|
||||||
|
canvasLiner._drawingLiner.SetPosition(StartPositionX, StartPositionY);
|
||||||
|
canvasLiner.repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ActionListener actionListener = new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent event) {
|
||||||
|
if (canvasLiner._drawingLiner == null)
|
||||||
|
return;
|
||||||
|
boolean result = false;
|
||||||
|
switch ((((JButton) (event.getSource())).getName())) {
|
||||||
|
case "UP":
|
||||||
|
result = canvasLiner._drawingLiner.MoveTransport(DirectionType.Up);
|
||||||
|
break;
|
||||||
|
case "DOWN":
|
||||||
|
result = canvasLiner._drawingLiner.MoveTransport(DirectionType.Down);
|
||||||
|
break;
|
||||||
|
case "LEFT":
|
||||||
|
result = canvasLiner._drawingLiner.MoveTransport(DirectionType.Left);
|
||||||
|
break;
|
||||||
|
case "RIGHT":
|
||||||
|
result = canvasLiner._drawingLiner.MoveTransport(DirectionType.Right);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (result) {
|
||||||
|
canvasLiner.repaint();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
UpButton.addActionListener(actionListener);
|
||||||
|
DownButton.addActionListener(actionListener);
|
||||||
|
LeftButton.addActionListener(actionListener);
|
||||||
|
RightButton.addActionListener(actionListener);
|
||||||
|
|
||||||
|
setSize(dimension.width, dimension.height);
|
||||||
|
setLayout(null);
|
||||||
|
canvasLiner.setBounds(0, 0, getWidth(), getHeight());
|
||||||
|
CreateButton.setBounds(10, getHeight() - 90, 100, 40);
|
||||||
|
UpButton.setBounds(getWidth() - 140, getHeight() - 160, 50, 50);
|
||||||
|
DownButton.setBounds(getWidth() - 140, getHeight() - 100, 50, 50);
|
||||||
|
RightButton.setBounds(getWidth() - 80, getHeight() - 100, 50, 50);
|
||||||
|
LeftButton.setBounds(getWidth() - 200, getHeight() - 100, 50, 50);
|
||||||
|
add(CreateButton);
|
||||||
|
add(UpButton);
|
||||||
|
add(DownButton);
|
||||||
|
add(RightButton);
|
||||||
|
add(LeftButton);
|
||||||
|
add(canvasLiner);
|
||||||
|
setVisible(true);
|
||||||
|
// обработка события изменения размеров окна
|
||||||
|
addComponentListener(new ComponentAdapter() {
|
||||||
|
public void componentResized(ComponentEvent e) {
|
||||||
|
Width = getWidth() - 15;
|
||||||
|
Height = getHeight() - 35;
|
||||||
|
if (canvasLiner._drawingLiner != null)
|
||||||
|
canvasLiner._drawingLiner.SetPictureSize(Width, Height);
|
||||||
|
canvasLiner.setBounds(0, 0, getWidth(), getHeight());
|
||||||
|
CreateButton.setBounds(10, getHeight() - 90, 100, 40);
|
||||||
|
UpButton.setBounds(getWidth() - 140, getHeight() - 160, 50, 50);
|
||||||
|
DownButton.setBounds(getWidth() - 140, getHeight() - 100, 50, 50);
|
||||||
|
RightButton.setBounds(getWidth() - 80, getHeight() - 100, 50, 50);
|
||||||
|
LeftButton.setBounds(getWidth() - 200, getHeight() - 100, 50, 50);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
8
ProjectLiner/src/Main.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
FormLiner form = new FormLiner("Лайнер", new Dimension(600, 400));
|
||||||
|
form.Init();
|
||||||
|
}
|
||||||
|
}
|
BIN
ProjectLiner/src/images/arrowDown.jpg
Normal file
After Width: | Height: | Size: 61 KiB |
BIN
ProjectLiner/src/images/arrowLeft.jpg
Normal file
After Width: | Height: | Size: 60 KiB |
BIN
ProjectLiner/src/images/arrowRight.jpg
Normal file
After Width: | Height: | Size: 60 KiB |
BIN
ProjectLiner/src/images/arrowUp.jpg
Normal file
After Width: | Height: | Size: 61 KiB |
BIN
ProjectLiner/src/images/bottom.png
Normal file
After Width: | Height: | Size: 5.7 KiB |
BIN
ProjectLiner/src/images/down.png
Normal file
After Width: | Height: | Size: 278 B |
BIN
ProjectLiner/src/images/left.png
Normal file
After Width: | Height: | Size: 285 B |
BIN
ProjectLiner/src/images/right.png
Normal file
After Width: | Height: | Size: 282 B |
BIN
ProjectLiner/src/images/top.png
Normal file
After Width: | Height: | Size: 5.5 KiB |
BIN
ProjectLiner/src/images/up.png
Normal file
After Width: | Height: | Size: 305 B |