From 62b3b3129eb556dbd42b4f2dc27ae17f904a2cce Mon Sep 17 00:00:00 2001 From: ArtemEmelyanov Date: Wed, 16 Nov 2022 16:44:07 +0400 Subject: [PATCH] first lab complete --- .idea/.gitignore | 3 + .idea/ProjectAirbus.iml | 11 +++ .idea/misc.xml | 6 ++ .idea/modules.xml | 8 +++ .idea/vcs.xml | 6 ++ Direction.java | 7 ++ DrawningIlluminator.java | 36 ++++++++++ DrawningPlane.java | 145 +++++++++++++++++++++++++++++++++++++++ EntityPlane.java | 29 ++++++++ FormPlane.form | 103 +++++++++++++++++++++++++++ FormPlane.java | 80 +++++++++++++++++++++ IlluminatorCount.java | 22 ++++++ Main.java | 14 ++++ Resource/arrowDown.jpg | Bin 0 -> 1249 bytes Resource/arrowLeft.jpg | Bin 0 -> 1255 bytes Resource/arrowRight.jpg | Bin 0 -> 1253 bytes Resource/arrowUp.jpg | Bin 0 -> 1232 bytes 17 files changed, 470 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/ProjectAirbus.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 Direction.java create mode 100644 DrawningIlluminator.java create mode 100644 DrawningPlane.java create mode 100644 EntityPlane.java create mode 100644 FormPlane.form create mode 100644 FormPlane.java create mode 100644 IlluminatorCount.java create mode 100644 Main.java create mode 100644 Resource/arrowDown.jpg create mode 100644 Resource/arrowLeft.jpg create mode 100644 Resource/arrowRight.jpg create mode 100644 Resource/arrowUp.jpg diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/ProjectAirbus.iml b/.idea/ProjectAirbus.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/.idea/ProjectAirbus.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..104cfef --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..bed92e1 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Direction.java b/Direction.java new file mode 100644 index 0000000..d82266b --- /dev/null +++ b/Direction.java @@ -0,0 +1,7 @@ +public enum Direction { + Up(1), + Down(2), + Left(3), + Right(4); + Direction(int value){} +} \ No newline at end of file diff --git a/DrawningIlluminator.java b/DrawningIlluminator.java new file mode 100644 index 0000000..86de975 --- /dev/null +++ b/DrawningIlluminator.java @@ -0,0 +1,36 @@ +import javax.swing.*; +import java.awt.*; + +public class DrawningIlluminator extends JComponent { + private IlluminatorCount _Illuminator; + + public void SetIlluminatorCount(int numOfIllum) { + _Illuminator = IlluminatorCount.GetIlluminatorCount(numOfIllum); + } + + public void DrawIlluminator(Graphics g, int _startPosX, int _startPosY) { + super.paintComponent(g); + Graphics2D g2d = (Graphics2D) g; + g2d.setColor(Color.BLACK); + int numOfIlluminator = 0; + switch (_Illuminator) + { + case Ten: + numOfIlluminator = 10; + break; + case Twenty: + numOfIlluminator = 20; + break; + case Thirty: + numOfIlluminator = 30; + break; + } + + for(int i = numOfIlluminator; i >= 1; --i){ + g2d.setColor(Color.CYAN); + g2d.fillOval(_startPosX + 105 - 3 * i, _startPosY + 35, 3, 3); + g2d.setColor(Color.BLACK); + g2d.drawOval(_startPosX + 105 - 3 * i, _startPosY + 35, 3, 3); + } + } +} diff --git a/DrawningPlane.java b/DrawningPlane.java new file mode 100644 index 0000000..6600f0a --- /dev/null +++ b/DrawningPlane.java @@ -0,0 +1,145 @@ +import javax.swing.*; +import java.awt.*; +import java.util.Random; +import java.util.random.RandomGenerator; + +public class DrawningPlane extends JPanel { + + private EntityPlane Plane; + public EntityPlane GetPlane(){ + return Plane; + } + + private int _startPosX; + private int _startPosY; + public DrawningIlluminator IlluminatorDraw; + public Integer _pictureWidth = null; + public Integer _pictureHeight = null; + private final int _PlaneWidth = 130; + private final int _PlaneHeight = 70; + + public void SetIlluminator() { + Random r = new Random(); + int numIllum = r.nextInt(1,4); + numIllum = numIllum * 10; + IlluminatorDraw.SetIlluminatorCount(numIllum); + } + + public void Init(int speed, float weight, Color bodyColor) + { + Plane = new EntityPlane(); + Plane.Init(speed, weight, bodyColor); + IlluminatorDraw = new DrawningIlluminator(); + SetIlluminator(); + } + + public void SetPosition(int x, int y, int width, int height) + { + if (x >= 0 && x + _PlaneWidth <= width && y >= 0 && y + _PlaneHeight <= height) { + _startPosX = x; + _startPosY = y; + _pictureWidth = width; + _pictureHeight = height; + } + } + + public void MoveTransport(Direction direction) + { + if (_pictureWidth == null || _pictureHeight == null) + { + return; + } + switch (direction) + { + case Right: + if (_startPosX + _PlaneWidth + Plane.Step < _pictureWidth) + { + _startPosX += Plane.Step; + } + break; + case Left: + if (_startPosX - Plane.Step > 0) + { + _startPosX -= Plane.Step; + } + break; + case Up: + if (_startPosY - Plane.Step > 0) + { + _startPosY -= Plane.Step; + } + break; + case Down: + if (_startPosY + _PlaneHeight + Plane.Step < _pictureHeight) + { + _startPosY += Plane.Step; + } + break; + } + } + + public void DrawTransport() { + if (_startPosX < 0 || _startPosY < 0 || _pictureWidth == null || _pictureHeight == null) { + return; + } + repaint(); + } + @Override + public void paintComponent(Graphics g) { + if (GetPlane() == null) { + return; + } + if (_startPosX < 0 || _startPosY < 0 || _pictureWidth == null || _pictureHeight == null) { + return; + } + super.paintComponent(g); + Graphics2D g2d = (Graphics2D) g; + + g2d.setColor(Color.BLACK); + g2d.drawOval(_startPosX, _startPosY + 30, 20, 20); + g2d.drawRect(_startPosX + 10, _startPosY + 30, 100, 20); + + g2d.drawLine(_startPosX + 110, _startPosY + 30, _startPosX + 130, _startPosY+40); + g2d.drawLine(_startPosX + 110, _startPosY+50, _startPosX + 130, _startPosY+40); + + g2d.drawLine(_startPosX, _startPosY, _startPosX, _startPosY+40); + g2d.drawLine(_startPosX, _startPosY, _startPosX + 30, _startPosY+30); + + g2d.drawLine(_startPosX + 40, _startPosY + 50, _startPosX + 40, _startPosY+55); + g2d.drawLine(_startPosX + 100, _startPosY + 50, _startPosX + 100, _startPosY+55); + + g2d.drawOval(_startPosX + 95, _startPosY + 55, 10, 10); + g2d.drawOval(_startPosX + 29, _startPosY + 55, 10, 10); + g2d.drawOval(_startPosX + 41, _startPosY + 55, 10, 10); + + g2d.setPaint(Plane.GetBodyColor()); + g2d.fillOval(_startPosX, _startPosY + 31, 20, 19); + g2d.fillRect(_startPosX + 10, _startPosY + 31, 100, 19); + + g2d.setPaint(Color.BLACK); + g2d.fillOval(_startPosX + 40, _startPosY + 40, 60, 5); + g2d.fillOval(_startPosX - 5, _startPosY + 25, 30, 10); + + IlluminatorDraw.DrawIlluminator(g, _startPosX, _startPosY); + } + + public void ChangeBorders(int width, int height) + { + _pictureWidth = width; + _pictureHeight = height; + if (_pictureWidth <= _PlaneWidth || _pictureHeight <= _PlaneHeight) + { + _pictureWidth = null; + _pictureHeight = null; + return; + } + if (_startPosX + _PlaneWidth > _pictureWidth) + { + _startPosX = _pictureWidth - _PlaneWidth; + } + if (_startPosY + _PlaneHeight > _pictureHeight) + { + _startPosY = _pictureHeight - _PlaneHeight; + } + } +} diff --git a/EntityPlane.java b/EntityPlane.java new file mode 100644 index 0000000..dd00e40 --- /dev/null +++ b/EntityPlane.java @@ -0,0 +1,29 @@ +import java.awt.*; +import java.util.Random; + +public class EntityPlane { + private int Speed; + public int GetSpeed() { + return Speed; + } + + private float Weight; + public float GetWeight() { + return Weight; + } + + private Color BodyColor; + public Color GetBodyColor() { + return BodyColor; + } + public float Step; + + public void Init(int speed, float weight, Color bodyColor) + { + Random rnd = new Random(); + Speed = speed <= 0 ? rnd.nextInt(50,150) : speed; + Weight = weight <= 0 ? rnd.nextInt(40,70) : weight; + BodyColor = bodyColor; + Step = Speed * 100 / (int)Weight; + } +} diff --git a/FormPlane.form b/FormPlane.form new file mode 100644 index 0000000..4e8ede6 --- /dev/null +++ b/FormPlane.form @@ -0,0 +1,103 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/FormPlane.java b/FormPlane.java new file mode 100644 index 0000000..b4f9c5f --- /dev/null +++ b/FormPlane.java @@ -0,0 +1,80 @@ +import javax.imageio.ImageIO; +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 FormPlane { + public JPanel Mainpanel; + private JButton ButtonCreate; + private JButton ButtonLeft; + private JButton ButtonUp; + private JButton ButtonDown; + private JButton ButtonRight; + protected DrawningPlane PictureBoxPlane; + private JToolBar StatusStrip; + private JLabel JLabelSpeed = new JLabel(); + private JLabel JLabelWeight = new JLabel(); + private JLabel JLabelColor = new JLabel(); + public void Draw() { + if (PictureBoxPlane.GetPlane() == null) { + return; + } + PictureBoxPlane.DrawTransport(); + } + public FormPlane() { + Box LabelBox = Box.createHorizontalBox(); + LabelBox.setMinimumSize(new Dimension(1, 20)); + LabelBox.add(JLabelSpeed); + LabelBox.add(JLabelWeight); + LabelBox.add(JLabelColor); + StatusStrip.add(LabelBox); + try { + Image img = ImageIO.read(FormPlane.class.getResource("/Resource/arrowUp.jpg")); + ButtonUp.setIcon(new ImageIcon(img)); + img = ImageIO.read(FormPlane.class.getResource("/Resource/arrowDown.jpg")); + ButtonDown.setIcon(new ImageIcon(img)); + img = ImageIO.read(FormPlane.class.getResource("/Resource/arrowLeft.jpg")); + ButtonLeft.setIcon(new ImageIcon(img)); + img = ImageIO.read(FormPlane.class.getResource("/Resource/arrowRight.jpg")); + ButtonRight.setIcon(new ImageIcon(img)); + } catch (Exception ex) { + System.out.println(ex); + } + ButtonCreate.addActionListener(e -> { + Random random = new Random(); + PictureBoxPlane.Init(random.nextInt(100, 300), random.nextInt(1000, 2000), new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256))); + PictureBoxPlane.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100), PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight()); + JLabelSpeed.setText("Cкорость: " + PictureBoxPlane.GetPlane().GetSpeed() + " "); + JLabelWeight.setText("Вес: " + PictureBoxPlane.GetPlane().GetWeight() + " "); + JLabelColor.setText(("Цвет: " + PictureBoxPlane.GetPlane().GetBodyColor() + " ")); + Draw(); + }); + PictureBoxPlane.addComponentListener(new ComponentAdapter() { + @Override + public void componentResized(ComponentEvent e) { + super.componentResized(e); + PictureBoxPlane.ChangeBorders(PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight()); + Draw(); + } + }); + ButtonUp.addActionListener(e -> { + PictureBoxPlane.MoveTransport(Direction.Up); + Draw(); + }); + ButtonDown.addActionListener(e -> { + PictureBoxPlane.MoveTransport(Direction.Down); + Draw(); + }); + ButtonRight.addActionListener(e -> { + PictureBoxPlane.MoveTransport(Direction.Right); + Draw(); + }); + ButtonLeft.addActionListener(e -> { + PictureBoxPlane.MoveTransport(Direction.Left); + Draw(); + }); + } +} diff --git a/IlluminatorCount.java b/IlluminatorCount.java new file mode 100644 index 0000000..7beef64 --- /dev/null +++ b/IlluminatorCount.java @@ -0,0 +1,22 @@ +public enum IlluminatorCount { + Ten, + Twenty, + Thirty; + + public static IlluminatorCount GetIlluminatorCount(int Value) + { + switch(Value) + { + case 10: + return Ten; + + case 20: + return Twenty; + + case 30: + return Thirty; + + } + return null; + } +} diff --git a/Main.java b/Main.java new file mode 100644 index 0000000..dfdda90 --- /dev/null +++ b/Main.java @@ -0,0 +1,14 @@ +import javax.swing.*; + +public class Main { + + public static void main(String[] args) { + JFrame frame = new JFrame("Корабль"); + frame.setContentPane(new FormPlane().Mainpanel); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setLocation(500, 200); + frame.pack(); + frame.setSize(800, 600); + frame.setVisible(true); + } +} diff --git a/Resource/arrowDown.jpg b/Resource/arrowDown.jpg new file mode 100644 index 0000000000000000000000000000000000000000..2751bb701d3614245906f1eb5c072cc368cd8496 GIT binary patch literal 1249 zcmex=kR1VRR8 zMg~?en}H#WnHeMk#teZ15H?64P>_KIBF=XtPzb>WiUC!(Enr~S*#G}FgEIpYBO?ew z0W&Kz2(YoRFtf6=v9p6P2PZct2L~4iJ3ALI7Z*1V5U_Ld@$>TVf!H8JK-xjNfQW~K zodcwTH1PibgCGZk9D^J)qY?v?AS1INnAuRebI{N?Mn?>~P20{M#(7=%LgJIG&* zOyxk#EXcyDXviky7|5PjD6C}E$RXl1apA^;oXW;QA4HRiE^>*fm^@Vd2=W@(XT*7| zi7cPNJ%;etEe0N7!ekO;7G$tz`1@!5)AoP-(*GHz?7Ufjqj_olOV_vcp7Gn_-*!H@ zf5ZNP+0u{Nj~K5l{Lt2GVwfdfRW?`kb3|v1+a!;PO^56aCvr0s#1m2=)V00avMq?aW9iQH*hvgGm|UJqSlUft{AK!| zfz9GS!-?s?J?pQ3Z?FFnw={mQ=%0Q684j+G{}ArqB>%ztKKGxD?LQ8#&$^{^&v@6x zCzr0B_t>%T^R&DAE=y)iX+1d0es9n7o(GSAW&S9A98st8gW2Vy=-$4y%Wl8ECh$t& zR@OHE)Y_a$3ram7Oki&dkYMXQkdm{S!I6RSpZy29{*V3#W?gUnT$dT#I`sk@&h@~&CCB_`VEMZd!Kd8Ulpm|P}0{Ek0$ZE9Ty_HYj#?cpl>RBFa9uoS+qb<_A2*2XnCYqT?4FsM=WY3`qLun@^nXiL zxc}q)&+uF8hy6qQrra}C`Ymr-^ot&U|F!gT&3ExhpXw`3)_fA+yLv~|Y0;|ws0IB0 GZvp^;hTRAN literal 0 HcmV?d00001 diff --git a/Resource/arrowLeft.jpg b/Resource/arrowLeft.jpg new file mode 100644 index 0000000000000000000000000000000000000000..c25c05c59b4d1609ffff4140ad5fd6bd4e31400d GIT binary patch literal 1255 zcmex=kR1VRR8 zMg~?en}H#WnHeMk#teZ15H?64P>_KIBF=XtPzb>WiUC!(Enr~S*#G}FgEIpYBO?ew z0W&Kz2(YoRFtf6=v9p6P2PZct2L~4iJ3ALI7Z*1V5U_Ld@$>TVf!H8JK-xjNfQW~K zodcwTH1PibgCGZk9D^J)qY?v?AS1INnAuRebI{N?Mn?>~P20{M#(7=%LgJIG&* zOyxk#EXcyDXviky7|5PjD6C}E$RXl1apA^;oXW;QA4HRiE^>*fm^@Vd2=W@(XT*7| zi7cPNJ%;etEe0N7!ekO;7G$tz`1@zQ>fcTO8S?U5>o>3;e7#<#CgNk=%!jdJGD|o4 z{C;ohx#Nh~w%0S&r%&)&Gr%#h{{)gi~ls|u)`p}>E<*(Sa(+|aOdO2-l zl=J?>m#5v7Vu_i*L}7Y-aZymWF>1da`P|;2xc)uYXPe zX{|pfP-hO*saX@Ovd;jdQ|U*2X~Bh;bwHh!CA%k1+^A=9H`AJp`P6jA85X@yL-gZs zu1&AlfAE+85qYkxD8BtmU*3AwzBcM)@`}t`t(#(Q#Ydl5s?ruQM`V(DQ0UY~79kF$ z278u2y#E>4yfgNheDLdEQ-9d))wcf(x2_q)RmOj4al02kQ)=Ixzq{w8i?069AYk!g z|Cgeu<^Kde{%819TK6F{Ds)@x(%TU?56Z5cJI9+v;MndUjVr97fj59<)vYxF?Eh~9 E05>q#%m4rY literal 0 HcmV?d00001 diff --git a/Resource/arrowRight.jpg b/Resource/arrowRight.jpg new file mode 100644 index 0000000000000000000000000000000000000000..195d279ee2272202620c79f7555a99052b7b5a42 GIT binary patch literal 1253 zcmex=kR1VRR8 zMg~?en}H#WnHeMk#teZ15H?64P>_KIBF=XtPzb>WiUC!(Enr~S*#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