4 Commits

Author SHA1 Message Date
DozorovaA.A
d526660dc2 fix polimorph class 2022-11-16 09:42:24 +04:00
55025611d1 clear 2022-11-05 12:41:19 +04:00
c968474e79 dopTask 2022-11-05 12:35:05 +04:00
040fec6b58 base part 2022-11-05 11:17:16 +04:00
13 changed files with 1533 additions and 113 deletions

Binary file not shown.

View File

@@ -71,7 +71,7 @@ jlink.additionalmodules=
jlink.additionalparam=
jlink.launcher=true
jlink.launcher.name=ArmoredVehicle
main.class=MapForm
main.class=FormMapWithSetMachine
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false

View File

@@ -39,7 +39,7 @@ public class DrawingArmoredVehicle{
/// <summary>
/// Инициализация свойств
/// </summary>
private IDrawingRoller roller;
protected IDrawingRoller roller;
Random rnd = new Random();
public int Count;
@@ -72,7 +72,14 @@ public class DrawingArmoredVehicle{
{
this(speed, weight, bodyColor);
_ArmoredVehicleHeight = ArmoredVehicleHeight + 50;
_ArmoredVehicleWidth = ArmoredVehicleWidth + 50;
_ArmoredVehicleWidth = ArmoredVehicleWidth + 150;
}
public DrawingArmoredVehicle(ArmoredVehicleEntity machine, IDrawingRoller rollers)
{
ArmoredVehicle = machine;
roller = rollers;
}
/// <summary>
/// Установка позиции

View File

@@ -9,6 +9,13 @@ public class DrawingTank extends DrawingArmoredVehicle{
ArmoredVehicle = new TankEntity(speed, weight, bodyColor, dopColor, machineGun, tower);
}
public DrawingTank(ArmoredVehicleEntity tank, IDrawingRoller roll)
{
super(tank, roll);
ArmoredVehicle = (TankEntity)tank;
roller = roll;
}
@Override
public void DrawTransport(Graphics2D g)
{

View File

@@ -0,0 +1,271 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.9" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="3"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="PicturePanel" pref="336" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="InstrumentPanel" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="PicturePanel" max="32767" attributes="0"/>
<Component id="InstrumentPanel" alignment="0" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JPanel" name="PicturePanel">
<LayoutCode>
<CodeStatement>
<CodeExpression id="1_PicturePanel">
<CodeVariable name="PicturePanel" type="8194" declaredType="javax.swing.JPanel"/>
<ExpressionOrigin>
<ExpressionProvider type="ComponentRef">
<ComponentRef name="PicturePanel"/>
</ExpressionProvider>
</ExpressionOrigin>
</CodeExpression>
<StatementProvider type="CodeMethod">
<CodeMethod name="setLayout" class="java.awt.Container" parameterTypes="java.awt.LayoutManager"/>
</StatementProvider>
<Parameters>
<CodeExpression id="2">
<ExpressionOrigin>
<ExpressionProvider type="CodeConstructor">
<CodeConstructor class="javax.swing.OverlayLayout" parameterTypes="java.awt.Container"/>
</ExpressionProvider>
<Parameters>
<CodeExpression id="1_PicturePanel"/>
</Parameters>
</ExpressionOrigin>
</CodeExpression>
</Parameters>
</CodeStatement>
</LayoutCode>
</Container>
<Container class="javax.swing.JPanel" name="InstrumentPanel">
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="22" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="MapComboBox" pref="165" max="32767" attributes="0"/>
<Component id="AddMachineButton" max="32767" attributes="0"/>
<Component id="TextBoxPosition" alignment="0" max="32767" attributes="0"/>
<Component id="DeleteButton" alignment="0" max="32767" attributes="0"/>
<Component id="StoreButton" alignment="0" max="32767" attributes="0"/>
<Component id="MapButton" alignment="0" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="25" pref="25" max="-2" attributes="0"/>
<Component id="UpButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="27" max="-2" attributes="0"/>
</Group>
<Group type="103" alignment="0" groupAlignment="0" attributes="0">
<Component id="RightButton" alignment="1" min="-2" max="-2" attributes="0"/>
<Group type="102" alignment="1" attributes="0">
<Component id="LeftButton" min="-2" pref="22" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="1" max="-2" attributes="0"/>
<Component id="DownButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="29" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
<EmptySpace min="-2" pref="49" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="MapComboBox" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="AddMachineButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="TextBoxPosition" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="DeleteButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="StoreButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="MapButton" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="28" max="32767" attributes="0"/>
<Component id="UpButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="1" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="LeftButton" alignment="1" max="32767" attributes="0"/>
<Component id="RightButton" alignment="1" min="-2" pref="30" max="-2" attributes="0"/>
</Group>
<EmptySpace min="21" pref="21" max="-2" attributes="0"/>
</Group>
<Component id="DownButton" alignment="1" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="jLabel1">
<Properties>
<Property name="text" type="java.lang.String" value="&#x418;&#x43d;&#x441;&#x442;&#x440;&#x443;&#x43c;&#x435;&#x43d;&#x442;&#x44b;"/>
<Property name="name" type="java.lang.String" value="InstrumentLabel" noResource="true"/>
</Properties>
</Component>
<Component class="javax.swing.JComboBox" name="MapComboBox">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="3">
<StringItem index="0" value="&#x41f;&#x440;&#x43e;&#x441;&#x442;&#x430;&#x44f; &#x43a;&#x430;&#x440;&#x442;&#x430;"/>
<StringItem index="1" value="&#x412;&#x435;&#x440;&#x442;&#x438;&#x43a;&#x430;&#x43b;&#x44c;&#x43d;&#x430;&#x44f; &#x43a;&#x430;&#x440;&#x442;&#x430;"/>
<StringItem index="2" value="&#x413;&#x43e;&#x440;&#x438;&#x437;&#x43e;&#x43d;&#x442;&#x430;&#x43b;&#x44c;&#x43d;&#x430;&#x44f; &#x43a;&#x430;&#x440;&#x442;&#x430;"/>
</StringArray>
</Property>
<Property name="name" type="java.lang.String" value="MapComboBox" noResource="true"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="MapComboBoxActionPerformed"/>
</Events>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
</AuxValues>
</Component>
<Component class="java.awt.Button" name="AddMachineButton">
<Properties>
<Property name="label" type="java.lang.String" value="&#x414;&#x43e;&#x431;&#x430;&#x432;&#x438;&#x442;&#x44c; &#x43c;&#x430;&#x448;&#x438;&#x43d;&#x443;"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="AddMachineButtonMouseClicked"/>
</Events>
</Component>
<Component class="java.awt.TextField" name="TextBoxPosition">
<Properties>
<Property name="name" type="java.lang.String" value="TextBoxPosition" noResource="true"/>
</Properties>
</Component>
<Component class="java.awt.Button" name="DeleteButton">
<Properties>
<Property name="label" type="java.lang.String" value="&#x423;&#x434;&#x430;&#x43b;&#x438;&#x442;&#x44c; &#x43c;&#x430;&#x448;&#x438;&#x43d;&#x443;"/>
<Property name="name" type="java.lang.String" value="DeleteMachineButton" noResource="true"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="DeleteButtonMouseClicked"/>
</Events>
</Component>
<Component class="java.awt.Button" name="StoreButton">
<Properties>
<Property name="label" type="java.lang.String" value="&#x41f;&#x43e;&#x441;&#x43c;&#x43e;&#x442;&#x440;&#x435;&#x442;&#x44c; &#x445;&#x440;&#x430;&#x43d;&#x438;&#x43b;&#x438;&#x449;&#x435;"/>
<Property name="name" type="java.lang.String" value="StoreButton" noResource="true"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="StoreButtonMouseClicked"/>
</Events>
</Component>
<Component class="java.awt.Button" name="MapButton">
<Properties>
<Property name="label" type="java.lang.String" value="&#x41f;&#x43e;&#x441;&#x43c;&#x43e;&#x442;&#x440;&#x435;&#x442;&#x44c; &#x43a;&#x430;&#x440;&#x442;&#x443;"/>
<Property name="name" type="java.lang.String" value="MapButton" noResource="true"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="MapButtonMouseClicked"/>
</Events>
</Component>
<Component class="java.awt.Button" name="RightButton">
<Properties>
<Property name="actionCommand" type="java.lang.String" value="Right"/>
<Property name="label" type="java.lang.String" value="&#x2192;"/>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[30, 30]"/>
</Property>
<Property name="name" type="java.lang.String" value="RightButton" noResource="true"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="RightButtonMouseClicked"/>
</Events>
</Component>
<Component class="java.awt.Button" name="DownButton">
<Properties>
<Property name="actionCommand" type="java.lang.String" value="Left"/>
<Property name="label" type="java.lang.String" value="&#x2193;"/>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[30, 30]"/>
</Property>
<Property name="name" type="java.lang.String" value="LeftButton" noResource="true"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="DownButtonMouseClicked"/>
</Events>
</Component>
<Component class="java.awt.Button" name="LeftButton">
<Properties>
<Property name="actionCommand" type="java.lang.String" value="Left"/>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[30, 30]"/>
</Property>
<Property name="name" type="java.lang.String" value="LeftButton" noResource="true"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="LeftButtonMouseClicked"/>
</Events>
</Component>
<Component class="java.awt.Button" name="UpButton">
<Properties>
<Property name="actionCommand" type="java.lang.String" value="Up"/>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Default Cursor"/>
</Property>
<Property name="label" type="java.lang.String" value="&#x2191;"/>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[30, 30]"/>
</Property>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="UpButtonMouseClicked"/>
</Events>
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new java.awt.Button()"/>
</AuxValues>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Form>

View File

@@ -0,0 +1,383 @@
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class FormMapWithSetMachine extends javax.swing.JFrame {
private Image img;
private MapWithSetArmoredCarsGeneric<DrawingObject, AbstractMap> _mapCollectionGeneric;
public FormMapWithSetMachine() {
initComponents();
LeftButton.setLabel("<");
RightButton.setLabel(">");
UpButton.setLabel("/\\");
DownButton.setLabel("\\/");
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
PicturePanel = new javax.swing.JPanel();
InstrumentPanel = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
MapComboBox = new javax.swing.JComboBox<>();
AddMachineButton = new java.awt.Button();
TextBoxPosition = new java.awt.TextField();
DeleteButton = new java.awt.Button();
StoreButton = new java.awt.Button();
MapButton = new java.awt.Button();
RightButton = new java.awt.Button();
DownButton = new java.awt.Button();
LeftButton = new java.awt.Button();
UpButton = new java.awt.Button();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
PicturePanel.setLayout(new javax.swing.OverlayLayout(PicturePanel));
jLabel1.setText("Инструменты");
jLabel1.setName("InstrumentLabel"); // NOI18N
MapComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Простая карта", "Вертикальная карта", "Горизонтальная карта" }));
MapComboBox.setName("MapComboBox"); // NOI18N
MapComboBox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
MapComboBoxActionPerformed(evt);
}
});
AddMachineButton.setLabel("Добавить машину");
AddMachineButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
AddMachineButtonMouseClicked(evt);
}
});
TextBoxPosition.setName("TextBoxPosition"); // NOI18N
DeleteButton.setLabel("Удалить машину");
DeleteButton.setName("DeleteMachineButton"); // NOI18N
DeleteButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
DeleteButtonMouseClicked(evt);
}
});
StoreButton.setLabel("Посмотреть хранилище");
StoreButton.setName("StoreButton"); // NOI18N
StoreButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
StoreButtonMouseClicked(evt);
}
});
MapButton.setLabel("Посмотреть карту");
MapButton.setName("MapButton"); // NOI18N
MapButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
MapButtonMouseClicked(evt);
}
});
RightButton.setActionCommand("Right");
RightButton.setLabel("");
RightButton.setMinimumSize(new java.awt.Dimension(30, 30));
RightButton.setName("RightButton"); // NOI18N
RightButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
RightButtonMouseClicked(evt);
}
});
DownButton.setActionCommand("Left");
DownButton.setLabel("");
DownButton.setMinimumSize(new java.awt.Dimension(30, 30));
DownButton.setName("LeftButton"); // NOI18N
DownButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
DownButtonMouseClicked(evt);
}
});
LeftButton.setActionCommand("Left");
LeftButton.setMinimumSize(new java.awt.Dimension(30, 30));
LeftButton.setName("LeftButton"); // NOI18N
LeftButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
LeftButtonMouseClicked(evt);
}
});
UpButton.setActionCommand("Up");
UpButton.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
UpButton.setLabel("");
UpButton.setMinimumSize(new java.awt.Dimension(30, 30));
UpButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
UpButtonMouseClicked(evt);
}
});
javax.swing.GroupLayout InstrumentPanelLayout = new javax.swing.GroupLayout(InstrumentPanel);
InstrumentPanel.setLayout(InstrumentPanelLayout);
InstrumentPanelLayout.setHorizontalGroup(
InstrumentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(InstrumentPanelLayout.createSequentialGroup()
.addComponent(jLabel1)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(InstrumentPanelLayout.createSequentialGroup()
.addGap(22, 22, 22)
.addGroup(InstrumentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(MapComboBox, 0, 165, Short.MAX_VALUE)
.addComponent(AddMachineButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(TextBoxPosition, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(DeleteButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(StoreButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(MapButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, InstrumentPanelLayout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(InstrumentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(InstrumentPanelLayout.createSequentialGroup()
.addGap(25, 25, 25)
.addComponent(UpButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(27, 27, 27))
.addGroup(InstrumentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(RightButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, InstrumentPanelLayout.createSequentialGroup()
.addComponent(LeftButton, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(1, 1, 1)
.addComponent(DownButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(29, 29, 29))))
.addGap(49, 49, 49))
);
InstrumentPanelLayout.setVerticalGroup(
InstrumentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(InstrumentPanelLayout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(MapComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(AddMachineButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(TextBoxPosition, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(DeleteButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(StoreButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(MapButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
.addComponent(UpButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(1, 1, 1)
.addGroup(InstrumentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, InstrumentPanelLayout.createSequentialGroup()
.addGroup(InstrumentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(LeftButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(RightButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(21, 21, 21))
.addComponent(DownButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(PicturePanel, javax.swing.GroupLayout.DEFAULT_SIZE, 336, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(InstrumentPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(PicturePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(InstrumentPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void RightButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_RightButtonMouseClicked
Move("RightButton");
}//GEN-LAST:event_RightButtonMouseClicked
private void DownButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_DownButtonMouseClicked
Move("DownButton");
}//GEN-LAST:event_DownButtonMouseClicked
private void LeftButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_LeftButtonMouseClicked
Move("LeftButton");
}//GEN-LAST:event_LeftButtonMouseClicked
private void UpButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_UpButtonMouseClicked
Move("UpButton");
}//GEN-LAST:event_UpButtonMouseClicked
private void MapComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MapComboBoxActionPerformed
AbstractMap map = null;
String name = (String) MapComboBox.getSelectedItem();
switch (name)
{
case "Простая карта":
map = new SimpleMap();
break;
case "Горизонтальная карта":
map = new HorizontalMap();
break;
case "Вертикальная карта":
map = new VerticalMap();
break;
}
if (map != null)
{
_mapCollectionGeneric = new MapWithSetArmoredCarsGeneric<DrawingObject, AbstractMap>(
PicturePanel.getWidth(), PicturePanel.getHeight(), map);
}
else
{
_mapCollectionGeneric = null;
}
}//GEN-LAST:event_MapComboBoxActionPerformed
private void AddMachineButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_AddMachineButtonMouseClicked
if (_mapCollectionGeneric == null)
{
JOptionPane.showMessageDialog(null, "Не выбрана карта");
return;
}
PolimorphForm form = new PolimorphForm();
form.setVisible(true);
form.addWindowListener(new WindowAdapter() {
@Override
public void windowDeactivated(WindowEvent e) {
if (form.getSelectedCar() == null)
return;
DrawingObject machine = new DrawingObject(form.getSelectedCar());
if (_mapCollectionGeneric.add(machine) > -1)
{
JOptionPane.showMessageDialog(null, "Объект добавлен");
img = _mapCollectionGeneric.ShowSet();
Draw();
}
else
{
JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
}
}
});
}//GEN-LAST:event_AddMachineButtonMouseClicked
private void DeleteButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_DeleteButtonMouseClicked
if (TextBoxPosition.getText().equals(""))
{
return;
}
int res = JOptionPane.showConfirmDialog (null,"Удалить объект?",
"Удаление", JOptionPane.YES_NO_OPTION);
if (res == JOptionPane.YES_OPTION) {
int pos = Integer.parseInt(TextBoxPosition.getText());
if (_mapCollectionGeneric.remove(pos) != null)
{
JOptionPane.showMessageDialog(null, "Объект удален");
img = _mapCollectionGeneric.ShowSet();
Draw();
}
else
{
JOptionPane.showMessageDialog(null, "Не удалось удалить объект");
}
}
}//GEN-LAST:event_DeleteButtonMouseClicked
private void StoreButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_StoreButtonMouseClicked
if (_mapCollectionGeneric == null)
{
return;
}
img = _mapCollectionGeneric.ShowSet();
Draw();
}//GEN-LAST:event_StoreButtonMouseClicked
private void MapButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_MapButtonMouseClicked
if (_mapCollectionGeneric == null)
{
return;
}
img = _mapCollectionGeneric.ShowOnMap();
Draw();
}//GEN-LAST:event_MapButtonMouseClicked
public void Move(String name)
{
switch (name)
{
case "UpButton" -> img = _mapCollectionGeneric.MoveObject(Direction.Up);
case "DownButton" -> img = _mapCollectionGeneric.MoveObject(Direction.Down);
case "LeftButton" -> img = _mapCollectionGeneric.MoveObject(Direction.Left);
case "RightButton" -> img = _mapCollectionGeneric.MoveObject(Direction.Right);
}
Draw();
}
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(FormMapWithSetMachine.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(FormMapWithSetMachine.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(FormMapWithSetMachine.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(FormMapWithSetMachine.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new FormMapWithSetMachine().setVisible(true);
}
});
}
void Draw()
{
Graphics g = PicturePanel.getGraphics();
g.drawImage(img, 0, 0, this);
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private java.awt.Button AddMachineButton;
private java.awt.Button DeleteButton;
private java.awt.Button DownButton;
private javax.swing.JPanel InstrumentPanel;
private java.awt.Button LeftButton;
private java.awt.Button MapButton;
private javax.swing.JComboBox<String> MapComboBox;
private javax.swing.JPanel PicturePanel;
private java.awt.Button RightButton;
private java.awt.Button StoreButton;
private java.awt.TextField TextBoxPosition;
private java.awt.Button UpButton;
private javax.swing.JLabel jLabel1;
// End of variables declaration//GEN-END:variables
}

View File

@@ -59,8 +59,7 @@
<EmptySpace min="19" pref="19" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="MapComboBox" min="-2" pref="152" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
<Component id="UpButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="76" max="-2" attributes="0"/>
</Group>
@@ -72,6 +71,8 @@
<Component id="CreateButton" min="-2" pref="83" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="CreateTankButton" min="-2" pref="132" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="SetButton" min="-2" pref="85" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
@@ -93,17 +94,9 @@
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace pref="210" max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace pref="217" max="32767" attributes="0"/>
<Component id="UpButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="1" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="1" attributes="0">
<Component id="MapComboBox" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Group type="103" groupAlignment="0" max="-2" attributes="0">
@@ -111,6 +104,7 @@
<Component id="LeftButton" alignment="1" max="32767" attributes="0"/>
<Component id="RightButton" alignment="1" max="32767" attributes="0"/>
<Component id="CreateTankButton" alignment="0" max="32767" attributes="0"/>
<Component id="SetButton" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="PropertyText" min="-2" max="-2" attributes="0"/>
@@ -209,22 +203,13 @@
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="CreateTankButtonMouseClicked"/>
</Events>
</Component>
<Component class="javax.swing.JComboBox" name="MapComboBox">
<Component class="java.awt.Button" name="SetButton">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="3">
<StringItem index="0" value="&#x41f;&#x440;&#x43e;&#x441;&#x442;&#x430;&#x44f; &#x43a;&#x430;&#x440;&#x442;&#x430;"/>
<StringItem index="1" value="&#x412;&#x435;&#x440;&#x442;&#x438;&#x43a;&#x430;&#x43b;&#x44c;&#x43d;&#x430;&#x44f; &#x43a;&#x430;&#x440;&#x442;&#x430;"/>
<StringItem index="2" value="&#x413;&#x43e;&#x440;&#x438;&#x437;&#x43e;&#x43d;&#x442;&#x430;&#x43b;&#x44c;&#x43d;&#x430;&#x44f; &#x43a;&#x430;&#x440;&#x442;&#x430;"/>
</StringArray>
</Property>
<Property name="label" type="java.lang.String" value="&#x412;&#x44b;&#x431;&#x440;&#x430;&#x442;&#x44c;"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="MapComboBoxActionPerformed"/>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="SetButtonMouseClicked"/>
</Events>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
</AuxValues>
</Component>
</SubComponents>
</Container>

View File

@@ -3,8 +3,10 @@ import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.util.Random;
import javax.swing.ImageIcon;
import javax.swing.JColorChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
@@ -14,8 +16,7 @@ public class MapForm extends JFrame{
private DrawingArmoredVehicle _ArmoredVehicle;
private DrawingArmoredVehicle SelectedMachine;
private AbstractMap abstractMap;
private Image img;
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
@@ -30,7 +31,7 @@ public class MapForm extends JFrame{
DownButton = new java.awt.Button();
RightButton = new java.awt.Button();
CreateTankButton = new java.awt.Button();
MapComboBox = new javax.swing.JComboBox<>();
SetButton = new java.awt.Button();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Карта");
@@ -100,10 +101,10 @@ public class MapForm extends JFrame{
}
});
MapComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Простая карта", "Вертикальная карта", "Горизонтальная карта" }));
MapComboBox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
MapComboBoxActionPerformed(evt);
SetButton.setLabel("Выбрать");
SetButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
SetButtonMouseClicked(evt);
}
});
@@ -115,8 +116,7 @@ public class MapForm extends JFrame{
.addGap(19, 19, 19)
.addGroup(DrawPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(DrawPanelLayout.createSequentialGroup()
.addComponent(MapComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(UpButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(76, 76, 76))
.addGroup(DrawPanelLayout.createSequentialGroup()
@@ -126,6 +126,8 @@ public class MapForm extends JFrame{
.addComponent(CreateButton, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(CreateTankButton, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(SetButton, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(DrawPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, DrawPanelLayout.createSequentialGroup()
@@ -140,21 +142,17 @@ public class MapForm extends JFrame{
DrawPanelLayout.setVerticalGroup(
DrawPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(DrawPanelLayout.createSequentialGroup()
.addContainerGap(210, Short.MAX_VALUE)
.addGroup(DrawPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, DrawPanelLayout.createSequentialGroup()
.addContainerGap(217, Short.MAX_VALUE)
.addComponent(UpButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(1, 1, 1))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, DrawPanelLayout.createSequentialGroup()
.addComponent(MapComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
.addGap(1, 1, 1)
.addGroup(DrawPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, DrawPanelLayout.createSequentialGroup()
.addGroup(DrawPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(CreateButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 30, Short.MAX_VALUE)
.addComponent(LeftButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(RightButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(CreateTankButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(CreateTankButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(SetButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(PropertyText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
@@ -187,24 +185,21 @@ public class MapForm extends JFrame{
RightButton.setLabel(">");
UpButton.setLabel("/\\");
DownButton.setLabel("\\/");
abstractMap = new SimpleMap();
}
private void CreateButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_CreateButtonMouseClicked
Random rnd = new Random();
Color newColor = JColorChooser.showDialog(null, "Choose a color", Color.RED);
_ArmoredVehicle = new DrawingArmoredVehicle(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)));
SetData(_ArmoredVehicle);
newColor);
SetData();
Draw();
}//GEN-LAST:event_CreateButtonMouseClicked
public void SetData(DrawingArmoredVehicle machine)
public void SetData()
{
if (abstractMap != null)
img = abstractMap.CreateMap(DrawPanel.getWidth(), DrawPanel.getHeight(),
new DrawingObject(machine));
Random rnd = new Random();
_ArmoredVehicle.SetPosition((int)_ArmoredVehicle._startPosX, (int)_ArmoredVehicle._startPosY,
_ArmoredVehicle.SetPosition(rnd.nextInt(0, 100), rnd.nextInt(25, 200),
DrawPanel.getWidth(), DrawPanel.getHeight());
PropertyText.setText("Скорость: " + _ArmoredVehicle.ArmoredVehicle.Speed +
" Вес: "+_ArmoredVehicle.ArmoredVehicle.Weight +
@@ -218,10 +213,10 @@ public class MapForm extends JFrame{
{
switch (name)
{
case "UpButton" -> img = abstractMap.MoveObject(Direction.Up);
case "DownButton" -> img = abstractMap.MoveObject(Direction.Down);
case "LeftButton" -> img = abstractMap.MoveObject(Direction.Left);
case "RightButton" -> img = abstractMap.MoveObject(Direction.Right);
case "UpButton" -> _ArmoredVehicle.MoveTransport(Direction.Up);
case "DownButton" -> _ArmoredVehicle.MoveTransport(Direction.Down);
case "LeftButton" -> _ArmoredVehicle.MoveTransport(Direction.Left);
case "RightButton" -> _ArmoredVehicle.MoveTransport(Direction.Right);
}
Draw();
@@ -245,43 +240,34 @@ public class MapForm extends JFrame{
private void DrawPanelComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_DrawPanelComponentResized
if (_ArmoredVehicle != null) {
_ArmoredVehicle.ChangeBorders(DrawPanel.getWidth(), DrawPanel.getHeight());
DrawPanel.repaint();
Draw();
}
}//GEN-LAST:event_DrawPanelComponentResized
private void CreateTankButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_CreateTankButtonMouseClicked
Random rnd = new Random();
Color newColor = JColorChooser.showDialog(null, "Choose a color", Color.RED);
Color newColorDop = JColorChooser.showDialog(null, "Choose a color", Color.RED);
_ArmoredVehicle = new DrawingTank(rnd.nextInt(100, 300),
rnd.nextInt(1000, 2000),
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)),
new Color(rnd.nextInt(50, 256), rnd.nextInt(0, 256), rnd.nextInt(20, 256)),
newColor,
newColorDop,
1==rnd.nextInt(0, 2), 1==rnd.nextInt(0, 2));
SetData(_ArmoredVehicle);
SetData();
Draw();
}//GEN-LAST:event_CreateTankButtonMouseClicked
private void MapComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MapComboBoxActionPerformed
String name = (String) MapComboBox.getSelectedItem();
switch (name)
{
case "Простая карта":
abstractMap = new SimpleMap();
break;
case "Горизонтальная карта":
abstractMap = new HorizontalMap();
break;
case "Вертикальная карта":
abstractMap = new VerticalMap();
break;
private void SetButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_SetButtonMouseClicked
if (_ArmoredVehicle != null) {
SelectedMachine = _ArmoredVehicle;
dispose();
}
}//GEN-LAST:event_MapComboBoxActionPerformed
}//GEN-LAST:event_SetButtonMouseClicked
private void Draw()
{
Graphics g = DrawPanel.getGraphics();
g.drawImage(img, 0, 0, this);
g.drawImage(Pic(), 0, 0, this);
}
private void createUIComponents() {
DrawPanel = new JPanel() {
@@ -291,36 +277,13 @@ public class MapForm extends JFrame{
}
};
}
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(MapForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(MapForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(MapForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(MapForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MapForm().setVisible(true);
}
});
Image Pic()
{
BufferedImage img = new BufferedImage(DrawPanel.getWidth(), DrawPanel.getHeight(), BufferedImage.TYPE_INT_BGR);
Graphics2D gr = img.createGraphics();
gr.setBackground(Color.yellow);
_ArmoredVehicle.DrawTransport(gr);
return img;
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private java.awt.Button CreateButton;
@@ -328,9 +291,9 @@ public class MapForm extends JFrame{
private java.awt.Button DownButton;
private javax.swing.JPanel DrawPanel;
private java.awt.Button LeftButton;
private javax.swing.JComboBox<String> MapComboBox;
private java.awt.TextField PropertyText;
private java.awt.Button RightButton;
private java.awt.Button SetButton;
private java.awt.Button UpButton;
// End of variables declaration//GEN-END:variables

View File

@@ -0,0 +1,123 @@
import java.awt.*;
import java.awt.image.BufferedImage;
public class MapWithSetArmoredCarsGeneric<T extends IDrawingObject, U extends AbstractMap> {
private int _pictureWidth;
private int _pictureHeight;
private int _placeSizeWidth = 210;
private int _placeSizeHeight = 110;
private SetArmoredCarsGeneric<T> _setCars;
private U _map;
public MapWithSetArmoredCarsGeneric(int picWidth, int picHeight, U map)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_setCars = new SetArmoredCarsGeneric<T>(width * height);
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_map = map;
}
public int add(T car)
{
return _setCars.Insert(car);
}
public T remove(int position)
{
return _setCars.Remove(position);
}
public Image ShowSet()
{
Image bmp = new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_BGR);
Graphics gr = bmp.getGraphics();
DrawBackground(gr);
DrawArmoredCars(gr);
return bmp;
}
public Image ShowOnMap()
{
Shaking();
for (int i = 0; i < _setCars.getCount(); i++)
{
var car = _setCars.Get(i);
if (car != null)
{
return _map.CreateMap(_pictureWidth, _pictureHeight, car);
}
}
return new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_BGR);
}
public Image MoveObject(Direction direction)
{
if (_map != null)
{
return _map.MoveObject(direction);
}
return new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_BGR);
}
private void Shaking()
{
int j = _setCars.getCount() - 1;
for (int i = 0; i < _setCars.getCount(); i++)
{
if (_setCars.Get(i) == null)
{
for (; j > i; j--)
{
var car = _setCars.Get(j);
if (car != null)
{
_setCars.Insert(car, i);
_setCars.Remove(j);
break;
}
}
if (j <= i)
{
return;
}
}
}
}
private void DrawBackground(Graphics g)
{
g.setColor(Color.GREEN);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
{//линия рамзетки места
int dop = 0;
if(i>0 && j>0)
{
dop = 30;
}
g.drawRect(i * _placeSizeWidth + dop, j * _placeSizeHeight + dop,_placeSizeWidth,_placeSizeHeight);
}
}
}
private void DrawArmoredCars(Graphics g)
{
int width = _pictureWidth / _placeSizeWidth;
for (int i = 0; i < _setCars.getCount(); i++)
{
if (_setCars.Get(i) != null) {
_setCars.Get(i).SetObject(i % width * _placeSizeWidth + 5, i / width * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
_setCars.Get(i).DrawingObject((Graphics2D) g);
}
}
}
}

View File

@@ -0,0 +1,48 @@
import java.util.ArrayList;
import java.util.Random;
public class PolimorphClass <M extends ArmoredVehicleEntity, R extends IDrawingRoller> {
ArrayList<M> machines;
ArrayList<R> rollers;
int _machineCount = 0;
int _rollersCount = 0;
public PolimorphClass(int machineCount, int rollersCount) {
_machineCount = machineCount;
_rollersCount = rollersCount;
machines = new ArrayList<M>(_machineCount);
rollers = new ArrayList<R>(_rollersCount);
}
public int AddEntity(M machine)
{
if(_machineCount < machines.size()){
machines.add(machine);
return _machineCount++;
}
return -1;
}
public int AddRollers(R rolls)
{
if(_rollersCount < rollers.size()){
rollers.add(rolls);
return _rollersCount++;
}
return -1;
}
public DrawingArmoredVehicle CreateMachine() {
int iMachine = new Random().nextInt(0, _machineCount);
int iRoller = new Random().nextInt(0, _rollersCount);
M selectedMachine = machines.get(iMachine);
R selectedRoller = rollers.get(iRoller);
if (selectedMachine instanceof TankEntity) {
return new DrawingTank(selectedMachine, selectedRoller);
}
return new DrawingArmoredVehicle(selectedMachine, selectedRoller);
}
}

View File

@@ -0,0 +1,217 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.9" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="3"/>
<Property name="title" type="java.lang.String" value="&#x41a;&#x430;&#x440;&#x442;&#x430;"/>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[444, 303]"/>
</Property>
<Property name="name" type="java.lang.String" value="MainFrame" noResource="true"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="482" max="32767" attributes="0"/>
<Group type="103" rootIndex="1" groupAlignment="0" attributes="0">
<Component id="DrawPanel" alignment="1" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="312" max="32767" attributes="0"/>
<Group type="103" rootIndex="1" groupAlignment="0" attributes="0">
<Component id="DrawPanel" alignment="1" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JPanel" name="DrawPanel">
<Events>
<EventHandler event="componentResized" listener="java.awt.event.ComponentListener" parameters="java.awt.event.ComponentEvent" handler="DrawPanelComponentResized"/>
</Events>
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new javax.swing.JPanel(){&#xa; Graphics2D g2;}"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="19" pref="19" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
<Component id="UpButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="76" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="PropertyText" min="-2" pref="330" max="-2" attributes="0"/>
<EmptySpace min="74" pref="133" max="32767" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<Component id="CreateButton" min="-2" pref="83" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="CreateTankButton" min="-2" pref="132" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="SetButton" min="-2" pref="85" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Component id="RightButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="49" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="1" attributes="0">
<Component id="LeftButton" min="-2" pref="22" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="1" max="-2" attributes="0"/>
<Component id="DownButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="78" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
</Group>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace pref="217" max="32767" attributes="0"/>
<Component id="UpButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="1" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="CreateButton" alignment="1" pref="30" max="32767" attributes="0"/>
<Component id="LeftButton" alignment="1" max="32767" attributes="0"/>
<Component id="RightButton" alignment="1" max="32767" attributes="0"/>
<Component id="CreateTankButton" alignment="0" max="32767" attributes="0"/>
<Component id="SetButton" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="PropertyText" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="1" attributes="0">
<Component id="DownButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="19" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="java.awt.TextField" name="PropertyText">
</Component>
<Component class="java.awt.Button" name="CreateButton">
<Properties>
<Property name="actionCommand" type="java.lang.String" value="Create"/>
<Property name="label" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="&quot;&#x421;&#x43e;&#x437;&#x434;&#x430;&#x442;&#x44c;&quot;" type="code"/>
</Property>
<Property name="name" type="java.lang.String" value="CreateButton" noResource="true"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="CreateButtonMouseClicked"/>
</Events>
</Component>
<Component class="java.awt.Button" name="UpButton">
<Properties>
<Property name="actionCommand" type="java.lang.String" value="Up"/>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Default Cursor"/>
</Property>
<Property name="label" type="java.lang.String" value="&#x2191;"/>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[30, 30]"/>
</Property>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="UpButtonMouseClicked"/>
</Events>
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new java.awt.Button()"/>
<AuxValue name="JavaCodeGenerator_CreateCodePre" type="java.lang.String" value="ImageIcon arrowUp = new ImageIcon(&quot;C:\\Users\\Alena\\Desktop\\New Folder\\JavaApplication4\\src\\Resources\\arrowUp.jpg&quot;);"/>
</AuxValues>
</Component>
<Component class="java.awt.Button" name="LeftButton">
<Properties>
<Property name="actionCommand" type="java.lang.String" value="Left"/>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[30, 30]"/>
</Property>
<Property name="name" type="java.lang.String" value="LeftButton" noResource="true"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="LeftButtonMouseClicked"/>
</Events>
</Component>
<Component class="java.awt.Button" name="DownButton">
<Properties>
<Property name="actionCommand" type="java.lang.String" value="Left"/>
<Property name="label" type="java.lang.String" value="&#x2193;"/>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[30, 30]"/>
</Property>
<Property name="name" type="java.lang.String" value="LeftButton" noResource="true"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="DownButtonMouseClicked"/>
</Events>
</Component>
<Component class="java.awt.Button" name="RightButton">
<Properties>
<Property name="actionCommand" type="java.lang.String" value="Right"/>
<Property name="label" type="java.lang.String" value="&#x2192;"/>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[30, 30]"/>
</Property>
<Property name="name" type="java.lang.String" value="RightButton" noResource="true"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="RightButtonMouseClicked"/>
</Events>
</Component>
<Component class="java.awt.Button" name="CreateTankButton">
<Properties>
<Property name="actionCommand" type="java.lang.String" value="Create"/>
<Property name="label" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="&quot;&#x41c;&#x43e;&#x434;&#x438;&#x444;&#x438;&#x43a;&#x430;&#x446;&#x438;&#x44f;&quot;" type="code"/>
</Property>
<Property name="name" type="java.lang.String" value="CreateTankButton" noResource="true"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="CreateTankButtonMouseClicked"/>
</Events>
</Component>
<Component class="java.awt.Button" name="SetButton">
<Properties>
<Property name="label" type="java.lang.String" value="&#x412;&#x44b;&#x431;&#x440;&#x430;&#x442;&#x44c;"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="SetButtonMouseClicked"/>
</Events>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Form>

View File

@@ -0,0 +1,350 @@
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.util.Random;
import javax.swing.ImageIcon;
import javax.swing.JColorChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class PolimorphForm extends JFrame{
private DrawingArmoredVehicle _ArmoredVehicle;
private DrawingArmoredVehicle SelectedMachine;
protected PolimorphClass<ArmoredVehicleEntity, IDrawingRoller> polymorphMachine;
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
DrawPanel = new javax.swing.JPanel(){
Graphics2D g2;};
PropertyText = new java.awt.TextField();
CreateButton = new java.awt.Button();
ImageIcon arrowUp = new ImageIcon("C:\\Users\\Alena\\Desktop\\New Folder\\JavaApplication4\\src\\Resources\\arrowUp.jpg");
UpButton = new java.awt.Button();
LeftButton = new java.awt.Button();
DownButton = new java.awt.Button();
RightButton = new java.awt.Button();
CreateTankButton = new java.awt.Button();
SetButton = new java.awt.Button();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Карта");
setMinimumSize(new java.awt.Dimension(444, 303));
setName("MainFrame"); // NOI18N
DrawPanel.addComponentListener(new java.awt.event.ComponentAdapter() {
public void componentResized(java.awt.event.ComponentEvent evt) {
DrawPanelComponentResized(evt);
}
});
CreateButton.setActionCommand("Create");
CreateButton.setLabel("Создать");
CreateButton.setName("CreateButton"); // NOI18N
CreateButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
CreateButtonMouseClicked(evt);
}
});
UpButton.setActionCommand("Up");
UpButton.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
UpButton.setLabel("");
UpButton.setMinimumSize(new java.awt.Dimension(30, 30));
UpButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
UpButtonMouseClicked(evt);
}
});
LeftButton.setActionCommand("Left");
LeftButton.setMinimumSize(new java.awt.Dimension(30, 30));
LeftButton.setName("LeftButton"); // NOI18N
LeftButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
LeftButtonMouseClicked(evt);
}
});
DownButton.setActionCommand("Left");
DownButton.setLabel("");
DownButton.setMinimumSize(new java.awt.Dimension(30, 30));
DownButton.setName("LeftButton"); // NOI18N
DownButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
DownButtonMouseClicked(evt);
}
});
RightButton.setActionCommand("Right");
RightButton.setLabel("");
RightButton.setMinimumSize(new java.awt.Dimension(30, 30));
RightButton.setName("RightButton"); // NOI18N
RightButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
RightButtonMouseClicked(evt);
}
});
CreateTankButton.setActionCommand("Create");
CreateTankButton.setLabel("Модификация");
CreateTankButton.setName("CreateTankButton"); // NOI18N
CreateTankButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
CreateTankButtonMouseClicked(evt);
}
});
SetButton.setLabel("Выбрать");
SetButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
SetButtonMouseClicked(evt);
}
});
javax.swing.GroupLayout DrawPanelLayout = new javax.swing.GroupLayout(DrawPanel);
DrawPanel.setLayout(DrawPanelLayout);
DrawPanelLayout.setHorizontalGroup(
DrawPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(DrawPanelLayout.createSequentialGroup()
.addGap(19, 19, 19)
.addGroup(DrawPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(DrawPanelLayout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(UpButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(76, 76, 76))
.addGroup(DrawPanelLayout.createSequentialGroup()
.addComponent(PropertyText, javax.swing.GroupLayout.PREFERRED_SIZE, 330, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(74, 133, Short.MAX_VALUE))
.addGroup(DrawPanelLayout.createSequentialGroup()
.addComponent(CreateButton, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(CreateTankButton, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(SetButton, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(DrawPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, DrawPanelLayout.createSequentialGroup()
.addComponent(RightButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(49, 49, 49))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, DrawPanelLayout.createSequentialGroup()
.addComponent(LeftButton, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(1, 1, 1)
.addComponent(DownButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(78, 78, 78))))))
);
DrawPanelLayout.setVerticalGroup(
DrawPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(DrawPanelLayout.createSequentialGroup()
.addContainerGap(217, Short.MAX_VALUE)
.addComponent(UpButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(1, 1, 1)
.addGroup(DrawPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, DrawPanelLayout.createSequentialGroup()
.addGroup(DrawPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(CreateButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 30, Short.MAX_VALUE)
.addComponent(LeftButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(RightButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(CreateTankButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(SetButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(PropertyText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, DrawPanelLayout.createSequentialGroup()
.addComponent(DownButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(19, 19, 19))))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 482, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(DrawPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 312, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(DrawPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
public PolimorphForm() {
initComponents();
LeftButton.setLabel("<");
RightButton.setLabel(">");
UpButton.setLabel("/\\");
DownButton.setLabel("\\/");
polymorphMachine = new PolimorphClass<ArmoredVehicleEntity, IDrawingRoller>(50, 50);
}
private void CreateButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_CreateButtonMouseClicked
Random rnd = new Random();
Color newColor = JColorChooser.showDialog(null, "Choose a color", Color.RED);
IDrawingRoller roll = null;
switch (rnd.nextInt(3)) {
case (0) -> roll = new Roller(newColor);
case (1) -> roll = new DrawingFirstRoller(newColor);
case (2) -> roll = new DrawingSecondRoller(newColor);
}
int c= rnd.nextInt(4, 6);
roll.setCount(c);
ArmoredVehicleEntity machine = new ArmoredVehicleEntity(rnd.nextInt(300), rnd.nextInt(2000),
newColor);
polymorphMachine.AddRollers(roll);
polymorphMachine.AddEntity(machine);
_ArmoredVehicle = polymorphMachine.CreateMachine();
_ArmoredVehicle.Count = c;
SetData();
Draw();
}//GEN-LAST:event_CreateButtonMouseClicked
public void SetData()
{
Random rnd = new Random();
_ArmoredVehicle.SetPosition(rnd.nextInt(0, 100), rnd.nextInt(25, 200),
DrawPanel.getWidth(), DrawPanel.getHeight());
PropertyText.setText("Скорость: " + _ArmoredVehicle.ArmoredVehicle.Speed +
" Вес: "+_ArmoredVehicle.ArmoredVehicle.Weight +
" Цвет: "+_ArmoredVehicle.ArmoredVehicle.BodyColor.getRGB()+
" Катков: "+_ArmoredVehicle.Count);
}
public DrawingArmoredVehicle getSelectedCar() {
return SelectedMachine;
}
public void Move(String name)
{
switch (name)
{
case "UpButton" -> _ArmoredVehicle.MoveTransport(Direction.Up);
case "DownButton" -> _ArmoredVehicle.MoveTransport(Direction.Down);
case "LeftButton" -> _ArmoredVehicle.MoveTransport(Direction.Left);
case "RightButton" -> _ArmoredVehicle.MoveTransport(Direction.Right);
}
Draw();
}
private void UpButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_UpButtonMouseClicked
Move("UpButton");
}//GEN-LAST:event_UpButtonMouseClicked
private void LeftButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_LeftButtonMouseClicked
Move("LeftButton");
}//GEN-LAST:event_LeftButtonMouseClicked
private void RightButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_RightButtonMouseClicked
Move("RightButton");
}//GEN-LAST:event_RightButtonMouseClicked
private void DownButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_DownButtonMouseClicked
Move("DownButton");
}//GEN-LAST:event_DownButtonMouseClicked
private void DrawPanelComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_DrawPanelComponentResized
if (_ArmoredVehicle != null) {
_ArmoredVehicle.ChangeBorders(DrawPanel.getWidth(), DrawPanel.getHeight());
Draw();
}
}//GEN-LAST:event_DrawPanelComponentResized
private void CreateTankButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_CreateTankButtonMouseClicked
Random rnd = new Random();
Color newColor = JColorChooser.showDialog(null, "Choose a color", Color.RED);
Color newColorDop = JColorChooser.showDialog(null, "Choose a color", Color.RED);
_ArmoredVehicle = new DrawingTank(rnd.nextInt(100, 300),
rnd.nextInt(1000, 2000),
newColor,
newColorDop,
1==rnd.nextInt(0, 2), 1==rnd.nextInt(0, 2));
SetData();
Draw();
}//GEN-LAST:event_CreateTankButtonMouseClicked
private void SetButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_SetButtonMouseClicked
if (_ArmoredVehicle != null) {
SelectedMachine = _ArmoredVehicle;
dispose();
}
}//GEN-LAST:event_SetButtonMouseClicked
private void Draw()
{
Graphics g = DrawPanel.getGraphics();
g.drawImage(Pic(), 0, 0, this);
}
private void createUIComponents() {
DrawPanel = new JPanel() {
@Override
public void paintComponent(Graphics g) {
Draw();
}
};
}
Image Pic()
{
BufferedImage img = new BufferedImage(DrawPanel.getWidth(), DrawPanel.getHeight(), BufferedImage.TYPE_INT_BGR);
Graphics2D gr = img.createGraphics();
gr.setBackground(Color.yellow);
_ArmoredVehicle.DrawTransport(gr);
return img;
}
// public static void main(String args[]) {
// /* Set the Nimbus look and feel */
// //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
// /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
// * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
// */
// try {
// for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
// if ("Nimbus".equals(info.getName())) {
// javax.swing.UIManager.setLookAndFeel(info.getClassName());
// break;
// }
// }
// } catch (ClassNotFoundException ex) {
// java.util.logging.Logger.getLogger(MapForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
// } catch (InstantiationException ex) {
// java.util.logging.Logger.getLogger(MapForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
// } catch (IllegalAccessException ex) {
// java.util.logging.Logger.getLogger(MapForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
// } catch (javax.swing.UnsupportedLookAndFeelException ex) {
// java.util.logging.Logger.getLogger(MapForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
// }
// //</editor-fold>
//
// /* Create and display the form */
// java.awt.EventQueue.invokeLater(new Runnable() {
// public void run() {
// new MapForm().setVisible(true);
// }
// });
// }
// Variables declaration - do not modify//GEN-BEGIN:variables
private java.awt.Button CreateButton;
private java.awt.Button CreateTankButton;
private java.awt.Button DownButton;
private javax.swing.JPanel DrawPanel;
private java.awt.Button LeftButton;
private java.awt.TextField PropertyText;
private java.awt.Button RightButton;
private java.awt.Button SetButton;
private java.awt.Button UpButton;
// End of variables declaration//GEN-END:variables
}

View File

@@ -0,0 +1,66 @@
import java.lang.reflect.Array;
import java.util.ArrayList;
public class SetArmoredCarsGeneric<T> {
private T[] _places;
public SetArmoredCarsGeneric(int count)
{
_places = (T[]) new Object[count];
}
public int getCount() {
return _places != null ? _places.length : 0;
}
public int Insert(T armoredCar)
{
return Insert(armoredCar, 0);
}
public int Insert(T armoredCar, int position)
{
if (position < 0 || position >= getCount())
return -1;
if (!(_places[position] == null))
{
int index_empty = -1;
// поиск первого пустого элемента
for (int i = position + 1; i < getCount(); i++)
{
if (_places[i] == null)
{
index_empty = i;
}
}
if (index_empty == -1)
return -1;
else
{
for (int i = index_empty; i > position; i--)
{
_places[i] = _places[i - 1];
}
}
}
_places[position] = armoredCar;
return position;
}
public T Remove(int position)
{
if (position < 0 || position >= getCount())
return null;
T armoredCar = _places[position];
_places[position] = null;
return armoredCar;
}
public T Get(int position)
{
if (position < 0 || position >= getCount())
return null;
return _places[position];
}
}