From 0d00dd715ac644b43b1a5f4030be072a70c9ffef 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: Thu, 30 Nov 2023 20:16:12 +0400 Subject: [PATCH 01/12] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=B0=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tank/.idea/misc.xml | 1 - Tank/Tank.iml | 11 - Tank/src/DrawingStarOrnament.java | 8 +- Tank/src/DrawingSuspensionOrnament.java | 36 +-- Tank/src/DrawingTank.java | 12 +- Tank/src/DrawingWheelsCombination.java | 42 +-- Tank/src/EntityArmoVehicle.java | 1 + Tank/src/EntityTank.java | 6 +- Tank/src/FormTankCollection.java | 41 +-- Tank/src/FormTankConfig.java | 389 ++++++++++++++++++++++++ Tank/src/FormTankGenerate.java | 6 +- Tank/src/SetGeneric.java | 4 +- Tank/src/TanksGenericCollections.java | 2 + 13 files changed, 477 insertions(+), 82 deletions(-) delete mode 100644 Tank/Tank.iml create mode 100644 Tank/src/FormTankConfig.java diff --git a/Tank/.idea/misc.xml b/Tank/.idea/misc.xml index 5d30da4..1e4328b 100644 --- a/Tank/.idea/misc.xml +++ b/Tank/.idea/misc.xml @@ -1,4 +1,3 @@ - diff --git a/Tank/Tank.iml b/Tank/Tank.iml deleted file mode 100644 index c90834f..0000000 --- a/Tank/Tank.iml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/Tank/src/DrawingStarOrnament.java b/Tank/src/DrawingStarOrnament.java index 53cb792..07af097 100644 --- a/Tank/src/DrawingStarOrnament.java +++ b/Tank/src/DrawingStarOrnament.java @@ -18,6 +18,9 @@ public class DrawingStarOrnament implements IOrnamentForm { case 4: wheels = CountWheels.Four; break; + case 5: + wheels = CountWheels.Five; + break; default: wheels = CountWheels.Two; break; @@ -27,7 +30,7 @@ public class DrawingStarOrnament implements IOrnamentForm { public void CaterpillarStar(Graphics g, int _startPosX, int _startPosY) { StarColor = Color.RED; g.setColor(StarColor); - int xPontsStar[] = {_startPosX + 15, _startPosX + 18, _startPosX + 21, _startPosX + 18, _startPosX + 19, _startPosX + 16, _startPosX + 12, _startPosX + 12, _startPosX + 11, _startPosX + 15, _startPosX + 16}; + int xPontsStar[] = {_startPosX + 15, _startPosX + 18, _startPosX + 21, _startPosX + 18, _startPosX + 19, _startPosX + 16, _startPosX + 12, _startPosX + 13, _startPosX + 12, _startPosX + 15, _startPosX + 16}; int yPontsStar[] = {_startPosY + 35, _startPosY + 38, _startPosY + 38, _startPosY + 42, _startPosY + 45, _startPosY + 42, _startPosY + 45, _startPosY + 41, _startPosY + 38, _startPosY + 38, _startPosY + 35}; g.drawPolygon(xPontsStar, yPontsStar, xPontsStar.length); g.fillPolygon(xPontsStar, yPontsStar, xPontsStar.length); @@ -38,6 +41,9 @@ public class DrawingStarOrnament implements IOrnamentForm { g.fillOval(10 + _startPosX, 42 + _startPosY, 20, 20); } public void Draw(Graphics g, int _startPosX, int _startPosY) { + DrawWheels(g,_startPosX, _startPosY); + CaterpillarStar(g,_startPosX + 5, _startPosY + 12); + if (wheels == CountWheels.Two){ DrawWheels(g,_startPosX, _startPosY); DrawWheels(g,_startPosX + 100, _startPosY); diff --git a/Tank/src/DrawingSuspensionOrnament.java b/Tank/src/DrawingSuspensionOrnament.java index 32f1953..33712f0 100644 --- a/Tank/src/DrawingSuspensionOrnament.java +++ b/Tank/src/DrawingSuspensionOrnament.java @@ -18,6 +18,9 @@ public class DrawingSuspensionOrnament implements IOrnamentForm { case 4: wheels = CountWheels.Four; break; + case 5: + wheels = CountWheels.Five; + break; default: wheels = CountWheels.Two; break; @@ -29,19 +32,17 @@ public class DrawingSuspensionOrnament implements IOrnamentForm { g.fillOval(10 + _startPosX, 42 + _startPosY, 20, 20); } - public void DrawSuspension(Graphics g, int _startPosX, int _startPosY) { - SuspensionColor = Color.BLUE; - g.setColor(SuspensionColor); - g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); - } - public void Draw(Graphics g, int _startPosX, int _startPosY) { + DrawWheels(g,_startPosX, _startPosY); + g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); + if (wheels == CountWheels.Two) { DrawWheels(g,_startPosX, _startPosY); DrawWheels(g,_startPosX + 100, _startPosY); - - DrawSuspension(g, _startPosX, _startPosY); - DrawSuspension(g,_startPosX + 73, _startPosY); + SuspensionColor = Color.RED; + g.setColor(SuspensionColor); + g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); + g.fillRect(_startPosX + 51, _startPosY + 50, 10, 3); } if (wheels == CountWheels.Three) { @@ -49,22 +50,23 @@ public class DrawingSuspensionOrnament implements IOrnamentForm { DrawWheels(g,_startPosX + 50, _startPosY); DrawWheels(g,_startPosX + 100, _startPosY); - DrawSuspension(g, _startPosX, _startPosY); - DrawSuspension(g,_startPosX + 24, _startPosY); - DrawSuspension(g,_startPosX + 73, _startPosY); + g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); + g.fillRect(_startPosX + 51, _startPosY + 50, 10, 3); + g.fillRect(_startPosX + 80, _startPosY + 50, 10, 3); } - if (wheels == CountWheels.Four) { + if (wheels == CountWheels.Four || wheels == CountWheels.Five) { + // Можно подкорректировать с 4ой и 5ой, чтобы с колёсами было чуть поточнее DrawWheels(g,_startPosX, _startPosY); DrawWheels(g,_startPosX + 25, _startPosY); DrawWheels(g,_startPosX + 50, _startPosY); DrawWheels(g,_startPosX + 75, _startPosY); DrawWheels(g,_startPosX + 100, _startPosY); - DrawSuspension(g, _startPosX, _startPosY); - DrawSuspension(g,_startPosX + 24, _startPosY); - DrawSuspension(g,_startPosX + 53, _startPosY); - DrawSuspension(g,_startPosX + 73, _startPosY); + g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); + g.fillRect(_startPosX + 51, _startPosY + 50, 10, 3); + g.fillRect(_startPosX + 80, _startPosY + 50, 10, 3); + g.fillRect(_startPosX + 101, _startPosY + 50, 10, 3); } } } \ No newline at end of file diff --git a/Tank/src/DrawingTank.java b/Tank/src/DrawingTank.java index bd27a18..14d971c 100644 --- a/Tank/src/DrawingTank.java +++ b/Tank/src/DrawingTank.java @@ -4,7 +4,6 @@ public class DrawingTank extends DrawingArmoVehicle { protected IOrnamentForm OrnamentsForm; private boolean OrnamentAdd; - // Конструктор (Инициализация характеристик) public DrawingTank(int speed, double weight, Color bodyColor, int _numWheel, Color additionalColor, boolean bodyKit, boolean caterpillar, boolean tower, int width, int height, boolean ornamentAdd) { super(speed, weight, bodyColor, _numWheel, width, height); ArmoVehicle = new EntityTank(speed, weight, bodyColor, _numWheel, additionalColor, bodyKit, caterpillar, tower); @@ -13,11 +12,16 @@ public class DrawingTank extends DrawingArmoVehicle { this.OrnamentAdd = ornamentAdd; } - // Ещё один конструктор - public DrawingTank(EntityTank tank, IOrnamentForm _wheelDrawing, int width, int height) { - super(tank, _wheelDrawing, width, height); + public DrawingTank(int speed, float weight, Color bodyColor, int _numWheel, Color additionalColor, boolean bodyKit, boolean caterpillar, boolean tower, int width, int height) { + super(speed, weight, bodyColor, _numWheel, width, height); + ArmoVehicle=new EntityTank(speed,weight,bodyColor,_numWheel, additionalColor,bodyKit,caterpillar, tower); + } + + public DrawingTank(EntityTank armoVehicle, IOrnamentForm _wheelDrawing, int width, int height) { + super(armoVehicle, _wheelDrawing, width, height); if (height < _pictureHeight || width < _pictureWidth) return; + ArmoVehicle = armoVehicle; } // Установка позиции diff --git a/Tank/src/DrawingWheelsCombination.java b/Tank/src/DrawingWheelsCombination.java index 5712a20..f0737df 100644 --- a/Tank/src/DrawingWheelsCombination.java +++ b/Tank/src/DrawingWheelsCombination.java @@ -18,6 +18,9 @@ public class DrawingWheelsCombination implements IOrnamentForm { case 4: wheels = CountWheels.Four; break; + case 5: + wheels = CountWheels.Five; + break; default: wheels = CountWheels.Two; break; @@ -33,24 +36,22 @@ public class DrawingWheelsCombination implements IOrnamentForm { g.fillPolygon(xPontsStar, yPontsStar, xPontsStar.length); } - public void DrawSuspension(Graphics g, int _startPosX, int _startPosY) { - CombinationColor = Color.BLUE; - g.setColor(CombinationColor); - g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); - } - - public void DrawWheels(Graphics g, int _startPosX, int _startPosY){ + public void DrawWheels(Graphics g, int _startPosX, int _startPosY) { g.setColor(Color.BLACK); g.fillOval(10 + _startPosX, 42 + _startPosY, 20, 20); } public void Draw(Graphics g, int _startPosX, int _startPosY) { + DrawWheels(g,_startPosX, _startPosY); + g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); + CaterpillarStar(g,_startPosX + 5, _startPosY + 12); + if (wheels == CountWheels.Two){ DrawWheels(g,_startPosX, _startPosY); DrawWheels(g,_startPosX + 100, _startPosY); - DrawSuspension(g, _startPosX, _startPosY); - DrawSuspension(g,_startPosX + 73, _startPosY); + g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); + g.fillRect(_startPosX + 101, _startPosY + 50, 10, 3); CaterpillarStar(g,_startPosX + 5, _startPosY + 12); CaterpillarStar(g,_startPosX + 105, _startPosY + 12); @@ -61,9 +62,10 @@ public class DrawingWheelsCombination implements IOrnamentForm { DrawWheels(g,_startPosX + 50, _startPosY); DrawWheels(g,_startPosX + 100, _startPosY); - DrawSuspension(g, _startPosX, _startPosY); - DrawSuspension(g,_startPosX + 24, _startPosY); - DrawSuspension(g,_startPosX + 73, _startPosY); + g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); + g.fillRect(_startPosX + 51, _startPosY + 50, 10, 3); + g.fillRect(_startPosX + 100, _startPosY + 50, 10, 3); + CaterpillarStar(g,_startPosX + 5, _startPosY + 12); CaterpillarStar(g,_startPosX + 55, _startPosY + 12); @@ -76,10 +78,10 @@ public class DrawingWheelsCombination implements IOrnamentForm { DrawWheels(g,_startPosX + 50, _startPosY); DrawWheels(g,_startPosX + 100, _startPosY); - DrawSuspension(g, _startPosX, _startPosY); - DrawSuspension(g,_startPosX + 24, _startPosY); - DrawSuspension(g,_startPosX + 53, _startPosY); - DrawSuspension(g,_startPosX + 73, _startPosY); + g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); + g.fillRect(_startPosX + 51, _startPosY + 50, 10, 3); + g.fillRect(_startPosX + 80, _startPosY + 50, 10, 3); + g.fillRect(_startPosX + 101, _startPosY + 50, 10, 3); CaterpillarStar(g,_startPosX + 5, _startPosY + 12); CaterpillarStar(g,_startPosX + 30, _startPosY + 12); @@ -94,10 +96,10 @@ public class DrawingWheelsCombination implements IOrnamentForm { DrawWheels(g,_startPosX + 75, _startPosY); DrawWheels(g,_startPosX + 100, _startPosY); - DrawSuspension(g, _startPosX, _startPosY); - DrawSuspension(g,_startPosX + 24, _startPosY); - DrawSuspension(g,_startPosX + 53, _startPosY); - DrawSuspension(g,_startPosX + 73, _startPosY); + g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); + g.fillRect(_startPosX + 51, _startPosY + 50, 10, 3); + g.fillRect(_startPosX + 80, _startPosY + 50, 10, 3); + g.fillRect(_startPosX + 101, _startPosY + 50, 10, 3); CaterpillarStar(g,_startPosX + 5, _startPosY + 12); CaterpillarStar(g,_startPosX + 30, _startPosY + 12); diff --git a/Tank/src/EntityArmoVehicle.java b/Tank/src/EntityArmoVehicle.java index a7c2b0d..11ecf8d 100644 --- a/Tank/src/EntityArmoVehicle.java +++ b/Tank/src/EntityArmoVehicle.java @@ -7,6 +7,7 @@ public class EntityArmoVehicle { return Weight; } public Color BodyColor; + public void setBodyColor(Color color){ BodyColor = color; } public double Step; public int numWheel; diff --git a/Tank/src/EntityTank.java b/Tank/src/EntityTank.java index ee6a1c3..cd81503 100644 --- a/Tank/src/EntityTank.java +++ b/Tank/src/EntityTank.java @@ -2,6 +2,7 @@ import java.awt.*; public class EntityTank extends EntityArmoVehicle { public Color AdditionalColor; + public void setAdditionalColor(Color color) { AdditionalColor = color; } public boolean BodyKit; public boolean Caterpillar; public boolean Tower; @@ -13,7 +14,4 @@ public class EntityTank extends EntityArmoVehicle { Caterpillar = caterpillar; Tower = tower; } -} - - - +} \ No newline at end of file diff --git a/Tank/src/FormTankCollection.java b/Tank/src/FormTankCollection.java index 01919ff..f0aa8b5 100644 --- a/Tank/src/FormTankCollection.java +++ b/Tank/src/FormTankCollection.java @@ -22,8 +22,8 @@ public class FormTankCollection { if (obj == null) { return; } - if (obj.ShowTank() != null) { - g.drawImage(obj.ShowTank(), 0, 0, this); + if (obj.ShowTanks() != null) { + g.drawImage(obj.ShowTanks(), 0, 0, this); } super.repaint(); } @@ -74,11 +74,11 @@ public class FormTankCollection { return; } - FormTank form = new FormTank(); - form.buttonSelectTank.addActionListener( + FormTankConfig form = new FormTankConfig(); + form.buttonAdd.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { - if (obj.Add(form._drawingVehicle) != -1) { + if (obj != null && obj.Add(form._vehicle) != -1) { JOptionPane.showMessageDialog(null, "Объект добавлен", "Информация", JOptionPane.INFORMATION_MESSAGE); Draw(); } else { @@ -152,14 +152,14 @@ public class FormTankCollection { JButton ButtonRefreshCollection = new JButton("Обновить коллекцию"); ButtonRefreshCollection.addActionListener( new ActionListener() { - public void actionPerformed(ActionEvent e){ + public void actionPerformed(ActionEvent e) { Draw(); } } ); - JButton toFormTankGenerate = new JButton("Генерировать технику"); - toFormTankGenerate.addActionListener( + JButton FormTankGenerate = new JButton("Генерация"); + FormTankGenerate.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { FormTankGenerate formTankGenerate = new FormTankGenerate(); @@ -210,30 +210,33 @@ public class FormTankCollection { Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Frame.setLayout(null); canv.setBounds(0, 0, pictureBoxWidth, pictureBoxHeight); - ButtonAddVehicle.setBounds(pictureBoxWidth - 10, 10, 170, 30); - TextBoxNumber.setBounds(pictureBoxWidth - 10, 50, 170, 30); - ButtonRemoveTank.setBounds(pictureBoxWidth - 10, 90, 170, 30); - ButtonRefreshCollection.setBounds(pictureBoxWidth - 10, 130, 170, 30); - toFormTankGenerate.setBounds(pictureBoxWidth - 10, 170, 170, 30); + ButtonAddVehicle.setBounds(pictureBoxWidth, 0, 160, 20); + TextBoxNumber.setBounds(pictureBoxWidth, 30, 160, 20); + ButtonRemoveTank.setBounds(pictureBoxWidth, 60, 160, 20); + ButtonRefreshCollection.setBounds(pictureBoxWidth, 90, 160, 20); + FormTankGenerate.setBounds(pictureBoxWidth, 120, 160, 20); - buttonAddSet.setBounds(pictureBoxWidth - 10, 210, 170, 20); - textBoxSetName.setBounds(pictureBoxWidth - 10, 240, 170, 20); - jListStorage.setBounds(pictureBoxWidth - 10, 270, 170, 80); - buttonRemoveSet.setBounds(pictureBoxWidth - 10, 360, 170, 20); + buttonAddSet.setBounds(pictureBoxWidth, 150, 160, 20); + textBoxSetName.setBounds(pictureBoxWidth, 180, 160, 20); + jListStorage.setBounds(pictureBoxWidth, 210, 160, 80); + buttonRemoveSet.setBounds(pictureBoxWidth, 300, 160, 20); - buttonGetRemoved.setBounds(pictureBoxWidth - 10, 390, 170, 20); + buttonGetRemoved.setBounds(pictureBoxWidth, 330, 160, 20); Frame.add(canv); Frame.add(ButtonAddVehicle); Frame.add(ButtonRemoveTank); Frame.add(ButtonRefreshCollection); Frame.add(TextBoxNumber); - Frame.add(toFormTankGenerate); + Frame.add(FormTankGenerate); + Frame.add(buttonAddSet); Frame.add(textBoxSetName); Frame.add(jListStorage); Frame.add(buttonRemoveSet); + Frame.add(buttonGetRemoved); + Frame.setVisible(true); } } \ No newline at end of file diff --git a/Tank/src/FormTankConfig.java b/Tank/src/FormTankConfig.java new file mode 100644 index 0000000..6a022df --- /dev/null +++ b/Tank/src/FormTankConfig.java @@ -0,0 +1,389 @@ +import java.awt.*; +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.StringSelection; +import java.awt.datatransfer.Transferable; +import java.awt.datatransfer.UnsupportedFlavorException; +import javax.swing.*; +import javax.swing.border.Border; + +import java.awt.event.*; +import java.io.IOException; + +public class FormTankConfig { + private class Canvas extends JComponent { + public Canvas() { } + + public void paintComponent (Graphics g) { + if(_vehicle == null) { + return; + } + super.paintComponents(g); + Graphics2D g2d = (Graphics2D)g; + _vehicle.DrawTransport(g2d); + super.repaint(); + } + } + + //Класс для перетаскивания объекта на формочку + private class LabelTransferHandler extends TransferHandler { + @Override + public int getSourceActions(JComponent c) { return TransferHandler.COPY; } + + @Override + protected Transferable createTransferable (JComponent c) { return new StringSelection(((JLabel)c).getText()); } + } + + // Класс для возможности передвижения цвета + private class ColorTransferable implements Transferable { + private Color color; + private static final DataFlavor colorDataFlavor = new DataFlavor(Color.class, "Color"); + public ColorTransferable(Color color) { this.color = color; } + + @Override + public DataFlavor[] getTransferDataFlavors() { return new DataFlavor[]{ colorDataFlavor }; } + + @Override + public boolean isDataFlavorSupported(DataFlavor flavor) { return colorDataFlavor.equals(flavor); } + + @Override + public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { + if(isDataFlavorSupported(flavor)) { + return color; + } else { + throw new UnsupportedFlavorException(flavor); + } + } + } + + // Для перетаскивания цвета к объекту + private class PanelTransferHandler extends TransferHandler { + @Override + public int getSourceActions(JComponent c) { return TransferHandler.COPY; } + + @Override + protected Transferable createTransferable(JComponent c) { + return new ColorTransferable(((JPanel)c).getBackground()); + } + } + + // Для обработки нажатий + private class LabelMouseAdapter extends MouseAdapter { + @Override + public void mousePressed(MouseEvent e) { + ((JLabel)e.getComponent()).getTransferHandler().exportAsDrag(((JLabel)e.getComponent()), e, TransferHandler.COPY); + } + } + + private class PanelMouseAdapter extends MouseAdapter { + @Override + public void mousePressed(MouseEvent e) { + ((JPanel)e.getComponent()).getTransferHandler().exportAsDrag(((JPanel)e.getComponent()), e, TransferHandler.COPY); + } + } + + // Для передвижения wheels по формочке + private class WheelTransferable implements Transferable { + private IOrnamentForm wheelDrawing; + private static final DataFlavor wheelDrawingDataFlavor = new DataFlavor(IOrnamentForm.class, "Wheel Drawing"); + public WheelTransferable(IOrnamentForm wheelDrawing) { this.wheelDrawing = wheelDrawing; } + + @Override + public boolean isDataFlavorSupported(DataFlavor flavor) { return flavor.equals(wheelDrawingDataFlavor); } + + @Override + public DataFlavor[] getTransferDataFlavors() { return new DataFlavor[] { wheelDrawingDataFlavor }; } + + @Override + public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { + if(isDataFlavorSupported(flavor)) { + return wheelDrawing; + } else { + throw new UnsupportedFlavorException(flavor); + } + } + } + + // Для отрисовки wheels, которые можно брать и перетаскивать на объект + private class ComponentWheel extends JComponent { + public IOrnamentForm wheelDrawing; + + // Конструктор + public ComponentWheel(IOrnamentForm _wheelDrawing) { + wheelDrawing = _wheelDrawing; + this.addMouseListener( + new MouseAdapter() { + @Override + public void mousePressed(MouseEvent e) { + ((ComponentWheel) e.getComponent()).getTransferHandler().exportAsDrag(((ComponentWheel) e.getComponent()), e, TransferHandler.COPY); + } + }); + this.setTransferHandler( + new TransferHandler() { + @Override + public int getSourceActions(JComponent c) { + return TransferHandler.COPY; + } + + @Override + protected Transferable createTransferable(JComponent c) { + return new WheelTransferable(((ComponentWheel)c).wheelDrawing); + } + } + ); + } + + public void paintComponent(Graphics g) { + super.paintComponent(g); + Graphics2D g2d = (Graphics2D) g; + wheelDrawing.Draw(g2d,-10, -42); //!!!! + super.repaint(); + } + } + + final int WindowHeight = 700; + final int WindowWidth = 1000; + final int CanvasHeight = 600; + final int CanvasWidth = 800; + public DrawingArmoVehicle _vehicle = null; + public JButton buttonAdd; + public JFrame Frame; + public Canvas canvas; + + public FormTankConfig() { + Border border = BorderFactory.createLineBorder(Color.GRAY); + JLabel labelSpeed = new JLabel("Speed"); + JLabel labelWeight = new JLabel("Weight"); + JLabel labelWheelNum = new JLabel("Wheel"); + SpinnerModel spinnerModel = new SpinnerNumberModel(100, 100, 1000, 1); + JSpinner numericSpeed = new JSpinner(spinnerModel); + SpinnerModel spinnerModel2 = new SpinnerNumberModel(100, 100, 1000, 1); + JSpinner numericWeight = new JSpinner(spinnerModel2); + SpinnerModel spinnerModel3 = new SpinnerNumberModel(2, 2, 5, 1); + JSpinner numericWheelNum = new JSpinner(spinnerModel3); + JCheckBox checkBoxBodyKit = new JCheckBox("BodyKit"); + JCheckBox checkBoxCaterpillar = new JCheckBox("Caterpillar"); + JCheckBox checkBoxTower = new JCheckBox("Tower"); + JPanel[] colorPanels = { + new JPanel(),new JPanel(),new JPanel(),new JPanel(), + new JPanel(),new JPanel(),new JPanel(),new JPanel(), + }; + colorPanels[0].setBackground(Color.BLACK); + colorPanels[1].setBackground(Color.BLUE); + colorPanels[2].setBackground(Color.GRAY); + colorPanels[3].setBackground(Color.YELLOW); + colorPanels[4].setBackground(Color.RED); + colorPanels[5].setBackground(Color.GREEN); + colorPanels[6].setBackground(Color.ORANGE); + colorPanels[7].setBackground(Color.WHITE); + for (var it : colorPanels){ + it.setTransferHandler(new PanelTransferHandler()); + it.addMouseListener(new PanelMouseAdapter()); + } + + JLabel labelArmoVehicle = new JLabel("ArmoVehicle"); + labelArmoVehicle.setTransferHandler(new LabelTransferHandler()); + labelArmoVehicle.addMouseListener(new LabelMouseAdapter()); + labelArmoVehicle.setBorder(border); + labelArmoVehicle.setHorizontalAlignment(SwingConstants.CENTER); + labelArmoVehicle.setVerticalAlignment(SwingConstants.CENTER); + + JLabel labelTank = new JLabel("Tank"); + labelTank.setTransferHandler(new LabelTransferHandler()); + labelTank.addMouseListener(new LabelMouseAdapter()); + labelTank.setBorder(border); + labelTank.setHorizontalAlignment(SwingConstants.CENTER); + labelTank.setVerticalAlignment(SwingConstants.CENTER); + + JLabel labelColor = new JLabel("Color"); + labelColor.setBorder(border); + labelColor.setHorizontalAlignment(SwingConstants.CENTER); + labelColor.setVerticalAlignment(SwingConstants.CENTER); + labelColor.setTransferHandler( + new TransferHandler(){ + @Override + public boolean canImport(TransferSupport support) { + return support.isDataFlavorSupported(ColorTransferable.colorDataFlavor); + } + + @Override + public boolean importData(TransferSupport support) { + if (canImport(support)) { + try { + Color color = (Color) support.getTransferable().getTransferData(ColorTransferable.colorDataFlavor); + if (_vehicle == null) + return false; + _vehicle.ArmoVehicle.setBodyColor(color); + canvas.repaint(); + return true; + } catch (UnsupportedFlavorException | IOException e) { + e.printStackTrace(); + } + } + return false; + } + } + ); + + JLabel labelAdditionalColor = new JLabel("Additional color"); + labelAdditionalColor.setBorder(border); + labelAdditionalColor.setHorizontalAlignment(SwingConstants.CENTER); + labelAdditionalColor.setVerticalAlignment(SwingConstants.CENTER); + labelAdditionalColor.setTransferHandler( + new TransferHandler(){ + @Override + public boolean canImport(TransferSupport support) { + return support.isDataFlavorSupported(ColorTransferable.colorDataFlavor); + } + + @Override + public boolean importData(TransferSupport support) { + if (canImport(support)) { + try { + Color color = (Color) support.getTransferable().getTransferData(ColorTransferable.colorDataFlavor); + if (_vehicle == null) + return false; + if (!(_vehicle instanceof DrawingTank)) + return false; + ((EntityTank)_vehicle.ArmoVehicle).setAdditionalColor(color); + return true; + } catch (UnsupportedFlavorException | IOException e) { + e.printStackTrace(); + } + } + return false; + } + } + ); + + JLabel labelWheel = new JLabel("Wheel"); + labelWheel.setBorder(border); + labelWheel.setHorizontalAlignment(SwingConstants.CENTER); + labelWheel.setVerticalAlignment(SwingConstants.CENTER); + labelWheel.setTransferHandler( + new TransferHandler(){ + @Override + public boolean canImport(TransferSupport support) { + return support.isDataFlavorSupported(WheelTransferable.wheelDrawingDataFlavor); + } + + @Override + public boolean importData(TransferSupport support) { + if (canImport(support)) { + try { + IOrnamentForm wheelDrawing = (IOrnamentForm) support.getTransferable().getTransferData(WheelTransferable.wheelDrawingDataFlavor); + if (_vehicle == null) + return false; + wheelDrawing.setDigit(_vehicle.ArmoVehicle.numWheel); + _vehicle.OrnamentsForm = wheelDrawing; + canvas.repaint(); + } catch (UnsupportedFlavorException | IOException e) { + e.printStackTrace(); + } + } + return false; + } + } + ); + + canvas = new Canvas(); + canvas.setTransferHandler( + new TransferHandler(){ + @Override + public boolean canImport(TransferSupport support) { + return support.isDataFlavorSupported(DataFlavor.stringFlavor); + } + + @Override + public boolean importData(TransferSupport support) { + if (canImport(support)) { + try { + String data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor); + switch (data) { + case "ArmoVehicle": + _vehicle = new DrawingArmoVehicle((int)numericSpeed.getValue(), (int)numericWeight.getValue(), Color.WHITE, (int)numericWheelNum.getValue(), CanvasWidth,CanvasHeight); + break; + case "Tank": + _vehicle = new DrawingTank((int)numericSpeed.getValue(), (int)numericWeight.getValue(), Color.WHITE, (int)numericWheelNum.getValue(), Color.BLACK, checkBoxBodyKit.isSelected(), checkBoxCaterpillar.isSelected(), checkBoxTower.isSelected(), CanvasWidth, CanvasHeight); + break; + } + canvas.repaint(); + return true; + } catch (UnsupportedFlavorException | IOException e) { + e.printStackTrace(); + } + } + return false; + } + } + ); + + buttonAdd = new JButton("Add"); + JButton buttonCancel = new JButton("Cancel"); + + ComponentWheel componentSuspensionOrnament = new ComponentWheel(new DrawingSuspensionOrnament()); + ComponentWheel componentAsteriskOrnament = new ComponentWheel(new DrawingStarOrnament()); + ComponentWheel componentWheelCombination = new ComponentWheel(new DrawingWheelsCombination()); + + labelSpeed.setBounds(10,10,40,20); + labelWeight.setBounds(10,40,40,20); + labelWheelNum.setBounds(10,70,40,20); + numericSpeed.setBounds(55,10,80,20); + numericWeight.setBounds(55,40,80,20); + numericWheelNum.setBounds(55,70,80,20); + checkBoxBodyKit.setBounds(10,100,120,20); + checkBoxCaterpillar.setBounds(10,130,120,20); + checkBoxTower.setBounds(10,160,120,20); + for (int i = 0; i < colorPanels.length; i+=2) { + colorPanels[i].setBounds(10,200+i/2*60,50,50); + colorPanels[i+1].setBounds(70,200+i/2*60,50,50); + } + componentSuspensionOrnament.setBounds(10,470,25,20); //!!!!!!!!!!!!! + componentAsteriskOrnament.setBounds(50,470,20,20); + componentWheelCombination.setBounds(90,470,25,20); + labelArmoVehicle.setBounds(10,600 ,80,30); + labelTank.setBounds(100,600 ,80,30); + + labelColor.setBounds(WindowWidth-CanvasWidth, 10, CanvasWidth/3, 30); + labelAdditionalColor.setBounds(WindowWidth-CanvasWidth + CanvasWidth/3, 10, CanvasWidth/3, 30); + labelWheel.setBounds(WindowWidth-CanvasWidth + CanvasWidth*2/3, 10, CanvasWidth/3, 30); + canvas.setBounds(WindowWidth-CanvasWidth, 50, CanvasWidth, CanvasHeight); + buttonAdd.setBounds(WindowWidth-CanvasWidth, CanvasHeight+60, CanvasWidth/3, 30); + buttonCancel.setBounds(WindowWidth-CanvasWidth + CanvasWidth*2/3, CanvasHeight+60, CanvasWidth/3, 30); + + Frame = new JFrame(); + Frame.setSize (WindowWidth+20, WindowHeight+40); + Frame.setLayout(null); + Frame.add(labelSpeed); + Frame.add(labelWeight); + Frame.add(labelWheelNum); + Frame.add(numericSpeed); + Frame.add(numericWeight); + Frame.add(numericWheelNum); + Frame.add(checkBoxBodyKit); + Frame.add(checkBoxCaterpillar); + Frame.add(checkBoxTower); + for (var it : colorPanels) + Frame.add(it); + Frame.add(labelArmoVehicle); + Frame.add(labelTank); + Frame.add(labelColor); + Frame.add(labelAdditionalColor); + Frame.add(labelWheel); + Frame.add(canvas); + Frame.add(buttonAdd); + Frame.add(buttonCancel); + Frame.add(componentSuspensionOrnament); + Frame.add(componentAsteriskOrnament); + Frame.add(componentWheelCombination); + + Frame.setVisible(true); + + buttonCancel.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e){ + Frame.dispose(); + } + } + ); + } +} \ No newline at end of file diff --git a/Tank/src/FormTankGenerate.java b/Tank/src/FormTankGenerate.java index 3d9c91d..0e95bdf 100644 --- a/Tank/src/FormTankGenerate.java +++ b/Tank/src/FormTankGenerate.java @@ -41,9 +41,9 @@ public class FormTankGenerate extends JFrame { creatButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e){ - _drawingTank = genericTankGenerate.GenerateTank(pictureBoxWidth,pictureBoxHeight); - canv.repaint(); - } + _drawingTank = genericTankGenerate.GenerateTank(pictureBoxWidth,pictureBoxHeight); + canv.repaint(); + } } ); creatButton.setBounds(pictureBoxWidth/2 - 40, pictureBoxHeight-20, 180, 20); diff --git a/Tank/src/SetGeneric.java b/Tank/src/SetGeneric.java index 7ab88d6..7134ffc 100644 --- a/Tank/src/SetGeneric.java +++ b/Tank/src/SetGeneric.java @@ -4,7 +4,7 @@ public class SetGeneric { // Массив объектов, которые храним private final ArrayList _places; // Количество объектов в массиве - public int Count() { return _places.size(); } + public int Count() { return _places.size(); } // Максимальное количество объектов в списке private final int _maxCount; @@ -44,7 +44,7 @@ public class SetGeneric { if (position < 0 || position >= _places.size()) return false; _places.remove(position); - return true; + return true; } // Получение объекта из набора по позиции diff --git a/Tank/src/TanksGenericCollections.java b/Tank/src/TanksGenericCollections.java index 4c6d961..6a9654b 100644 --- a/Tank/src/TanksGenericCollections.java +++ b/Tank/src/TanksGenericCollections.java @@ -72,6 +72,8 @@ public class TanksGenericCollections Date: Thu, 30 Nov 2023 20:17:42 +0400 Subject: [PATCH 02/12] fix 5 lab --- Tank/.idea/misc.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/Tank/.idea/misc.xml b/Tank/.idea/misc.xml index 1e4328b..5d30da4 100644 --- a/Tank/.idea/misc.xml +++ b/Tank/.idea/misc.xml @@ -1,3 +1,4 @@ + -- 2.25.1 From 6326cef5f297cd87fd6f12e27a5517572fc1cd98 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: Thu, 30 Nov 2023 20:19:02 +0400 Subject: [PATCH 03/12] fix 5 lab --- Tank/src/FormTankGenerate.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tank/src/FormTankGenerate.java b/Tank/src/FormTankGenerate.java index 0e95bdf..3f1e687 100644 --- a/Tank/src/FormTankGenerate.java +++ b/Tank/src/FormTankGenerate.java @@ -41,8 +41,8 @@ public class FormTankGenerate extends JFrame { creatButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e){ - _drawingTank = genericTankGenerate.GenerateTank(pictureBoxWidth,pictureBoxHeight); - canv.repaint(); + _drawingTank = genericTankGenerate.GenerateTank(pictureBoxWidth,pictureBoxHeight); + canv.repaint(); } } ); -- 2.25.1 From 9829e4a9a5142b224eb0be7c86b24df977e23979 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: Thu, 30 Nov 2023 20:19:42 +0400 Subject: [PATCH 04/12] fix 5 lab --- Tank/src/SetGeneric.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tank/src/SetGeneric.java b/Tank/src/SetGeneric.java index 7134ffc..7ab88d6 100644 --- a/Tank/src/SetGeneric.java +++ b/Tank/src/SetGeneric.java @@ -4,7 +4,7 @@ public class SetGeneric { // Массив объектов, которые храним private final ArrayList _places; // Количество объектов в массиве - public int Count() { return _places.size(); } + public int Count() { return _places.size(); } // Максимальное количество объектов в списке private final int _maxCount; @@ -44,7 +44,7 @@ public class SetGeneric { if (position < 0 || position >= _places.size()) return false; _places.remove(position); - return true; + return true; } // Получение объекта из набора по позиции -- 2.25.1 From b79b037e9e092b719555c024d328b9fb9d3c06ef 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: Thu, 30 Nov 2023 20:28:42 +0400 Subject: [PATCH 05/12] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tank/Tank.iml | 11 +++++++++++ Tank/src/DrawingTank.java | 2 ++ Tank/src/FormTankCollection.java | 28 ++++++++++++++-------------- 3 files changed, 27 insertions(+), 14 deletions(-) create mode 100644 Tank/Tank.iml diff --git a/Tank/Tank.iml b/Tank/Tank.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Tank/Tank.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Tank/src/DrawingTank.java b/Tank/src/DrawingTank.java index 14d971c..1e319fa 100644 --- a/Tank/src/DrawingTank.java +++ b/Tank/src/DrawingTank.java @@ -4,6 +4,7 @@ public class DrawingTank extends DrawingArmoVehicle { protected IOrnamentForm OrnamentsForm; private boolean OrnamentAdd; + // Конструктор (Инициализация характеристик) public DrawingTank(int speed, double weight, Color bodyColor, int _numWheel, Color additionalColor, boolean bodyKit, boolean caterpillar, boolean tower, int width, int height, boolean ornamentAdd) { super(speed, weight, bodyColor, _numWheel, width, height); ArmoVehicle = new EntityTank(speed, weight, bodyColor, _numWheel, additionalColor, bodyKit, caterpillar, tower); @@ -12,6 +13,7 @@ public class DrawingTank extends DrawingArmoVehicle { this.OrnamentAdd = ornamentAdd; } + // Ещё один конструктор public DrawingTank(int speed, float weight, Color bodyColor, int _numWheel, Color additionalColor, boolean bodyKit, boolean caterpillar, boolean tower, int width, int height) { super(speed, weight, bodyColor, _numWheel, width, height); ArmoVehicle=new EntityTank(speed,weight,bodyColor,_numWheel, additionalColor,bodyKit,caterpillar, tower); diff --git a/Tank/src/FormTankCollection.java b/Tank/src/FormTankCollection.java index f0aa8b5..a0b96b0 100644 --- a/Tank/src/FormTankCollection.java +++ b/Tank/src/FormTankCollection.java @@ -152,14 +152,14 @@ public class FormTankCollection { JButton ButtonRefreshCollection = new JButton("Обновить коллекцию"); ButtonRefreshCollection.addActionListener( new ActionListener() { - public void actionPerformed(ActionEvent e) { + public void actionPerformed(ActionEvent e){ Draw(); } } ); - JButton FormTankGenerate = new JButton("Генерация"); - FormTankGenerate.addActionListener( + JButton toFormTankGenerate = new JButton("Генерировать технику"); + toFormTankGenerate.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { FormTankGenerate formTankGenerate = new FormTankGenerate(); @@ -210,25 +210,25 @@ public class FormTankCollection { Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Frame.setLayout(null); canv.setBounds(0, 0, pictureBoxWidth, pictureBoxHeight); - ButtonAddVehicle.setBounds(pictureBoxWidth, 0, 160, 20); - TextBoxNumber.setBounds(pictureBoxWidth, 30, 160, 20); - ButtonRemoveTank.setBounds(pictureBoxWidth, 60, 160, 20); - ButtonRefreshCollection.setBounds(pictureBoxWidth, 90, 160, 20); - FormTankGenerate.setBounds(pictureBoxWidth, 120, 160, 20); + ButtonAddVehicle.setBounds(pictureBoxWidth - 10, 10, 170, 30); + TextBoxNumber.setBounds(pictureBoxWidth - 10, 50, 170, 30); + ButtonRemoveTank.setBounds(pictureBoxWidth - 10, 90, 170, 30); + ButtonRefreshCollection.setBounds(pictureBoxWidth - 10, 130, 170, 30); + toFormTankGenerate.setBounds(pictureBoxWidth - 10, 170, 170, 30); - buttonAddSet.setBounds(pictureBoxWidth, 150, 160, 20); - textBoxSetName.setBounds(pictureBoxWidth, 180, 160, 20); - jListStorage.setBounds(pictureBoxWidth, 210, 160, 80); - buttonRemoveSet.setBounds(pictureBoxWidth, 300, 160, 20); + buttonAddSet.setBounds(pictureBoxWidth - 10, 210, 170, 20); + textBoxSetName.setBounds(pictureBoxWidth - 10, 240, 170, 20); + jListStorage.setBounds(pictureBoxWidth - 10, 270, 170, 80); + buttonRemoveSet.setBounds(pictureBoxWidth - 10, 360, 170, 20); - buttonGetRemoved.setBounds(pictureBoxWidth, 330, 160, 20); + buttonGetRemoved.setBounds(pictureBoxWidth - 10, 390, 170, 20); Frame.add(canv); Frame.add(ButtonAddVehicle); Frame.add(ButtonRemoveTank); Frame.add(ButtonRefreshCollection); Frame.add(TextBoxNumber); - Frame.add(FormTankGenerate); + Frame.add(toFormTankGenerate); Frame.add(buttonAddSet); Frame.add(textBoxSetName); -- 2.25.1 From 767f265a610f77bb31522557a69a8307131cf176 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: Thu, 30 Nov 2023 20:45:01 +0400 Subject: [PATCH 06/12] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tank/src/DrawingWheelsCombination.java | 34 +++++++++++++++----------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/Tank/src/DrawingWheelsCombination.java b/Tank/src/DrawingWheelsCombination.java index f0737df..0673bc0 100644 --- a/Tank/src/DrawingWheelsCombination.java +++ b/Tank/src/DrawingWheelsCombination.java @@ -36,6 +36,12 @@ public class DrawingWheelsCombination implements IOrnamentForm { g.fillPolygon(xPontsStar, yPontsStar, xPontsStar.length); } + public void DrawSuspension(Graphics g, int _startPosX, int _startPosY) { + CombinationColor = Color.BLUE; + g.setColor(CombinationColor); + g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); + } + public void DrawWheels(Graphics g, int _startPosX, int _startPosY) { g.setColor(Color.BLACK); g.fillOval(10 + _startPosX, 42 + _startPosY, 20, 20); @@ -43,15 +49,15 @@ public class DrawingWheelsCombination implements IOrnamentForm { public void Draw(Graphics g, int _startPosX, int _startPosY) { DrawWheels(g,_startPosX, _startPosY); - g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); + DrawSuspension(g, _startPosX, _startPosY); CaterpillarStar(g,_startPosX + 5, _startPosY + 12); if (wheels == CountWheels.Two){ DrawWheels(g,_startPosX, _startPosY); DrawWheels(g,_startPosX + 100, _startPosY); - g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); - g.fillRect(_startPosX + 101, _startPosY + 50, 10, 3); + DrawSuspension(g, _startPosX, _startPosY); + DrawSuspension(g,_startPosX + 73, _startPosY); CaterpillarStar(g,_startPosX + 5, _startPosY + 12); CaterpillarStar(g,_startPosX + 105, _startPosY + 12); @@ -62,9 +68,9 @@ public class DrawingWheelsCombination implements IOrnamentForm { DrawWheels(g,_startPosX + 50, _startPosY); DrawWheels(g,_startPosX + 100, _startPosY); - g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); - g.fillRect(_startPosX + 51, _startPosY + 50, 10, 3); - g.fillRect(_startPosX + 100, _startPosY + 50, 10, 3); + DrawSuspension(g, _startPosX, _startPosY); + DrawSuspension(g,_startPosX + 24, _startPosY); + DrawSuspension(g,_startPosX + 73, _startPosY); CaterpillarStar(g,_startPosX + 5, _startPosY + 12); @@ -78,10 +84,10 @@ public class DrawingWheelsCombination implements IOrnamentForm { DrawWheels(g,_startPosX + 50, _startPosY); DrawWheels(g,_startPosX + 100, _startPosY); - g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); - g.fillRect(_startPosX + 51, _startPosY + 50, 10, 3); - g.fillRect(_startPosX + 80, _startPosY + 50, 10, 3); - g.fillRect(_startPosX + 101, _startPosY + 50, 10, 3); + DrawSuspension(g, _startPosX, _startPosY); + DrawSuspension(g,_startPosX + 24, _startPosY); + DrawSuspension(g,_startPosX + 53, _startPosY); + DrawSuspension(g,_startPosX + 73, _startPosY); CaterpillarStar(g,_startPosX + 5, _startPosY + 12); CaterpillarStar(g,_startPosX + 30, _startPosY + 12); @@ -96,10 +102,10 @@ public class DrawingWheelsCombination implements IOrnamentForm { DrawWheels(g,_startPosX + 75, _startPosY); DrawWheels(g,_startPosX + 100, _startPosY); - g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); - g.fillRect(_startPosX + 51, _startPosY + 50, 10, 3); - g.fillRect(_startPosX + 80, _startPosY + 50, 10, 3); - g.fillRect(_startPosX + 101, _startPosY + 50, 10, 3); + DrawSuspension(g, _startPosX, _startPosY); + DrawSuspension(g,_startPosX + 24, _startPosY); + DrawSuspension(g,_startPosX + 53, _startPosY); + DrawSuspension(g,_startPosX + 73, _startPosY); CaterpillarStar(g,_startPosX + 5, _startPosY + 12); CaterpillarStar(g,_startPosX + 30, _startPosY + 12); -- 2.25.1 From 6522e6933a5c421d08b9c99bfde269f9597bb095 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: Thu, 30 Nov 2023 20:49:50 +0400 Subject: [PATCH 07/12] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tank/src/DrawingSuspensionOrnament.java | 29 +++++++++++++++---------- Tank/src/DrawingWheelsCombination.java | 1 - 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Tank/src/DrawingSuspensionOrnament.java b/Tank/src/DrawingSuspensionOrnament.java index 33712f0..7af7ff7 100644 --- a/Tank/src/DrawingSuspensionOrnament.java +++ b/Tank/src/DrawingSuspensionOrnament.java @@ -32,17 +32,22 @@ public class DrawingSuspensionOrnament implements IOrnamentForm { g.fillOval(10 + _startPosX, 42 + _startPosY, 20, 20); } + public void DrawSuspension(Graphics g, int _startPosX, int _startPosY) { + SuspensionColor = Color.BLUE; + g.setColor(SuspensionColor); + g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); + } + public void Draw(Graphics g, int _startPosX, int _startPosY) { DrawWheels(g,_startPosX, _startPosY); - g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); + DrawSuspension(g, _startPosX, _startPosY); if (wheels == CountWheels.Two) { DrawWheels(g,_startPosX, _startPosY); DrawWheels(g,_startPosX + 100, _startPosY); - SuspensionColor = Color.RED; - g.setColor(SuspensionColor); - g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); - g.fillRect(_startPosX + 51, _startPosY + 50, 10, 3); + + DrawSuspension(g, _startPosX, _startPosY); + DrawSuspension(g,_startPosX + 73, _startPosY); } if (wheels == CountWheels.Three) { @@ -50,9 +55,9 @@ public class DrawingSuspensionOrnament implements IOrnamentForm { DrawWheels(g,_startPosX + 50, _startPosY); DrawWheels(g,_startPosX + 100, _startPosY); - g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); - g.fillRect(_startPosX + 51, _startPosY + 50, 10, 3); - g.fillRect(_startPosX + 80, _startPosY + 50, 10, 3); + DrawSuspension(g, _startPosX, _startPosY); + DrawSuspension(g,_startPosX + 24, _startPosY); + DrawSuspension(g,_startPosX + 73, _startPosY); } if (wheels == CountWheels.Four || wheels == CountWheels.Five) { @@ -63,10 +68,10 @@ public class DrawingSuspensionOrnament implements IOrnamentForm { DrawWheels(g,_startPosX + 75, _startPosY); DrawWheels(g,_startPosX + 100, _startPosY); - g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); - g.fillRect(_startPosX + 51, _startPosY + 50, 10, 3); - g.fillRect(_startPosX + 80, _startPosY + 50, 10, 3); - g.fillRect(_startPosX + 101, _startPosY + 50, 10, 3); + DrawSuspension(g, _startPosX, _startPosY); + DrawSuspension(g,_startPosX + 24, _startPosY); + DrawSuspension(g,_startPosX + 53, _startPosY); + DrawSuspension(g,_startPosX + 73, _startPosY); } } } \ No newline at end of file diff --git a/Tank/src/DrawingWheelsCombination.java b/Tank/src/DrawingWheelsCombination.java index 0673bc0..af8f722 100644 --- a/Tank/src/DrawingWheelsCombination.java +++ b/Tank/src/DrawingWheelsCombination.java @@ -72,7 +72,6 @@ public class DrawingWheelsCombination implements IOrnamentForm { DrawSuspension(g,_startPosX + 24, _startPosY); DrawSuspension(g,_startPosX + 73, _startPosY); - CaterpillarStar(g,_startPosX + 5, _startPosY + 12); CaterpillarStar(g,_startPosX + 55, _startPosY + 12); CaterpillarStar(g,_startPosX + 105, _startPosY + 12); -- 2.25.1 From 95ba108e2cdcc6e323e44380c89e5eb54f424d1f 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: Thu, 30 Nov 2023 20:50:53 +0400 Subject: [PATCH 08/12] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tank/src/DrawingSuspensionOrnament.java | 1 - 1 file changed, 1 deletion(-) diff --git a/Tank/src/DrawingSuspensionOrnament.java b/Tank/src/DrawingSuspensionOrnament.java index 7af7ff7..9d486a2 100644 --- a/Tank/src/DrawingSuspensionOrnament.java +++ b/Tank/src/DrawingSuspensionOrnament.java @@ -61,7 +61,6 @@ public class DrawingSuspensionOrnament implements IOrnamentForm { } if (wheels == CountWheels.Four || wheels == CountWheels.Five) { - // Можно подкорректировать с 4ой и 5ой, чтобы с колёсами было чуть поточнее DrawWheels(g,_startPosX, _startPosY); DrawWheels(g,_startPosX + 25, _startPosY); DrawWheels(g,_startPosX + 50, _startPosY); -- 2.25.1 From 1f88f2883e29f036fd1f4195e3d716324d68aea8 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: Thu, 30 Nov 2023 21:00:16 +0400 Subject: [PATCH 09/12] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tank/src/DrawingStarOrnament.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tank/src/DrawingStarOrnament.java b/Tank/src/DrawingStarOrnament.java index 07af097..13a5b20 100644 --- a/Tank/src/DrawingStarOrnament.java +++ b/Tank/src/DrawingStarOrnament.java @@ -30,7 +30,7 @@ public class DrawingStarOrnament implements IOrnamentForm { public void CaterpillarStar(Graphics g, int _startPosX, int _startPosY) { StarColor = Color.RED; g.setColor(StarColor); - int xPontsStar[] = {_startPosX + 15, _startPosX + 18, _startPosX + 21, _startPosX + 18, _startPosX + 19, _startPosX + 16, _startPosX + 12, _startPosX + 13, _startPosX + 12, _startPosX + 15, _startPosX + 16}; + int xPontsStar[] = {_startPosX + 15, _startPosX + 18, _startPosX + 21, _startPosX + 18, _startPosX + 19, _startPosX + 16, _startPosX + 12, _startPosX + 12, _startPosX + 11, _startPosX + 15, _startPosX + 16}; int yPontsStar[] = {_startPosY + 35, _startPosY + 38, _startPosY + 38, _startPosY + 42, _startPosY + 45, _startPosY + 42, _startPosY + 45, _startPosY + 41, _startPosY + 38, _startPosY + 38, _startPosY + 35}; g.drawPolygon(xPontsStar, yPontsStar, xPontsStar.length); g.fillPolygon(xPontsStar, yPontsStar, xPontsStar.length); -- 2.25.1 From 397c4068b8588ac072f111fc2805bad0fcf1ee1e 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: Thu, 30 Nov 2023 21:56:47 +0400 Subject: [PATCH 10/12] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tank/src/DrawingWheelsCombination.java | 2 +- Tank/src/FormTankConfig.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Tank/src/DrawingWheelsCombination.java b/Tank/src/DrawingWheelsCombination.java index af8f722..5eb136d 100644 --- a/Tank/src/DrawingWheelsCombination.java +++ b/Tank/src/DrawingWheelsCombination.java @@ -42,7 +42,7 @@ public class DrawingWheelsCombination implements IOrnamentForm { g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); } - public void DrawWheels(Graphics g, int _startPosX, int _startPosY) { + public void DrawWheels(Graphics g, int _startPosX, int _startPosY){ g.setColor(Color.BLACK); g.fillOval(10 + _startPosX, 42 + _startPosY, 20, 20); } diff --git a/Tank/src/FormTankConfig.java b/Tank/src/FormTankConfig.java index 6a022df..29d839e 100644 --- a/Tank/src/FormTankConfig.java +++ b/Tank/src/FormTankConfig.java @@ -82,7 +82,7 @@ public class FormTankConfig { } // Для передвижения wheels по формочке - private class WheelTransferable implements Transferable { + private class WheelTransferable implements Transferable { private IOrnamentForm wheelDrawing; private static final DataFlavor wheelDrawingDataFlavor = new DataFlavor(IOrnamentForm.class, "Wheel Drawing"); public WheelTransferable(IOrnamentForm wheelDrawing) { this.wheelDrawing = wheelDrawing; } -- 2.25.1 From 98c35a61c00a8ba76d87a58a97df77742179e630 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: Thu, 30 Nov 2023 22:36:53 +0400 Subject: [PATCH 11/12] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tank/src/FormTankConfig.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Tank/src/FormTankConfig.java b/Tank/src/FormTankConfig.java index 29d839e..37a5413 100644 --- a/Tank/src/FormTankConfig.java +++ b/Tank/src/FormTankConfig.java @@ -135,7 +135,7 @@ public class FormTankConfig { public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; - wheelDrawing.Draw(g2d,-10, -42); //!!!! + wheelDrawing.Draw(g2d,-10, -42); super.repaint(); } } @@ -231,12 +231,12 @@ public class FormTankConfig { labelAdditionalColor.setTransferHandler( new TransferHandler(){ @Override - public boolean canImport(TransferSupport support) { + public boolean canImport(TransferHandler.TransferSupport support) { return support.isDataFlavorSupported(ColorTransferable.colorDataFlavor); } @Override - public boolean importData(TransferSupport support) { + public boolean importData(TransferHandler.TransferSupport support) { if (canImport(support)) { try { Color color = (Color) support.getTransferable().getTransferData(ColorTransferable.colorDataFlavor); @@ -262,12 +262,12 @@ public class FormTankConfig { labelWheel.setTransferHandler( new TransferHandler(){ @Override - public boolean canImport(TransferSupport support) { + public boolean canImport(TransferHandler.TransferSupport support) { return support.isDataFlavorSupported(WheelTransferable.wheelDrawingDataFlavor); } @Override - public boolean importData(TransferSupport support) { + public boolean importData(TransferHandler.TransferSupport support) { if (canImport(support)) { try { IOrnamentForm wheelDrawing = (IOrnamentForm) support.getTransferable().getTransferData(WheelTransferable.wheelDrawingDataFlavor); @@ -289,12 +289,12 @@ public class FormTankConfig { canvas.setTransferHandler( new TransferHandler(){ @Override - public boolean canImport(TransferSupport support) { + public boolean canImport(TransferHandler.TransferSupport support) { return support.isDataFlavorSupported(DataFlavor.stringFlavor); } @Override - public boolean importData(TransferSupport support) { + public boolean importData(TransferHandler.TransferSupport support) { if (canImport(support)) { try { String data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor); @@ -337,7 +337,7 @@ public class FormTankConfig { colorPanels[i].setBounds(10,200+i/2*60,50,50); colorPanels[i+1].setBounds(70,200+i/2*60,50,50); } - componentSuspensionOrnament.setBounds(10,470,25,20); //!!!!!!!!!!!!! + componentSuspensionOrnament.setBounds(10,470,25,20); componentAsteriskOrnament.setBounds(50,470,20,20); componentWheelCombination.setBounds(90,470,25,20); labelArmoVehicle.setBounds(10,600 ,80,30); -- 2.25.1 From 8c23720f0f7a5a6e070ae021879a67f328f0b9e9 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: Thu, 30 Nov 2023 22:38:22 +0400 Subject: [PATCH 12/12] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tank/src/EntityArmoVehicle.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tank/src/EntityArmoVehicle.java b/Tank/src/EntityArmoVehicle.java index 11ecf8d..79bf519 100644 --- a/Tank/src/EntityArmoVehicle.java +++ b/Tank/src/EntityArmoVehicle.java @@ -7,7 +7,7 @@ public class EntityArmoVehicle { return Weight; } public Color BodyColor; - public void setBodyColor(Color color){ BodyColor = color; } + public void setBodyColor(Color color) { BodyColor = color; } public double Step; public int numWheel; -- 2.25.1