LabWork03 is done.
This commit is contained in:
parent
9754f55a89
commit
65ee7b9c39
2
App.java
2
App.java
@ -2,6 +2,8 @@ import Form.FormAirFighter;
|
||||
import Form.FormAirport;
|
||||
import Form.FormMapWithSetAircrafts;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class App
|
||||
{
|
||||
public static void main(String[] args) {
|
||||
|
@ -1,58 +1,44 @@
|
||||
package Classes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
public class EntityWithEngines<T extends EntityAircraft,U extends IDrawingEngines>
|
||||
{
|
||||
Random rnd = new Random();
|
||||
public Object[] entities;
|
||||
int entitiesCount;
|
||||
public Object[] engines;
|
||||
int enginesCount;
|
||||
public final int maxElems;
|
||||
public ArrayList<T> entities;
|
||||
public ArrayList<U> engines;
|
||||
|
||||
public EntityWithEngines(int count)
|
||||
public EntityWithEngines()
|
||||
{
|
||||
maxElems = count;
|
||||
entities = new Object[count];
|
||||
engines = new Object[count];
|
||||
|
||||
entities = new ArrayList<T>();
|
||||
engines = new ArrayList<U>();
|
||||
}
|
||||
|
||||
public void addEntity(EntityAircraft aircraft)
|
||||
public void addEntity(T aircraft)
|
||||
{
|
||||
if(entitiesCount + 1 > entities.length)
|
||||
{
|
||||
return;
|
||||
}
|
||||
entities[entitiesCount] = aircraft;
|
||||
entitiesCount++;
|
||||
entities.add(aircraft);
|
||||
}
|
||||
|
||||
public void addEngines(IDrawingEngines engine)
|
||||
public void addEngines(U engine)
|
||||
{
|
||||
if(enginesCount + 1 > engines.length)
|
||||
{
|
||||
return;
|
||||
}
|
||||
engines[enginesCount] = engine;
|
||||
enginesCount++;
|
||||
engines.add(engine);
|
||||
}
|
||||
|
||||
public DrawingObjectAircraft createObject()
|
||||
{
|
||||
if(enginesCount == 0 || entitiesCount == 0)
|
||||
if(entities.size() == 0 || engines.size() == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
EntityAircraft entity = (EntityAircraft) entities[rnd.nextInt(0,entitiesCount)];
|
||||
IDrawingEngines engine = (IDrawingEngines) engines[rnd.nextInt(0,enginesCount)];
|
||||
EntityAircraft entity = (EntityAircraft) entities.get(rnd.nextInt(0, entities.size()));
|
||||
IDrawingEngines engine = (IDrawingEngines) engines.get(rnd.nextInt(0,engines.size()));
|
||||
|
||||
if(entity instanceof EntityMilitaryAircraft modAircraft)
|
||||
{
|
||||
return new DrawingObjectAircraft(new DrawingMilitaryAircraft(modAircraft,engine));
|
||||
}
|
||||
return new DrawingObjectAircraft(new DrawingMilitaryAircraft(entity,engine));
|
||||
return new DrawingObjectAircraft(new DrawingAircraft(entity,engine));
|
||||
|
||||
}
|
||||
|
||||
|
@ -57,14 +57,10 @@ public class SetAircraftsGeneric<T>
|
||||
|
||||
public T get(int position)
|
||||
{
|
||||
|
||||
if (position < _maxCount && position >= 0)
|
||||
{
|
||||
return _places.get(position);
|
||||
}
|
||||
|
||||
if (position < _maxCount && position >= 0)
|
||||
{
|
||||
return _places.get(position);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ public class FormAirport extends JFrame{
|
||||
setContentPane(Form);
|
||||
|
||||
Random rnd = new Random();
|
||||
parts = new EntityWithEngines<>(15);
|
||||
parts = new EntityWithEngines<>();
|
||||
int mod = 0;
|
||||
for(int i = 0 ; i < 15;i++)
|
||||
{
|
||||
|
@ -7,7 +7,7 @@
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="de9c4" binding="pictureBox" layout-manager="GridLayoutManager" row-count="8" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="de9c4" binding="pictureBox" layout-manager="GridLayoutManager" row-count="7" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints border-constraint="Center"/>
|
||||
<properties/>
|
||||
@ -18,17 +18,44 @@
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="4c74b" layout-manager="GridLayoutManager" row-count="9" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints border-constraint="East"/>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="e569a" class="javax.swing.JComboBox" binding="comboBoxMapSelection">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="3" vsize-policy="2" hsize-policy="2" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<model>
|
||||
<item value="1. Simple map"/>
|
||||
<item value="2. NightSky map"/>
|
||||
</model>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="d798e" class="javax.swing.JButton" binding="AddAircraftButton">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="4" vsize-policy="0" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<grid row="1" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Add aircraft"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="f4aba" class="javax.swing.JFormattedTextField" binding="maskedTextBoxPosition">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="192c4" class="javax.swing.JButton" binding="DeleteAircraftButton">
|
||||
<constraints>
|
||||
<grid row="3" column="1" row-span="1" col-span="4" vsize-policy="0" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<grid row="3" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Delete aircraft"/>
|
||||
@ -36,7 +63,7 @@
|
||||
</component>
|
||||
<component id="f84e6" class="javax.swing.JButton" binding="ShowHangarButton">
|
||||
<constraints>
|
||||
<grid row="4" column="1" row-span="1" col-span="4" vsize-policy="0" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<grid row="4" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Show hangar"/>
|
||||
@ -44,7 +71,7 @@
|
||||
</component>
|
||||
<component id="1a170" class="javax.swing.JButton" binding="ShowMapButton">
|
||||
<constraints>
|
||||
<grid row="5" column="1" row-span="1" col-span="4" vsize-policy="0" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<grid row="5" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Show map"/>
|
||||
@ -52,7 +79,7 @@
|
||||
</component>
|
||||
<component id="32298" class="javax.swing.JButton" binding="moveUp">
|
||||
<constraints>
|
||||
<grid row="6" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||
<grid row="7" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="2" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
@ -64,23 +91,9 @@
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="c514d" class="javax.swing.JButton" binding="moveDown">
|
||||
<constraints>
|
||||
<grid row="7" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<icon value="Resources/bottomarrow.png"/>
|
||||
<name value="down"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="6a898" class="javax.swing.JButton" binding="moveLeft">
|
||||
<constraints>
|
||||
<grid row="7" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||
<grid row="8" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="2" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
@ -92,9 +105,23 @@
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="c514d" class="javax.swing.JButton" binding="moveDown">
|
||||
<constraints>
|
||||
<grid row="8" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="2" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<icon value="Resources/bottomarrow.png"/>
|
||||
<name value="down"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="a2ec2" class="javax.swing.JButton" binding="moveRight">
|
||||
<constraints>
|
||||
<grid row="7" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||
<grid row="8" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="2" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
@ -106,25 +133,11 @@
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="f4aba" class="javax.swing.JFormattedTextField" binding="maskedTextBoxPosition">
|
||||
<vspacer id="5a9ee">
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="1" col-span="4" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
<grid row="6" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="e569a" class="javax.swing.JComboBox" binding="comboBoxMapSelection">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="4" vsize-policy="2" hsize-policy="2" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<model>
|
||||
<item value="1. Simple map"/>
|
||||
<item value="2. NightSky map"/>
|
||||
</model>
|
||||
</properties>
|
||||
</component>
|
||||
</vspacer>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
|
@ -19,7 +19,7 @@ import java.text.ParseException;
|
||||
|
||||
public class FormMapWithSetAircrafts extends JFrame
|
||||
{
|
||||
private JPanel Form;
|
||||
public JPanel Form;
|
||||
private JPanel pictureBox;
|
||||
private JComboBox comboBoxMapSelection;
|
||||
|
||||
@ -62,7 +62,6 @@ public class FormMapWithSetAircrafts extends JFrame
|
||||
{
|
||||
_mapAircraftsCollectionGeneric = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void addAircraft()
|
||||
@ -142,7 +141,6 @@ public class FormMapWithSetAircrafts extends JFrame
|
||||
case "right" -> dir = Direction.Right;
|
||||
case "up" -> dir = Direction.Up;
|
||||
case "down" -> dir = Direction.Down;
|
||||
|
||||
}
|
||||
bufferedImage = _mapAircraftsCollectionGeneric.MoveObject(dir);
|
||||
repaint();
|
||||
@ -163,14 +161,11 @@ public class FormMapWithSetAircrafts extends JFrame
|
||||
moveRight.addActionListener(listener);
|
||||
moveLeft.addActionListener(listener);
|
||||
|
||||
|
||||
|
||||
ShowMapButton.addActionListener(e -> showMap());
|
||||
comboBoxMapSelection.addActionListener(e -> indexChanged());
|
||||
AddAircraftButton.addActionListener(e -> addAircraft());
|
||||
DeleteAircraftButton.addActionListener(e -> DeleteAircraft());
|
||||
ShowHangarButton.addActionListener(e -> ShowHangar());
|
||||
|
||||
}
|
||||
|
||||
public void paint(Graphics g) {
|
||||
|
Loading…
Reference in New Issue
Block a user