From b3a579a55d56fb61ad95433f5a814b98d0742ab0 Mon Sep 17 00:00:00 2001 From: Nikita Potapov <47923521+nikita-potapov@users.noreply.github.com> Date: Sun, 27 Nov 2022 11:31:05 +0400 Subject: [PATCH] gui form --- Resources/30px_arrow_down.png | Bin 0 -> 244 bytes Resources/30px_arrow_left.png | Bin 0 -> 249 bytes Resources/30px_arrow_right.png | Bin 0 -> 254 bytes Resources/30px_arrow_up.png | Bin 0 -> 257 bytes Direction.java => src/Direction.java | 2 + src/DrawingBoat.java | 100 +++++++++++++++++ EntityBoat.java => src/EntityBoat.java | 2 + src/FormBoat.form | 142 +++++++++++++++++++++++++ src/FormBoat.java | 18 ++++ src/Program.java | 16 +++ 10 files changed, 280 insertions(+) create mode 100644 Resources/30px_arrow_down.png create mode 100644 Resources/30px_arrow_left.png create mode 100644 Resources/30px_arrow_right.png create mode 100644 Resources/30px_arrow_up.png rename Direction.java => src/Direction.java (82%) create mode 100644 src/DrawingBoat.java rename EntityBoat.java => src/EntityBoat.java (96%) create mode 100644 src/FormBoat.form create mode 100644 src/FormBoat.java create mode 100644 src/Program.java diff --git a/Resources/30px_arrow_down.png b/Resources/30px_arrow_down.png new file mode 100644 index 0000000000000000000000000000000000000000..7aa32554361c5096853e1a67276f0da08b666977 GIT binary patch literal 244 zcmeAS@N?(olHy`uVBq!ia0vp^av;pX1SGcvS$+jloCO|{#S9EWB_ParFHODzD7ehi z#WBRA^X*kbp=JXf7Kd0h`vptS{Ev6>oNcbb%E+|MPpGHcASSz#`|J;%(5YsXCPlX| z`4_P%I7MiuZt2+bTU`Fdv4d8>&d1*W;u}9PPQGe`;i)O&%fk-l?_?tRPSx1g-h*@y$HPFQjp00i_>zopr0ChuOg8%>k literal 0 HcmV?d00001 diff --git a/Resources/30px_arrow_left.png b/Resources/30px_arrow_left.png new file mode 100644 index 0000000000000000000000000000000000000000..9a3dfa2d5b89d36919b575b8befd59eac504d75e GIT binary patch literal 249 zcmeAS@N?(olHy`uVBq!ia0vp^av;pX1SGcvS$+jloCO|{#S9EWB_ParFHODzD7f0w z#WBRA^X#>QybT5%tN{jj53Vl$?f>NBYU3JyHPf{jOaH1E9mr;8UB#fH)~4{?e9Nk~ z3vu7I*RJ}#=fg|0?SAIFMRy$+op|wSoo3oAN7LOKf9|`yP3?k*N4i|l6qD1snTuv$ zjQPIkG?%%2RWks*vIi`7u`I25Nb!YfkCWjxp-pybJbT)&htDnm{r-UW|LqcYO literal 0 HcmV?d00001 diff --git a/Resources/30px_arrow_right.png b/Resources/30px_arrow_right.png new file mode 100644 index 0000000000000000000000000000000000000000..0f06fd0640536a7d699730ab5c192deace71668e GIT binary patch literal 254 zcmeAS@N?(olHy`uVBq!ia0vp^av;pX1SGcvS$+jloCO|{#S9EWB_ParFHODzD7eAX z#WBRA^XxT4z6Jvh)_|-%jjI=bx1YFpb^3~CPt}aK?DfJkWxjYWSfKe_r#9)ulU*;T z1nJ*ey8C5qoP%vpb^!l2!HbX8m#pl6dg^NJ+Ush`CfkKd51qK8b$I46_qk>-%IEHM z?(vKBk5a#UdE2zhhn8$Ty`DMcsJ{i>))#S@ZE}gjVI~7y13T$wCnDw z&$r3~qp!cW(aU;qs`b8Ww3U7Dt`)1|``+zbapnATLGje8$_2ra-H>* zUI~?GXQRn!Gfhq}iHuuhtC_8P?QX(9kLP=sy=Fd8(=v6@0lJXE)78&qol`;+0Nwv% AVgLXD literal 0 HcmV?d00001 diff --git a/Direction.java b/src/Direction.java similarity index 82% rename from Direction.java rename to src/Direction.java index a641b80..5391974 100644 --- a/Direction.java +++ b/src/Direction.java @@ -1,3 +1,5 @@ +package src; + public enum Direction { Up, Down, diff --git a/src/DrawingBoat.java b/src/DrawingBoat.java new file mode 100644 index 0000000..1e59761 --- /dev/null +++ b/src/DrawingBoat.java @@ -0,0 +1,100 @@ +package src; + +import java.awt.*; + +public class DrawingBoat { + public EntityBoat Boat; + private float _startPosX; + private float _startPosY; + private int _pictureWidth = 0; + private int _pictureHeight = 0; + private final int _boatWidth = 100; + private final int _boatHeight = 40; + + public void Init(int speed, float weight, Color bodyColor) { + Boat = new EntityBoat(); + Boat.Init(speed, weight, bodyColor); + } + + public void SetPosition(int x, int y, int width, int height) { + if (x > 0 && x < width - _boatWidth && y > 0 && y < height - _boatHeight) { + _startPosX = x; + _startPosY = y; + _pictureWidth = width; + _pictureHeight = height; + } + } + + public void MoveTransport(Direction direction) { + if (_pictureWidth == 0 || _pictureHeight == 0) { + return; + } + switch (direction) { + case Right: + if (_startPosX + _boatWidth + Boat.Step < _pictureWidth) { + _startPosX += Boat.Step; + } + break; + case Left: + if (_startPosX - Boat.Step > 0) { + _startPosX -= Boat.Step; + } + break; + case Up: + if (_startPosY - Boat.Step > 0) { + _startPosY -= Boat.Step; + } + break; + case Down: + if (_startPosY + _boatHeight + Boat.Step < _pictureHeight) { + _startPosY += Boat.Step; + } + break; + } + } + + public void DrawTransport(Graphics g) + { + if (_startPosX < 0 || _startPosY < 0 + || _pictureHeight == 0 || _pictureWidth == 0) + { + return; + } +// todo доделать прорисовку + +// SolidBrush brush = new SolidBrush(Boat.BodyColor); +// +// PointF[] bodyPoints = new PointF[5]; +// bodyPoints[0] = new PointF(_startPosX, _startPosY); +// bodyPoints[1] = new PointF(_startPosX + _boatWidth - _boatWidth / 4, _startPosY); +// bodyPoints[2] = new PointF(_startPosX + _boatWidth, _startPosY + _boatHeight / 2); +// bodyPoints[3] = new PointF(_startPosX + _boatWidth - _boatWidth / 4, _startPosY + _boatHeight); +// bodyPoints[4] = new PointF(_startPosX, _startPosY + _boatHeight); +// +// // Отрисовка корпуса лодки +// g.FillPolygon(brush, bodyPoints); +// g.DrawPolygon(Pens.Black, bodyPoints); +// +// // Отрисовка головы лодки +// g.FillEllipse(Brushes.White, _startPosX + _boatWidth / 8, _startPosY + _boatHeight / 8, +// _boatWidth / 2, _boatHeight - _boatHeight / 4); +// g.DrawEllipse(Pens.Black, _startPosX + _boatWidth / 8, _startPosY + _boatHeight / 8, +// _boatWidth / 2, _boatHeight - _boatHeight / 4); + } + + public void ChangeBorders(int width, int height) { + _pictureWidth = width; + _pictureHeight = height; + if (_pictureWidth <= _boatWidth || _pictureHeight <= _boatHeight) { + _pictureWidth = 0; + _pictureHeight = 0; + return; + } + if (_startPosX + _boatWidth > _pictureWidth) { + _startPosX = _pictureWidth - _boatWidth; + } + if (_startPosY + _boatHeight > _pictureHeight) { + _startPosY = _pictureHeight - _boatHeight; + } + } +} diff --git a/EntityBoat.java b/src/EntityBoat.java similarity index 96% rename from EntityBoat.java rename to src/EntityBoat.java index 949e88e..899cf03 100644 --- a/EntityBoat.java +++ b/src/EntityBoat.java @@ -1,3 +1,5 @@ +package src; + import java.awt.*; import java.util.Random; diff --git a/src/FormBoat.form b/src/FormBoat.form new file mode 100644 index 0000000..7dd7ac3 --- /dev/null +++ b/src/FormBoat.form @@ -0,0 +1,142 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/FormBoat.java b/src/FormBoat.java new file mode 100644 index 0000000..7e4b68a --- /dev/null +++ b/src/FormBoat.java @@ -0,0 +1,18 @@ +package src; + +import javax.swing.*; + +public class FormBoat { + JPanel PanelWrapper; + private JPanel PictureBox; + private JToolBar StatusStrip; + private JLabel StatusStripLabelSpeed; + private JLabel StatusStripLabelWeight; + private JLabel StatusStripLabelColor; + private JButton ButtonCreate; + private JPanel PanelButtonsMove; + private JButton ButtonDown; + private JButton ButtonUp; + private JButton ButtonLeft; + private JButton ButtonRight; +} diff --git a/src/Program.java b/src/Program.java new file mode 100644 index 0000000..d8d19a6 --- /dev/null +++ b/src/Program.java @@ -0,0 +1,16 @@ +package src; + +import javax.swing.*; + +public class Program { + public static void main(String[] args) { + JFrame.setDefaultLookAndFeelDecorated(false); + JFrame frame = new JFrame("Катамаран"); + frame.setContentPane(new FormBoat().PanelWrapper); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setLocation(500, 200); + frame.pack(); + frame.setSize(1000, 500); + frame.setVisible(true); + } +}