diff --git a/DrawingContainerShip.java b/DrawingContainerShip.java index ef37b6f..eb214c1 100644 --- a/DrawingContainerShip.java +++ b/DrawingContainerShip.java @@ -2,16 +2,31 @@ import java.awt.*; public class DrawingContainerShip extends DrawingShip { - public DrawingContainerShip(int speed, float weight, Color bodyColor, Color dopColor, boolean crane, boolean containers) + private Color dopColor; + public DrawingContainerShip(int speed, float weight, Color bodyColor,int numdeck,Color dopColor,boolean crane,boolean containers) { - super(speed,weight,bodyColor,130,45); + super(speed,weight,bodyColor,numdeck,130,45); Ship = new EntityContainerShip(speed, weight, bodyColor, dopColor, crane, containers); + this.dopColor=dopColor; } protected DrawingContainerShip(EntityShip ship,IAdditionalDrawingObject deck) { super(ship,deck); Ship=ship; } + public void SetDopColor(Color color) + { + var temp = (EntityContainerShip) Ship; + Ship=new EntityContainerShip(temp.GetSpeed(),temp.GetWeight(),temp.GetBodyColor(),color,temp.GetCrane(),temp.GetContainers()); + dopColor=color; + } + @Override + public void SetColor(Color color) + { + var temp = (EntityContainerShip) Ship; + dopColor = dopColor==null? Color.WHITE : dopColor; + Ship=new EntityContainerShip(temp.GetSpeed(),temp.GetWeight(),color,dopColor,temp.GetCrane(),temp.GetContainers()); + } @Override public void DrawTransport(Graphics g) { if (!(GetShip() instanceof EntityContainerShip containerShip)) diff --git a/DrawingObjectShip.java b/DrawingObjectShip.java index dc419c7..851054b 100644 --- a/DrawingObjectShip.java +++ b/DrawingObjectShip.java @@ -13,6 +13,7 @@ public class DrawingObjectShip implements IDrawingObject { } return 0; } + @Override public DrawingShip GetDrawingObjectShip() { return _ship; } diff --git a/DrawingShip.java b/DrawingShip.java index aa6cfbf..20ef30a 100644 --- a/DrawingShip.java +++ b/DrawingShip.java @@ -1,27 +1,27 @@ import javax.swing.*; import java.awt.*; import java.util.Random; -public class DrawingShip extends JPanel { +import java.util.Set; + +public class DrawingShip extends JComponent{ protected EntityShip Ship; - public IAdditionalDrawingObject Deck; - public void SetEnum() { - Random r = new Random(); - int numbEnum = r.nextInt(1, 4); - Deck.SetAddEnum(numbEnum); - } - public void SetFormEnum() + protected IAdditionalDrawingObject Deck; + public void SetColor(Color color) { - Random r = new Random(); - int numbEnum = r.nextInt(1, 4); - if (numbEnum == 1) { - Deck = new DrawingDeck(); - } - if (numbEnum == 2) { - Deck = new DrawingOvalDeck(); - } - if (numbEnum == 3) { - Deck=new DrawingTrapezDeck(); - } + Ship=new EntityShip(Ship.GetSpeed(),Ship.GetWeight(),color); + } + public IAdditionalDrawingObject GetDeck() + { + return Deck; + } + public void SetFormEnum(int decksnum,IAdditionalDrawingObject deck) + { + Deck=deck; + Deck.SetAddEnum(decksnum); + } + public void SetDeck(IAdditionalDrawingObject deck) + { + Deck=deck; } public EntityShip GetShip() { return Ship; @@ -32,14 +32,25 @@ public class DrawingShip extends JPanel { private Integer _pictureHeight = null; private int _shipWidth = 100; private int _shipHeight = 60; - public DrawingShip(int speed, float weight, Color bodycolor) { + public DrawingShip(int speed, float weight, Color bodycolor,int numdeck) { Ship = new EntityShip(speed, weight, bodycolor); - SetFormEnum(); - SetEnum(); + Deck = new DrawingTrapezDeck(); + Random r = new Random(); + int numbEnum = r.nextInt(1, 4); + if (numbEnum == 1) { + Deck=new DrawingDeck(); + } + if (numbEnum == 2) { + Deck = new DrawingOvalDeck(); + } + if (numbEnum == 3) { + Deck = new DrawingTrapezDeck(); + } + Deck.SetAddEnum(numdeck); } - public DrawingShip(int speed,float weight,Color bodyColor,int shipWidth,int shipHeight) + public DrawingShip(int speed,float weight,Color bodyColor,int numdeck,int shipWidth,int shipHeight) { - this(speed,weight,bodyColor); + this(speed,weight,bodyColor, numdeck); _shipWidth = shipWidth; _shipHeight = shipHeight; } diff --git a/FormMapWithSetShipsGeneric.java b/FormMapWithSetShipsGeneric.java index d04c3fe..da82121 100644 --- a/FormMapWithSetShipsGeneric.java +++ b/FormMapWithSetShipsGeneric.java @@ -24,9 +24,9 @@ public class FormMapWithSetShipsGeneric extends JFrame{ private JButton ButtonRight; private JTextField maskedTextBoxPosition; private JTextField textBoxNewMapName; - private int picWidth=600; + private final int picWidth=600; - private int picHeight=400; + private final int picHeight=400; private JButton ButtonAddMap; private JList ListBoxMaps; private JButton ButtonDeleteMap; @@ -89,24 +89,24 @@ public class FormMapWithSetShipsGeneric extends JFrame{ ButtonAddShip.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - if (ListBoxMaps.getSelectedIndex() == -1) - { - return; - } - FormShip form = new FormShip(); - form.setSize(1000,700); - form.setVisible(true); - form.setModal(true); - DrawingObjectShip ship = new DrawingObjectShip(form.GetSelectedShip()); - if(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).Add(ship)!=-1) - { - JOptionPane.showMessageDialog(null,"Объект добавлен"); - UpdateWindow(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).ShowSet()); - } - else - { - JOptionPane.showMessageDialog(null, "Не удалось добавить объект"); - } + FormShipConfig formShipConfig = new FormShipConfig(); + formShipConfig.AddEvent(newShip -> { + if (ListBoxMaps.getSelectedIndex() == -1) { + return; + } + if (newShip != null) { + DrawingObjectShip ship = new DrawingObjectShip(newShip); + if (_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).Add(ship) != -1) { + JOptionPane.showMessageDialog(null, "Объект добавлен"); + UpdateWindow(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).ShowSet()); + } else { + JOptionPane.showMessageDialog(null, "Не удалось добавить объект"); + } + } + + }); + formShipConfig.setSize(850, 300); + formShipConfig.setVisible(true); } }); ListBoxMaps.addListSelectionListener(new ListSelectionListener() { diff --git a/FormShip.java b/FormShip.java index eed562f..f533413 100644 --- a/FormShip.java +++ b/FormShip.java @@ -28,6 +28,11 @@ public class FormShip extends JDialog{ { return SelectedShip; } + public int SetEnum() { + Random r = new Random(); + int numbEnum = r.nextInt(1, 4); + return numbEnum; + } public void Draw(DrawingShip _ship) { pictureBoxShip.removeAll(); BufferedImage bmp = new BufferedImage(pictureBoxShip.getWidth(), pictureBoxShip.getHeight(),BufferedImage.TYPE_INT_RGB); @@ -44,7 +49,7 @@ public class FormShip extends JDialog{ } validate(); } - public FormShip(DrawingObjectShip ship) + public FormShip(IDrawingObject ship) { super(new Frame("Корабль")); CreateWindow(); @@ -82,7 +87,7 @@ public class FormShip extends JDialog{ public void actionPerformed(ActionEvent e){ Random random = new Random(); Color colorFirst = JColorChooser.showDialog(null, "Цвет", null); - _ship=new DrawingShip(random.nextInt(100, 300), random.nextInt(1000, 2000), colorFirst); + _ship=new DrawingShip(random.nextInt(100, 300), random.nextInt(1000, 2000), colorFirst,SetEnum()); _ship.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100), pictureBoxShip.getWidth(), pictureBoxShip.getHeight()); JLabelSpeed.setText("Cкорость: " + _ship.GetShip().GetSpeed() + " "); JLabelWeight.setText("Вес: " + _ship.GetShip().GetWeight() + " "); @@ -141,7 +146,7 @@ public class FormShip extends JDialog{ Random random = new Random(); Color colorFirst = JColorChooser.showDialog(null, "Цвет", null); Color colorSecond = JColorChooser.showDialog(null, "Цвет", null); - _ship=new DrawingContainerShip(random.nextInt(100, 300), random.nextInt(1000, 2000), colorFirst,colorSecond,random.nextBoolean(),random.nextBoolean()); + _ship=new DrawingContainerShip(random.nextInt(100, 300), random.nextInt(1000, 2000), colorFirst,SetEnum(),colorSecond,random.nextBoolean(),random.nextBoolean()); _ship.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100), pictureBoxShip.getWidth(), pictureBoxShip.getHeight()); JLabelSpeed.setText("Cкорость: " + _ship.GetShip().GetSpeed() + " "); JLabelWeight.setText("Вес: " + _ship.GetShip().GetWeight() + " "); diff --git a/FormShipConfig.form b/FormShipConfig.form new file mode 100644 index 0000000..0c2fbf8 --- /dev/null +++ b/FormShipConfig.form @@ -0,0 +1,338 @@ + +
diff --git a/FormShipConfig.java b/FormShipConfig.java new file mode 100644 index 0000000..4b532d7 --- /dev/null +++ b/FormShipConfig.java @@ -0,0 +1,246 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; +import java.awt.image.BufferedImage; + +import java.util.function.Consumer; + +public class FormShipConfig extends JFrame { + public JPanel mainPanel; + DrawingShip _ship; + Consumer