From 7042f498fbcfcd2b67a8651e500166eb282ab78b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BE=D0=BB=D0=BE=D0=B4=D1=8F?= Date: Sat, 3 Dec 2022 21:05:02 +0300 Subject: [PATCH 1/3] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=BE=D0=B2?= =?UTF-8?q?=20=D1=81=D1=83=D1=89=D0=BD=D0=BE=D1=81=D1=82=D0=B8,=D0=BE?= =?UTF-8?q?=D1=82=D1=80=D0=B8=D1=81=D0=BE=D0=B2=D0=BA=D0=B8=20=D0=B8=20?= =?UTF-8?q?=D1=84=D0=BE=D1=80=D0=BC=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RadarAirplane/src/Canvas.java | 15 +++ RadarAirplane/src/Direction.java | 6 + RadarAirplane/src/DrawingEntityPlain.java | 127 ++++++++++++++++++++++ RadarAirplane/src/EntityAirPlane.java | 22 ++++ RadarAirplane/src/FormAirPlane.form | 115 ++++++++++++++++++++ RadarAirplane/src/FormAirPlane.java | 95 ++++++++++++++++ RadarAirplane/src/Program.java | 2 +- 7 files changed, 381 insertions(+), 1 deletion(-) create mode 100644 RadarAirplane/src/Canvas.java create mode 100644 RadarAirplane/src/Direction.java create mode 100644 RadarAirplane/src/DrawingEntityPlain.java create mode 100644 RadarAirplane/src/EntityAirPlane.java create mode 100644 RadarAirplane/src/FormAirPlane.form create mode 100644 RadarAirplane/src/FormAirPlane.java diff --git a/RadarAirplane/src/Canvas.java b/RadarAirplane/src/Canvas.java new file mode 100644 index 0000000..e49955e --- /dev/null +++ b/RadarAirplane/src/Canvas.java @@ -0,0 +1,15 @@ +import javax.swing.*; +import java.awt.*; + +public class Canvas extends JComponent { + FormAirPlane form; + public Canvas(FormAirPlane form) { + this.form = form; + } + + @Override + public void paintComponent(Graphics g) { + Graphics2D g2 = (Graphics2D) g; + form.draw(g2); + } +} \ No newline at end of file diff --git a/RadarAirplane/src/Direction.java b/RadarAirplane/src/Direction.java new file mode 100644 index 0000000..870719c --- /dev/null +++ b/RadarAirplane/src/Direction.java @@ -0,0 +1,6 @@ +public enum Direction { + Up, + Right, + Left, + Down +} diff --git a/RadarAirplane/src/DrawingEntityPlain.java b/RadarAirplane/src/DrawingEntityPlain.java new file mode 100644 index 0000000..9cf11c8 --- /dev/null +++ b/RadarAirplane/src/DrawingEntityPlain.java @@ -0,0 +1,127 @@ +import java.awt.*; + +class DrawingEntityPlain +{ + public EntityAirPlane Airplane; + + private float _startPosX; + private float _startPosY; + + private int _pictureWidth = -1; + private int _pictureHeight = -1; + + private int _AirplaneWidth = 120; + private int _AirplaneHeight = 60; + + public void Init(int speed, float weight, Color bodyColor) + { + Airplane = new EntityAirPlane(); + Airplane.Init(speed, weight, bodyColor); + } + + public void SetPosition(int x, int y, int width, int height) + { + if (width < _AirplaneWidth || height < _AirplaneHeight) return; + + if (x + _AirplaneWidth > width || x < 0) return; + if (y + _AirplaneHeight > height || y < 0) return; + + _startPosX = x; + _startPosY = y; + + _pictureWidth = width; + _pictureHeight = height; + } + + public void MoveTransport(Direction direction) + { + if (_pictureWidth == -1 || _pictureHeight == -1) + { + return; + } + + + switch (direction) + { + case Right: + if (_startPosX + _AirplaneWidth + Airplane.Step < _pictureWidth) + { + _startPosX += Airplane.Step; + } + break; + case Left: + if (_startPosX - Airplane.Step > 0) + { + _startPosX -= Airplane.Step; + } + break; + case Up: + if (_startPosY - Airplane.Step > 0) + { + _startPosY -= Airplane.Step; + } + break; + case Down: + if (_startPosY + _AirplaneHeight + Airplane.Step < _pictureHeight) + { + _startPosY += Airplane.Step; + } + break; + } + + } + + public void DrawTransport(Graphics2D g) + { + if (_pictureWidth == -1 || _pictureHeight == -1) + { + return; + } + + + g.drawRect( (int)_startPosX, (int)_startPosY, 20, 30); + g.drawRect( (int)_startPosX, (int)_startPosY + 30, 100, 30); + g.drawRect( (int)_startPosX+100, (int)_startPosY + 40, 20, 15); + //koleso1 + g.drawRect( (int)_startPosX + 30, (int)_startPosY + 60, 5, 10); + g.drawOval( (int)_startPosX+28,(int) _startPosY+70, 9, 9); + //koleso2 + g.drawRect( (int)_startPosX + 80, (int)_startPosY + 60, 5, 10); + g.drawOval( (int)_startPosX + 78, (int)_startPosY + 70, 9, 9); + + //Korpys + g.setPaint(Airplane.BodyColor); + g.fillRect((int)_startPosX+3, (int)_startPosY + 33, 94, 24); + g.fillRect( (int)_startPosX+1, (int)_startPosY+1, 19, 29); + + //krilya + g.setPaint(Color.black); + g.fillRect((int)_startPosX + 30, (int)_startPosY + 40, 40, 8); + + //cabina + g.setPaint(Color.blue); + g.fillRect( (int)_startPosX + 101, (int)_startPosY + 41, 19, 14); + + } + + public void ChangeBorders(int width, int height) + { + _pictureWidth = width; + _pictureHeight = height; + if (_pictureWidth <= _AirplaneWidth || _pictureHeight <= _AirplaneHeight) + { + _pictureWidth = -1; + _pictureHeight = -1; + return; + } + if (_startPosX + _AirplaneWidth > _pictureWidth) + { + _startPosX = _pictureWidth - _AirplaneWidth; + } + if (_startPosY + _AirplaneHeight > _pictureHeight) + { + _startPosY = _pictureHeight - _AirplaneHeight; + } + } + +} \ No newline at end of file diff --git a/RadarAirplane/src/EntityAirPlane.java b/RadarAirplane/src/EntityAirPlane.java new file mode 100644 index 0000000..7559eec --- /dev/null +++ b/RadarAirplane/src/EntityAirPlane.java @@ -0,0 +1,22 @@ +import java.awt.*; +import java.util.Random; + +class EntityAirPlane +{ + public int Speed; + public float Weight; + public Color 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(50, 70) : weight; + BodyColor = bodyColor; + + Step = Speed * 100 / Weight; + } +} diff --git a/RadarAirplane/src/FormAirPlane.form b/RadarAirplane/src/FormAirPlane.form new file mode 100644 index 0000000..7226820 --- /dev/null +++ b/RadarAirplane/src/FormAirPlane.form @@ -0,0 +1,115 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
\ No newline at end of file diff --git a/RadarAirplane/src/FormAirPlane.java b/RadarAirplane/src/FormAirPlane.java new file mode 100644 index 0000000..442cef0 --- /dev/null +++ b/RadarAirplane/src/FormAirPlane.java @@ -0,0 +1,95 @@ +import javax.swing.*; +import javax.swing.border.LineBorder; +import java.awt.*; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; +import java.util.Random; + +public class FormAirPlane { + private JButton createButton; + private JButton upButton; + private JButton rightButton; + private JButton downButton; + private JButton leftButton; + private JPanel mainPanel; + private JPanel DrawPlace; + private JLabel speedLabel; + private JLabel weightLabel; + private JLabel colorLabel; + + DrawingEntityPlain _airPlane; + + + private JFrame jframe = getFrame(); + + private JFrame getFrame() { + JFrame frame = new JFrame(); + frame.setVisible(true); + frame.setBounds(300, 100, 800, 600); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + return frame; + } + + public void run() { + jframe.add(mainPanel); + Canvas canv = new Canvas(this); + DrawPlace.add(canv); + + + createButton.addActionListener(e -> { + Dimension canvSize = canv.getSize(); + Random rnd = new Random(); + + _airPlane = new DrawingEntityPlain(); + + _airPlane.Init(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), + new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256))); + + _airPlane.SetPosition((int)rnd.nextInt(10, 100), (int)rnd.nextInt(10, 100), canvSize.width, canvSize.height); + + Color bodyColor = _airPlane.Airplane.BodyColor; + String colorString = "(" + bodyColor.getRed() + ", " + bodyColor.getGreen() + ", " + bodyColor.getBlue() + ")"; + + speedLabel.setText("Скорость: " + _airPlane.Airplane.Speed + " "); + weightLabel.setText("Вес: " + _airPlane.Airplane.Weight + " "); + colorLabel.setText("Цвет: " + colorString); + + canv.repaint(); + }); + + jframe.addComponentListener(new ComponentAdapter() { + @Override + public void componentResized(ComponentEvent e) { + if(_airPlane == null) return; + _airPlane.ChangeBorders(canv.getSize().width, canv.getSize().height); + jframe.revalidate(); + } + }); + + upButton.addActionListener(e -> { + if(_airPlane == null) return; + _airPlane.MoveTransport(Direction.Up); + canv.repaint(); + }); + rightButton.addActionListener(e -> { + if(_airPlane == null) return; + _airPlane.MoveTransport(Direction.Right); + canv.repaint(); + }); + downButton.addActionListener(e -> { + if(_airPlane == null) return; + _airPlane.MoveTransport(Direction.Down); + canv.repaint(); + }); + leftButton.addActionListener(e -> { + if(_airPlane == null) return; + _airPlane.MoveTransport(Direction.Left); + canv.repaint(); + }); + } + + public void draw(Graphics2D g) { + if(_airPlane == null) return; + _airPlane.DrawTransport(g); + } +} \ No newline at end of file diff --git a/RadarAirplane/src/Program.java b/RadarAirplane/src/Program.java index a30fd5d..113c3d8 100644 --- a/RadarAirplane/src/Program.java +++ b/RadarAirplane/src/Program.java @@ -3,6 +3,6 @@ import java.awt.*; public class Program { public static void main(String[] args) { - System.out.println("Hello world"); + new FormAirPlane().run(); } } \ No newline at end of file -- 2.25.1 From 566571ab192a4f2222ddbe9c73a6cd167f5a1ce7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BE=D0=BB=D0=BE=D0=B4=D1=8F?= Date: Sat, 3 Dec 2022 23:26:09 +0300 Subject: [PATCH 2/3] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0=20?= =?UTF-8?q?=D0=B8=D0=BB=D0=BB=D1=8E=D0=BC=D0=B8=D0=BD=D0=B0=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=20=D0=B8=20=D0=B8=D1=85=20=D0=BE=D1=82=D1=80?= =?UTF-8?q?=D0=B8=D1=81=D0=BE=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RadarAirplane/src/DrawingEntityPlain.java | 33 +++-- RadarAirplane/src/DrawingPorthole.java | 40 ++++++ RadarAirplane/src/FormAirPlane.form | 163 ++++++++++++---------- RadarAirplane/src/Porthole.java | 5 + 4 files changed, 153 insertions(+), 88 deletions(-) create mode 100644 RadarAirplane/src/DrawingPorthole.java create mode 100644 RadarAirplane/src/Porthole.java diff --git a/RadarAirplane/src/DrawingEntityPlain.java b/RadarAirplane/src/DrawingEntityPlain.java index 9cf11c8..b25868b 100644 --- a/RadarAirplane/src/DrawingEntityPlain.java +++ b/RadarAirplane/src/DrawingEntityPlain.java @@ -1,22 +1,24 @@ import java.awt.*; - +import java.util.Random; class DrawingEntityPlain { public EntityAirPlane Airplane; - + public DrawingPorthole drawingPortholes = new DrawingPorthole(); private float _startPosX; private float _startPosY; private int _pictureWidth = -1; private int _pictureHeight = -1; - private int _AirplaneWidth = 120; - private int _AirplaneHeight = 60; + private int _AirplaneWidth = 240; + private int _AirplaneHeight = 120; public void Init(int speed, float weight, Color bodyColor) { + Random rnd = new Random(); Airplane = new EntityAirPlane(); Airplane.Init(speed, weight, bodyColor); + drawingPortholes.Init(rnd.nextInt(1, 35),Airplane.BodyColor); } public void SetPosition(int x, int y, int width, int height) @@ -79,29 +81,30 @@ class DrawingEntityPlain } - g.drawRect( (int)_startPosX, (int)_startPosY, 20, 30); - g.drawRect( (int)_startPosX, (int)_startPosY + 30, 100, 30); - g.drawRect( (int)_startPosX+100, (int)_startPosY + 40, 20, 15); + g.drawRect( (int)_startPosX, (int)_startPosY, 40, 60); + g.drawRect( (int)_startPosX, (int)_startPosY + 60, 200, 60); + g.drawRect( (int)_startPosX+100, (int)_startPosY + 80, 40, 30); //koleso1 - g.drawRect( (int)_startPosX + 30, (int)_startPosY + 60, 5, 10); - g.drawOval( (int)_startPosX+28,(int) _startPosY+70, 9, 9); + g.drawRect( (int)_startPosX + 60, (int)_startPosY + 120, 10, 20); + g.drawOval( (int)_startPosX+56,(int) _startPosY+140, 18, 18); //koleso2 - g.drawRect( (int)_startPosX + 80, (int)_startPosY + 60, 5, 10); - g.drawOval( (int)_startPosX + 78, (int)_startPosY + 70, 9, 9); + g.drawRect( (int)_startPosX + 160, (int)_startPosY + 120, 10, 20); + g.drawOval( (int)_startPosX + 156, (int)_startPosY + 140, 18, 18); //Korpys g.setPaint(Airplane.BodyColor); - g.fillRect((int)_startPosX+3, (int)_startPosY + 33, 94, 24); - g.fillRect( (int)_startPosX+1, (int)_startPosY+1, 19, 29); + g.fillRect((int)_startPosX+6, (int)_startPosY + 66, 188, 48); + g.fillRect( (int)_startPosX+2, (int)_startPosY+2, 38, 58); //krilya g.setPaint(Color.black); - g.fillRect((int)_startPosX + 30, (int)_startPosY + 40, 40, 8); + g.fillRect((int)_startPosX + 60, (int)_startPosY + 80, 80, 16); //cabina g.setPaint(Color.blue); - g.fillRect( (int)_startPosX + 101, (int)_startPosY + 41, 19, 14); + g.fillRect( (int)_startPosX + 202, (int)_startPosY + 82, 38, 28); + drawingPortholes.draw(g, (int)_startPosX+6, (int)_startPosY+70); } public void ChangeBorders(int width, int height) diff --git a/RadarAirplane/src/DrawingPorthole.java b/RadarAirplane/src/DrawingPorthole.java new file mode 100644 index 0000000..3d4e049 --- /dev/null +++ b/RadarAirplane/src/DrawingPorthole.java @@ -0,0 +1,40 @@ +import java.awt.*; + +public class DrawingPorthole { + + private Porthole PortholeCount; + + Color color; + + public void Init(int count, Color bodyColor) { + if(count <= 10) PortholeCount = Porthole.Ten; + else if(count >= 30) PortholeCount = Porthole.Twenty; + else PortholeCount = Porthole.Thirty; + color = bodyColor; + + } + + public void draw(Graphics2D g, int startPosX, int startPosY) { + g.setPaint(Color.white); + int count = 0; + int i = -1; + int j = 0; + while(true) + { + if(i==15) { + i = 0; + j=30; + } + else i++; + if(PortholeCount == Porthole.Ten && count==10) break; + else if(PortholeCount == Porthole.Twenty && count==20) break; + else if(PortholeCount == Porthole.Thirty && count==30) break; + g.drawOval(startPosX+i*12 , startPosY + j, 10, 10); + g.fillOval(startPosX+i*12, startPosY + j, 10, 10); + count++; + } + + + + } +} diff --git a/RadarAirplane/src/FormAirPlane.form b/RadarAirplane/src/FormAirPlane.form index 7226820..fe11c37 100644 --- a/RadarAirplane/src/FormAirPlane.form +++ b/RadarAirplane/src/FormAirPlane.form @@ -1,6 +1,7 @@
- + + @@ -10,106 +11,122 @@ - - + + - - - - - - - - - - - + + + - + - - - - - - - - - - - - - - + - + - + - - + - + - + - - + - - - - - - - - - - + - + + - - + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -
\ No newline at end of file + diff --git a/RadarAirplane/src/Porthole.java b/RadarAirplane/src/Porthole.java new file mode 100644 index 0000000..906bb3f --- /dev/null +++ b/RadarAirplane/src/Porthole.java @@ -0,0 +1,5 @@ +public enum Porthole { + Ten, + Twenty, + Thirty +} -- 2.25.1 From f97e47e9d1965665ec21f63ac80a20877e442811 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BE=D0=BB=D0=BE=D0=B4=D1=8F?= Date: Sun, 4 Dec 2022 00:29:17 +0300 Subject: [PATCH 3/3] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RadarAirplane/src/Canvas.java | 8 ++++---- RadarAirplane/src/DrawingEntityPlain.java | 2 +- RadarAirplane/src/DrawingPorthole.java | 9 ++++++--- RadarAirplane/src/Form.java | 5 +++++ RadarAirplane/src/FormAirPlane.form | 4 +++- RadarAirplane/src/FormAirPlane.java | 6 +++--- 6 files changed, 22 insertions(+), 12 deletions(-) create mode 100644 RadarAirplane/src/Form.java diff --git a/RadarAirplane/src/Canvas.java b/RadarAirplane/src/Canvas.java index e49955e..6421b3a 100644 --- a/RadarAirplane/src/Canvas.java +++ b/RadarAirplane/src/Canvas.java @@ -2,14 +2,14 @@ import javax.swing.*; import java.awt.*; public class Canvas extends JComponent { - FormAirPlane form; - public Canvas(FormAirPlane form) { + Form form; + public Canvas(Form form) { this.form = form; } @Override public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; - form.draw(g2); + form.Draw(g2); } -} \ No newline at end of file +} diff --git a/RadarAirplane/src/DrawingEntityPlain.java b/RadarAirplane/src/DrawingEntityPlain.java index b25868b..34ad00b 100644 --- a/RadarAirplane/src/DrawingEntityPlain.java +++ b/RadarAirplane/src/DrawingEntityPlain.java @@ -11,7 +11,7 @@ class DrawingEntityPlain private int _pictureHeight = -1; private int _AirplaneWidth = 240; - private int _AirplaneHeight = 120; + private int _AirplaneHeight = 150; public void Init(int speed, float weight, Color bodyColor) { diff --git a/RadarAirplane/src/DrawingPorthole.java b/RadarAirplane/src/DrawingPorthole.java index 3d4e049..9dd300a 100644 --- a/RadarAirplane/src/DrawingPorthole.java +++ b/RadarAirplane/src/DrawingPorthole.java @@ -3,17 +3,20 @@ import java.awt.*; public class DrawingPorthole { private Porthole PortholeCount; - Color color; - public void Init(int count, Color bodyColor) { + public void SetCount(int count){ if(count <= 10) PortholeCount = Porthole.Ten; else if(count >= 30) PortholeCount = Porthole.Twenty; else PortholeCount = Porthole.Thirty; + } + public void Init(int count, Color bodyColor) { + SetCount(count); color = bodyColor; } + public void draw(Graphics2D g, int startPosX, int startPosY) { g.setPaint(Color.white); int count = 0; @@ -21,7 +24,7 @@ public class DrawingPorthole { int j = 0; while(true) { - if(i==15) { + if(i==14) { i = 0; j=30; } diff --git a/RadarAirplane/src/Form.java b/RadarAirplane/src/Form.java new file mode 100644 index 0000000..0347fbb --- /dev/null +++ b/RadarAirplane/src/Form.java @@ -0,0 +1,5 @@ +import java.awt.*; + +public interface Form { + void Draw(Graphics2D g); +} diff --git a/RadarAirplane/src/FormAirPlane.form b/RadarAirplane/src/FormAirPlane.form index fe11c37..9f861cb 100644 --- a/RadarAirplane/src/FormAirPlane.form +++ b/RadarAirplane/src/FormAirPlane.form @@ -57,7 +57,9 @@ - + + + diff --git a/RadarAirplane/src/FormAirPlane.java b/RadarAirplane/src/FormAirPlane.java index 442cef0..f02cf12 100644 --- a/RadarAirplane/src/FormAirPlane.java +++ b/RadarAirplane/src/FormAirPlane.java @@ -5,7 +5,7 @@ import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import java.util.Random; -public class FormAirPlane { +public class FormAirPlane implements Form { private JButton createButton; private JButton upButton; private JButton rightButton; @@ -87,8 +87,8 @@ public class FormAirPlane { canv.repaint(); }); } - - public void draw(Graphics2D g) { + @Override + public void Draw(Graphics2D g) { if(_airPlane == null) return; _airPlane.DrawTransport(g); } -- 2.25.1