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.FormAirport;
|
||||||
import Form.FormMapWithSetAircrafts;
|
import Form.FormMapWithSetAircrafts;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
public class App
|
public class App
|
||||||
{
|
{
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -1,58 +1,44 @@
|
|||||||
package Classes;
|
package Classes;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class EntityWithEngines<T extends EntityAircraft,U extends IDrawingEngines>
|
public class EntityWithEngines<T extends EntityAircraft,U extends IDrawingEngines>
|
||||||
{
|
{
|
||||||
Random rnd = new Random();
|
Random rnd = new Random();
|
||||||
public Object[] entities;
|
public ArrayList<T> entities;
|
||||||
int entitiesCount;
|
public ArrayList<U> engines;
|
||||||
public Object[] engines;
|
|
||||||
int enginesCount;
|
|
||||||
public final int maxElems;
|
|
||||||
|
|
||||||
public EntityWithEngines(int count)
|
public EntityWithEngines()
|
||||||
{
|
{
|
||||||
maxElems = count;
|
entities = new ArrayList<T>();
|
||||||
entities = new Object[count];
|
engines = new ArrayList<U>();
|
||||||
engines = new Object[count];
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addEntity(EntityAircraft aircraft)
|
public void addEntity(T aircraft)
|
||||||
{
|
{
|
||||||
if(entitiesCount + 1 > entities.length)
|
entities.add(aircraft);
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
entities[entitiesCount] = aircraft;
|
|
||||||
entitiesCount++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addEngines(IDrawingEngines engine)
|
public void addEngines(U engine)
|
||||||
{
|
{
|
||||||
if(enginesCount + 1 > engines.length)
|
engines.add(engine);
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
engines[enginesCount] = engine;
|
|
||||||
enginesCount++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public DrawingObjectAircraft createObject()
|
public DrawingObjectAircraft createObject()
|
||||||
{
|
{
|
||||||
if(enginesCount == 0 || entitiesCount == 0)
|
if(entities.size() == 0 || engines.size() == 0)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
EntityAircraft entity = (EntityAircraft) entities[rnd.nextInt(0,entitiesCount)];
|
EntityAircraft entity = (EntityAircraft) entities.get(rnd.nextInt(0, entities.size()));
|
||||||
IDrawingEngines engine = (IDrawingEngines) engines[rnd.nextInt(0,enginesCount)];
|
IDrawingEngines engine = (IDrawingEngines) engines.get(rnd.nextInt(0,engines.size()));
|
||||||
|
|
||||||
if(entity instanceof EntityMilitaryAircraft modAircraft)
|
if(entity instanceof EntityMilitaryAircraft modAircraft)
|
||||||
{
|
{
|
||||||
return new DrawingObjectAircraft(new DrawingMilitaryAircraft(modAircraft,engine));
|
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)
|
public T get(int position)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (position < _maxCount && position >= 0)
|
if (position < _maxCount && position >= 0)
|
||||||
{
|
{
|
||||||
return _places.get(position);
|
return _places.get(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ public class FormAirport extends JFrame{
|
|||||||
setContentPane(Form);
|
setContentPane(Form);
|
||||||
|
|
||||||
Random rnd = new Random();
|
Random rnd = new Random();
|
||||||
parts = new EntityWithEngines<>(15);
|
parts = new EntityWithEngines<>();
|
||||||
int mod = 0;
|
int mod = 0;
|
||||||
for(int i = 0 ; i < 15;i++)
|
for(int i = 0 ; i < 15;i++)
|
||||||
{
|
{
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<properties/>
|
<properties/>
|
||||||
<border type="none"/>
|
<border type="none"/>
|
||||||
<children>
|
<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"/>
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
<constraints border-constraint="Center"/>
|
<constraints border-constraint="Center"/>
|
||||||
<properties/>
|
<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"/>
|
<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>
|
</constraints>
|
||||||
</hspacer>
|
</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">
|
<component id="d798e" class="javax.swing.JButton" binding="AddAircraftButton">
|
||||||
<constraints>
|
<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>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<text value="Add aircraft"/>
|
<text value="Add aircraft"/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</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">
|
<component id="192c4" class="javax.swing.JButton" binding="DeleteAircraftButton">
|
||||||
<constraints>
|
<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>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<text value="Delete aircraft"/>
|
<text value="Delete aircraft"/>
|
||||||
@ -36,7 +63,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="f84e6" class="javax.swing.JButton" binding="ShowHangarButton">
|
<component id="f84e6" class="javax.swing.JButton" binding="ShowHangarButton">
|
||||||
<constraints>
|
<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>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<text value="Show hangar"/>
|
<text value="Show hangar"/>
|
||||||
@ -44,7 +71,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="1a170" class="javax.swing.JButton" binding="ShowMapButton">
|
<component id="1a170" class="javax.swing.JButton" binding="ShowMapButton">
|
||||||
<constraints>
|
<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>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<text value="Show map"/>
|
<text value="Show map"/>
|
||||||
@ -52,7 +79,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="32298" class="javax.swing.JButton" binding="moveUp">
|
<component id="32298" class="javax.swing.JButton" binding="moveUp">
|
||||||
<constraints>
|
<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"/>
|
<minimum-size width="30" height="30"/>
|
||||||
<preferred-size width="30" height="30"/>
|
<preferred-size width="30" height="30"/>
|
||||||
<maximum-size width="30" height="30"/>
|
<maximum-size width="30" height="30"/>
|
||||||
@ -64,23 +91,9 @@
|
|||||||
<text value=""/>
|
<text value=""/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</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">
|
<component id="6a898" class="javax.swing.JButton" binding="moveLeft">
|
||||||
<constraints>
|
<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"/>
|
<minimum-size width="30" height="30"/>
|
||||||
<preferred-size width="30" height="30"/>
|
<preferred-size width="30" height="30"/>
|
||||||
<maximum-size width="30" height="30"/>
|
<maximum-size width="30" height="30"/>
|
||||||
@ -92,9 +105,23 @@
|
|||||||
<text value=""/>
|
<text value=""/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</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">
|
<component id="a2ec2" class="javax.swing.JButton" binding="moveRight">
|
||||||
<constraints>
|
<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"/>
|
<minimum-size width="30" height="30"/>
|
||||||
<preferred-size width="30" height="30"/>
|
<preferred-size width="30" height="30"/>
|
||||||
<maximum-size width="30" height="30"/>
|
<maximum-size width="30" height="30"/>
|
||||||
@ -106,25 +133,11 @@
|
|||||||
<text value=""/>
|
<text value=""/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
<component id="f4aba" class="javax.swing.JFormattedTextField" binding="maskedTextBoxPosition">
|
<vspacer id="5a9ee">
|
||||||
<constraints>
|
<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">
|
<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"/>
|
||||||
<preferred-size width="150" height="-1"/>
|
|
||||||
</grid>
|
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties/>
|
</vspacer>
|
||||||
</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>
|
|
||||||
</children>
|
</children>
|
||||||
</grid>
|
</grid>
|
||||||
</children>
|
</children>
|
||||||
|
@ -19,7 +19,7 @@ import java.text.ParseException;
|
|||||||
|
|
||||||
public class FormMapWithSetAircrafts extends JFrame
|
public class FormMapWithSetAircrafts extends JFrame
|
||||||
{
|
{
|
||||||
private JPanel Form;
|
public JPanel Form;
|
||||||
private JPanel pictureBox;
|
private JPanel pictureBox;
|
||||||
private JComboBox comboBoxMapSelection;
|
private JComboBox comboBoxMapSelection;
|
||||||
|
|
||||||
@ -62,7 +62,6 @@ public class FormMapWithSetAircrafts extends JFrame
|
|||||||
{
|
{
|
||||||
_mapAircraftsCollectionGeneric = null;
|
_mapAircraftsCollectionGeneric = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addAircraft()
|
private void addAircraft()
|
||||||
@ -142,7 +141,6 @@ public class FormMapWithSetAircrafts extends JFrame
|
|||||||
case "right" -> dir = Direction.Right;
|
case "right" -> dir = Direction.Right;
|
||||||
case "up" -> dir = Direction.Up;
|
case "up" -> dir = Direction.Up;
|
||||||
case "down" -> dir = Direction.Down;
|
case "down" -> dir = Direction.Down;
|
||||||
|
|
||||||
}
|
}
|
||||||
bufferedImage = _mapAircraftsCollectionGeneric.MoveObject(dir);
|
bufferedImage = _mapAircraftsCollectionGeneric.MoveObject(dir);
|
||||||
repaint();
|
repaint();
|
||||||
@ -163,14 +161,11 @@ public class FormMapWithSetAircrafts extends JFrame
|
|||||||
moveRight.addActionListener(listener);
|
moveRight.addActionListener(listener);
|
||||||
moveLeft.addActionListener(listener);
|
moveLeft.addActionListener(listener);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ShowMapButton.addActionListener(e -> showMap());
|
ShowMapButton.addActionListener(e -> showMap());
|
||||||
comboBoxMapSelection.addActionListener(e -> indexChanged());
|
comboBoxMapSelection.addActionListener(e -> indexChanged());
|
||||||
AddAircraftButton.addActionListener(e -> addAircraft());
|
AddAircraftButton.addActionListener(e -> addAircraft());
|
||||||
DeleteAircraftButton.addActionListener(e -> DeleteAircraft());
|
DeleteAircraftButton.addActionListener(e -> DeleteAircraft());
|
||||||
ShowHangarButton.addActionListener(e -> ShowHangar());
|
ShowHangarButton.addActionListener(e -> ShowHangar());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void paint(Graphics g) {
|
public void paint(Graphics g) {
|
||||||
|
Loading…
Reference in New Issue
Block a user