From fb10dd3a4a87fd90d8662f08acb06191b662b056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=91=D0=B5=D0=BB?= =?UTF-8?q?=D1=8F=D0=BD=D0=B8=D0=BD?= Date: Wed, 13 Sep 2023 18:06:45 +0400 Subject: [PATCH] =?UTF-8?q?=D0=92=D1=8B=D0=B3=D1=80=D1=83=D0=B7=D0=BA?= =?UTF-8?q?=D0=B0=201=20=D0=BB=D0=B0=D0=B1=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tank/.gitignore | 29 ++++++++ Tank/.idea/.gitignore | 8 ++ Tank/.idea/misc.xml | 6 ++ Tank/.idea/modules.xml | 8 ++ Tank/.idea/vcs.xml | 6 ++ Tank/Resources/KeyDown.png | Bin 0 -> 1433 bytes Tank/Resources/KeyLeft.png | Bin 0 -> 1265 bytes Tank/Resources/KeyRight.png | Bin 0 -> 1310 bytes Tank/Resources/KeyUp.png | Bin 0 -> 1278 bytes Tank/Tank.iml | 11 +++ Tank/src/CountWheels.java | 14 ++++ Tank/src/Direction.java | 6 ++ Tank/src/DrawingField.java | 54 ++++++++++++++ Tank/src/DrawingTank.java | 142 ++++++++++++++++++++++++++++++++++++ Tank/src/DrawingWheels.java | 50 +++++++++++++ Tank/src/EntityTank.java | 28 +++++++ Tank/src/FormTank.java | 135 ++++++++++++++++++++++++++++++++++ Tank/src/Main.java | 5 ++ 18 files changed, 502 insertions(+) create mode 100644 Tank/.gitignore create mode 100644 Tank/.idea/.gitignore create mode 100644 Tank/.idea/misc.xml create mode 100644 Tank/.idea/modules.xml create mode 100644 Tank/.idea/vcs.xml create mode 100644 Tank/Resources/KeyDown.png create mode 100644 Tank/Resources/KeyLeft.png create mode 100644 Tank/Resources/KeyRight.png create mode 100644 Tank/Resources/KeyUp.png create mode 100644 Tank/Tank.iml create mode 100644 Tank/src/CountWheels.java create mode 100644 Tank/src/Direction.java create mode 100644 Tank/src/DrawingField.java create mode 100644 Tank/src/DrawingTank.java create mode 100644 Tank/src/DrawingWheels.java create mode 100644 Tank/src/EntityTank.java create mode 100644 Tank/src/FormTank.java create mode 100644 Tank/src/Main.java diff --git a/Tank/.gitignore b/Tank/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/Tank/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/Tank/.idea/.gitignore b/Tank/.idea/.gitignore new file mode 100644 index 0000000..1c2fda5 --- /dev/null +++ b/Tank/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/Tank/.idea/misc.xml b/Tank/.idea/misc.xml new file mode 100644 index 0000000..80cafc3 --- /dev/null +++ b/Tank/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Tank/.idea/modules.xml b/Tank/.idea/modules.xml new file mode 100644 index 0000000..8d39350 --- /dev/null +++ b/Tank/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Tank/.idea/vcs.xml b/Tank/.idea/vcs.xml new file mode 100644 index 0000000..2e3f692 --- /dev/null +++ b/Tank/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Tank/Resources/KeyDown.png b/Tank/Resources/KeyDown.png new file mode 100644 index 0000000000000000000000000000000000000000..ff09b70c28c9988dac153284f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40~=NyejqZ?@tdar8LN+Fh7X?=a2XV0Fov$I1G z1l{L91BHq8T7G+bn+FdbaPQtdUcY`_wCO_V5=*VyTe2AR+AsT2io;44+4|n| zkoTT23`vrNBuQ}2asK>y;y7k;agoQ5AG5i+i4>9`2yo8rAJ`C|N)<}WzUOJ|TatlB zLYm^ceEBjTKYrxSojW}J>nYpY+xr)nF&Bz{IP@Uc7=uj=&1RD`XU_2QiamHAxVoE8R%_i1b*4EZ|`0ydOZ{OzB z{3)c8hjMaGQJ7e-6KC!UeSIbTQ6tPSLRlArO0edp-=qiKb$2 zdOQdM-oJm(*47r+u3ckhW(My)Ns^$oMoM`gY?^f7dG$$>lt&B>Mh#it@y-veAEm!h z>XRfX*TkCN*`$=ffrS1vK=1DEGCMm< z6h#PM%m=c+^HKp-On>h^-@biATWg8q7%30tB=SC)&7O#}1I_z?**OsB97&R3twl#s z1V9|e2X8!b2A2IedR$^fQw9Ctz3*h3l~Oq8`VJ!foM901rc%{+VEy2nBMd|S1&2)B UC`*H+82|tP07*qoM6N<$g5dIoJpcdz literal 0 HcmV?d00001 diff --git a/Tank/Resources/KeyUp.png b/Tank/Resources/KeyUp.png new file mode 100644 index 0000000000000000000000000000000000000000..0e4bf6ffa0263f78b54fa34ba68c98c19ef64090 GIT binary patch literal 1278 zcmVu0sj2jo~ zRd69$DB?mv1Ys_yAR;J1xPw^=BIrVV#=N^8vk2))+H~x`={O|#K`km>b*fH%b?VeP z74q`(qB-ZN1xjgEoe)y9o!9SSeg6#Z{+Ub$)T3?7<6E&-180mm6~8v+7w-Oz$_s+_ zW$Y_gvDu)c#1kQ;jTv*>70`UY6BJ(Kl^JqFYu(0-5kjD~{=erD3JCp=+4f}&2yRnB zZ7l5eZriG4%4rj5#1_K0Vy%Xnfmj$e#VCVR(y3=M8JMPtj*bo#i^V|lz5G?(K7o7q zfKm#KGe{|+ltM0-!`$2)E-o&hwf+(ZUpsVe5R5U{whhiX48y?w{yuhgb`Xt5F+M(y zuC6ZFw%v@O9W;$Gr4$%rxVgE(^71lfXJ>JIe2kxe|AY{t>8w$pw8!feH$H368Hd&y zT50U=?&9I$0a8l*^~az1vGN1Ax3@411B|i{vVoFKRhAFqQ&Lqt6$=}-uwhviu98<+ zTU*2E=qQ8`0Dx>Zi@m))NFgDWY#MV-QOq<=q|<3^ZEc~iug^IJZ7DD`G=!Cv75w_= z7b1}eq?DnJTe-uU=Eu&@&#|$wf&Tt}Xsw}?axU8g0|VIH+(a&yLuG0rOw_copioMc zY>RVn&hh;GjMdduOiWBTTd*v93#!Sg~EsSwrwMu&0=I^1dEG{xVyUx zowb^Z1@&uMYgm?rL?VHBJdWPpUI-z;7=vk=wFjmYQc5t!u)VzvLWom$`zbHKrM0fw z5#@SlSt=S;o(mgrficDZeVb55DN`Kg6^r#Q)Gv%1mLcA-$f%*+g~ zuCCDC-TmRa`v4(?fKuw%Wlv8J5{U#(PEIgAJq@LluW`NRnM$R?QA`Md`}=#OQYl0t zkq_U!CQ2y_Kox~$Sq@8-Qr|XK55Dq>ZUk-b zj=S73ROL4GlREG-e%ofLz7=aV_&Piq&HH)fCH&%dV#Ky(>|3!`gRk6u(A@cFHuV)L z?zUy@Td`IHH%${#%DQ$G)DO9BsL_8V`01~;b}r*mO7QphcXUQOOB3=?pwUb6R~#0V zv0SlO1kdO5uq>NBO~#ODRKNK{wpSANF6I%1Twr o<>gd#GZFSF=_S7`R|tWB0pFkf#1au;M1& literal 0 HcmV?d00001 diff --git a/Tank/Tank.iml b/Tank/Tank.iml new file mode 100644 index 0000000..9465dd8 --- /dev/null +++ b/Tank/Tank.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Tank/src/CountWheels.java b/Tank/src/CountWheels.java new file mode 100644 index 0000000..5d064d7 --- /dev/null +++ b/Tank/src/CountWheels.java @@ -0,0 +1,14 @@ +public enum CountWheels { + Two(2), + Three(3), + Four(4), + Five(5); + private final int Value; + CountWheels(int Count){ + Value=Count; + } + public int getCountWheels(){ + return Value; + } + public int setCountWheels() { return Value; } +} diff --git a/Tank/src/Direction.java b/Tank/src/Direction.java new file mode 100644 index 0000000..a641b80 --- /dev/null +++ b/Tank/src/Direction.java @@ -0,0 +1,6 @@ +public enum Direction { + Up, + Down, + Left, + Right +} diff --git a/Tank/src/DrawingField.java b/Tank/src/DrawingField.java new file mode 100644 index 0000000..5f782e8 --- /dev/null +++ b/Tank/src/DrawingField.java @@ -0,0 +1,54 @@ +import javax.swing.*; +import java.awt.*; +import java.util.Random; + +public class DrawingField extends JPanel { + private final FormTank field; + DrawingTank _Tank; + public DrawingField(FormTank field) { + this.field = field; + } + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); + Graphics2D g2 =(Graphics2D)g; + if (_Tank!=null) + _Tank.DrawTransport(g2); + else return; + } + public void UpButtonAction(){ + if (_Tank!=null) + _Tank.MoveTransport(Direction.Up); + else + return; + } + public void DownButtonAction(){ + if (_Tank!=null) + _Tank.MoveTransport(Direction.Down); + else + return; + } + public void RightButtonAction(){ + if (_Tank!=null) + _Tank.MoveTransport(Direction.Right); + else + return; + } + public void LeftButtonAction(){ + if (_Tank!=null) + _Tank.MoveTransport(Direction.Left); + else + return; + } + public void CreateButtonAction(){ + Random rnd=new Random(); + _Tank=new DrawingTank(); + _Tank.Init(rnd.nextInt(50)+10,rnd.nextInt(100)+500,new Color(rnd.nextInt(256),rnd.nextInt(256),rnd.nextInt(256))); + _Tank.SetPosition(rnd.nextInt(100)+10,rnd.nextInt(100)+10,getWidth(),getHeight()); + } + public void ResizeField(){ + if (_Tank!=null) + _Tank.ChangeBorders(getWidth(),getHeight()); + else return; + } +} diff --git a/Tank/src/DrawingTank.java b/Tank/src/DrawingTank.java new file mode 100644 index 0000000..2d2d5f7 --- /dev/null +++ b/Tank/src/DrawingTank.java @@ -0,0 +1,142 @@ +import java.awt.*; + +public class DrawingTank { + public EntityTank Tank; + public EntityTank getTank() { + return Tank; + } + public DrawingWheels Wheels; + private int _startPosX; + private int _startPosY; + private Integer _pictureWidth = null; + private Integer _pictureHeight = null; + private final int _TankWidth = 175; + private final int _TankHeight = 100; + + public void Init(int speed, float weight, Color bodyColor) + { + Tank = new EntityTank(); + Tank.Init(speed, weight, bodyColor); + Wheels = new DrawingWheels(); + Wheels.SetCountWheels((int)(2 + Math.random() + Math.random()*2)); + } + + public void SetPosition(int x, int y, int width, int height) + { + if (x >= 0 && x+_TankWidth <= width && y >= 0 && y+_TankHeight <= 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 + _TankWidth + Tank.Step < _pictureWidth) + { + _startPosX += Tank.Step; + } + break; + + case Left: + if (_startPosX- Tank.Step >= 0) + { + _startPosX -= Tank.Step; + } + break; + + case Up: + if (_startPosY - Tank.Step >= 0) + { + _startPosY -= Tank.Step; + } + break; + + case Down: + if (_startPosY + _TankHeight + Tank.Step < _pictureHeight) + { + _startPosY += Tank.Step; + } + break; + } + } + public void DrawTransport(Graphics g) + { + if (_startPosX < 0 || _startPosY < 0 || _pictureHeight== null || _pictureWidth== null) + { + return; + } + + Graphics2D g2 = (Graphics2D) g; + + //Гусеница + Color Gray = new Color(128, 128, 128); + g2.setColor(Gray); + g2.drawOval(_startPosX + 10, _startPosY + 30, 120, 30); + + // Ведущие колёса танка (в размере чуть меньше) + g2.setColor(Color.BLACK); + g2.drawOval(_startPosX + 113, _startPosY + 41, 11, 11); + g2.fillOval(_startPosX + 113, _startPosY + 41, 11, 11); + g2.drawOval(_startPosX + 13, _startPosY + 40, 11, 11); + g2.fillOval(_startPosX + 13, _startPosY + 40, 11, 11); + Wheels.DrawWheels(g2, _startPosX, _startPosY); + + // Корпус танка + g2.setColor(Color.DARK_GRAY); + int[] xPoints = {_startPosX + 5, _startPosX + 140, _startPosX + 130,_startPosX + 12}; + int[] yPoints = {_startPosY + 30, _startPosY + 30, _startPosY + 42, _startPosY + 42}; + int nPoints = 4; + g2.drawPolygon(xPoints,yPoints,nPoints); + g2.fillPolygon(xPoints,yPoints,nPoints); + + // Башня + int[] xPointsBody = {_startPosX + 52, _startPosX + 52, _startPosX + 40, _startPosX + 15,_startPosX + 15, _startPosX + 60,_startPosX + 90,_startPosX + 120,_startPosX + 100,_startPosX + 95, _startPosX + 90}; + int[] yPointsBody = {_startPosY + 30, _startPosY + 27, _startPosY + 23, _startPosY + 18,_startPosY + 15, _startPosY + 11,_startPosY + 11,_startPosY + 20,_startPosY + 25,_startPosY + 27,_startPosY + 30}; + int nPointsBody = 11; + + g2.drawPolygon(xPointsBody,yPointsBody,nPointsBody); + g2.fillPolygon(xPointsBody,yPointsBody,nPointsBody); + + // Орудие + g2.drawRect(_startPosX + 112, _startPosY+17, 50, 5); + g2.fillRect(_startPosX + 112, _startPosY+17, 50, 5); + + // Зенитное орудие + int[] xPointsGun = {_startPosX + 45, _startPosX + 45, _startPosX + 41, _startPosX + 41, _startPosX + 42, _startPosX + 41, _startPosX + 44,_startPosX + 50 ,_startPosX + 52,_startPosX + 53, _startPosX + 58}; + int[] yPointsGun = {_startPosY + 12, _startPosY + 10, _startPosY + 8, _startPosY + 7, _startPosY + 5, _startPosY + 4,_startPosY + 3,_startPosY + 3,_startPosY + 5,_startPosY + 7,_startPosY + 10}; + int nPointsGun = 11; + + g2.fillRect(_startPosX + 50, _startPosY+5, 20, 2); + g2.drawPolygon(xPointsGun,yPointsGun,nPointsGun); + g2.fillPolygon(xPointsGun,yPointsGun,nPointsGun); + } + public void ChangeBorders(int width,int height) + { + _pictureWidth = width; + _pictureHeight = height; + if (_pictureWidth<=_TankWidth||_pictureHeight<=_TankHeight) + { + _pictureWidth = null; + _pictureHeight = null; + return; + } + if (_startPosX + _TankWidth > _pictureWidth) + { + _startPosX = _pictureWidth - _TankWidth; + } + if (_startPosY + _TankHeight > _pictureHeight) + { + _startPosY = _pictureHeight - _TankHeight; + } + } +} diff --git a/Tank/src/DrawingWheels.java b/Tank/src/DrawingWheels.java new file mode 100644 index 0000000..397c052 --- /dev/null +++ b/Tank/src/DrawingWheels.java @@ -0,0 +1,50 @@ +import java.awt.*; + +public class DrawingWheels { + + private CountWheels _wheels; + + public void SetCountWheels(int Count){ + for (CountWheels temp: CountWheels.values()) + if (temp.getCountWheels() == Count){ + _wheels=temp; + return; + } + } + + public void DrawWheels(Graphics2D g,int _startPosX, int _startPosY) { + switch (_wheels.getCountWheels()) + { + case 2: + // Отрисовка 2 катков + g.setColor(Color.BLACK); + g.drawOval(_startPosX + 30, _startPosY + 42, 15, 15); + g.fillOval(_startPosX + 30, _startPosY + 42, 15, 15); + g.drawOval(_startPosX + 50, _startPosY + 45, 15, 15); + g.fillOval(_startPosX + 50, _startPosY + 45, 15, 15); + break; + case 3: + // Отрисовка 3 катков + g.setColor(Color.BLACK); + g.drawOval(_startPosX + 30, _startPosY + 42, 15, 15); + g.fillOval(_startPosX + 30, _startPosY + 42, 15, 15); + g.drawOval(_startPosX + 50, _startPosY + 45, 15, 15); + g.fillOval(_startPosX + 50, _startPosY + 45, 15, 15); + g.drawOval(_startPosX + 75, _startPosY + 45, 15, 15); + g.fillOval(_startPosX + 75, _startPosY + 45, 15, 15); + break; + case 4: + // Отрисовка 4 катков + g.setColor(Color.BLACK); + g.drawOval(_startPosX + 30, _startPosY + 42, 15, 15); + g.fillOval(_startPosX + 30, _startPosY + 42, 15, 15); + g.drawOval(_startPosX + 50, _startPosY + 45, 15, 15); + g.fillOval(_startPosX + 50, _startPosY + 45, 15, 15); + g.drawOval(_startPosX + 75, _startPosY + 45, 15, 15); + g.fillOval(_startPosX + 75, _startPosY + 45, 15, 15); + g.drawOval(_startPosX + 95, _startPosY + 42, 15, 15); + g.fillOval(_startPosX + 95, _startPosY + 42, 15, 15); + break; + } + } +} diff --git a/Tank/src/EntityTank.java b/Tank/src/EntityTank.java new file mode 100644 index 0000000..5b36178 --- /dev/null +++ b/Tank/src/EntityTank.java @@ -0,0 +1,28 @@ +import java.awt.*; +import java.util.Random; + +public class EntityTank { + 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)+10 : speed; + Weight = weight <= 0 ? rnd.nextInt(100)+500 : weight; + BodyColor = bodyColor; + Step = Speed * 600 / (int)Weight; + } +} + diff --git a/Tank/src/FormTank.java b/Tank/src/FormTank.java new file mode 100644 index 0000000..f094dbe --- /dev/null +++ b/Tank/src/FormTank.java @@ -0,0 +1,135 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; +public class FormTank extends JFrame{ + private int Width; + private int Height; + + JPanel BottomPanel = new JPanel(); + JPanel CreatePanel = new JPanel(); + JPanel BottomAndCreatePanel = new JPanel(); + JPanel DimentionPanel = new JPanel(); + JPanel UpPanel = new JPanel(); + JPanel DownPanel = new JPanel(); + JPanel LRPanel = new JPanel(); + + DrawingField field = new DrawingField(this); + + JButton ButtonCreate=new JButton("Создать"); + Icon iconUp = new ImageIcon("Resources/KeyUp.png"); + JButton ButtonUp=new JButton(iconUp); + + Icon iconDown = new ImageIcon("Resources/KeyDown.png"); + JButton ButtonDown=new JButton(iconDown); + + Icon iconRight = new ImageIcon("Resources/KeyRight.png"); + JButton ButtonRight=new JButton(iconRight); + + Icon iconLeft = new ImageIcon("Resources/KeyLeft.png"); + JButton ButtonLeft=new JButton(iconLeft); + public FormTank(){ + super("Tank"); + setSize(800,600); + Width=getWidth(); + Height=getHeight(); + ShowWindow(); + RefreshWindow(); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setVisible(true); + } + + public void ShowWindow(){ + + Dimension dimen=new Dimension(30,30); + + // Обработка нажатия кнопки + ButtonUp.setPreferredSize(dimen); + ButtonUp.addActionListener(e->{ + field.UpButtonAction(); + repaint(); + }); + + // Обработка нажатия кнопки + ButtonDown.setPreferredSize(dimen); + ButtonDown.addActionListener(e->{ + field.DownButtonAction(); + repaint(); + }); + + // Обработка нажатия кнопки + ButtonRight.setPreferredSize(dimen); + ButtonRight.addActionListener(e->{ + field.RightButtonAction(); + repaint(); + }); + + // Обработка нажатия кнопки + ButtonLeft.setPreferredSize(dimen); + ButtonLeft.addActionListener(e->{ + field.LeftButtonAction(); + repaint(); + }); + + // Добавление кнопок на панель (Левая и правая стрелки) + LRPanel.setLayout(new FlowLayout(FlowLayout.CENTER,50,0)); + LRPanel.setBackground(new Color(0,0,0,0)); + LRPanel.add(ButtonLeft); + LRPanel.add(ButtonRight); + + // Добавление кнопки (Стрелка вверх) + UpPanel.setLayout(new FlowLayout()); + UpPanel.setBackground(new Color(0,0,0,0)); + UpPanel.add(ButtonUp); + + // Добавление кнопки (Стрелка вниз) + DownPanel.setLayout(new FlowLayout()); + DownPanel.setBackground(new Color(0,0,0,0)); + DownPanel.add(ButtonDown); + + DimentionPanel.setLayout(new BoxLayout(DimentionPanel,BoxLayout.Y_AXIS)); + DimentionPanel.setBackground(new Color(0,0,0,0)); + DimentionPanel.add(UpPanel); + DimentionPanel.add(LRPanel); + DimentionPanel.add(DownPanel); + add(DimentionPanel); + + // нажатие кнопки + CreatePanel.setLayout(new FlowLayout()); + CreatePanel.setBackground(new Color(0,0,0,0)); + CreatePanel.add(ButtonCreate); + ButtonCreate.addActionListener(e->{ + field.CreateButtonAction(); + repaint(); + }); + + BottomPanel.setLayout(new FlowLayout()); + BottomPanel.setBackground(new Color(0,0,0,0)); + + BottomAndCreatePanel.setLayout(new BoxLayout(BottomAndCreatePanel,BoxLayout.Y_AXIS)); + BottomAndCreatePanel.setBackground(new Color(0,0,0,0)); + BottomAndCreatePanel.add(CreatePanel); + BottomAndCreatePanel.add(BottomPanel); + + add(BottomAndCreatePanel); + add(field); + + addComponentListener(new ComponentAdapter() { + @Override + public void componentResized(ComponentEvent e) { + super.componentResized(e); + Width=getWidth(); + Height=getHeight(); + + field.ResizeField(); + repaint(); + RefreshWindow(); + } + }); + } + public void RefreshWindow(){ + field.setBounds(0,0,Width,Height); + BottomAndCreatePanel.setBounds(-320,Height-110,Width,80); + DimentionPanel.setBounds(Width-170,Height-170,190,140); + } +} diff --git a/Tank/src/Main.java b/Tank/src/Main.java new file mode 100644 index 0000000..7c7e57b --- /dev/null +++ b/Tank/src/Main.java @@ -0,0 +1,5 @@ +public class Main { + public static void main(String[] args){ + new FormTank(); + } +}