Kashin M.I. Lab work 3 #6
38
src/CreaterGeneric.java
Normal file
38
src/CreaterGeneric.java
Normal file
@ -0,0 +1,38 @@
|
||||
import java.util.Random;
|
||||
import java.util.ArrayList;
|
||||
public class CreaterGeneric <T extends EntityGasolineTanker, U extends IDrawningObjectWheels>{
|
||||
ArrayList<T> GasolineTanker;
|
||||
ArrayList<U> Wheels;
|
||||
int GasolineTankerCount=0;
|
||||
int WheelsCount=0;
|
||||
public CreaterGeneric(int gasolineTankerCount,int wheelsCount){
|
||||
GasolineTanker=new ArrayList<>(gasolineTankerCount);
|
||||
Wheels=new ArrayList<>(wheelsCount);
|
||||
}
|
||||
public int Add(T gasolineTanker){
|
||||
if(GasolineTankerCount<=GasolineTanker.size()){
|
||||
GasolineTanker.add(gasolineTanker);
|
||||
GasolineTankerCount++;
|
||||
return GasolineTankerCount-1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
public int Add(U wheels){
|
||||
if(WheelsCount<=Wheels.size()){
|
||||
Wheels.add(wheels);
|
||||
WheelsCount++;
|
||||
return WheelsCount-1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
public DrawingGasolineTanker NewGasolineTankerCreating()
|
||||
{
|
||||
Random rand=new Random();
|
||||
T gasolineTanker = (GasolineTanker.get(rand.nextInt(GasolineTankerCount)));
|
||||
U wheel = (Wheels.get(rand.nextInt(WheelsCount)));
|
||||
if(gasolineTanker instanceof EntityImprovedGasolineTanker){
|
||||
return new DrawingImprovedGasolineTanker(gasolineTanker,wheel);
|
||||
}
|
||||
return new DrawingGasolineTanker(gasolineTanker,wheel);
|
||||
}
|
||||
}
|
@ -60,4 +60,7 @@ public class DrawingField extends JPanel{
|
||||
_gasolineTanker.DrawTransport(graphics);
|
||||
else return;
|
||||
}
|
||||
public DrawingGasolineTanker GetDrawingGasolineTanker() {
|
||||
return _gasolineTanker;
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,16 @@ public class DrawingGasolineTanker {
|
||||
Wheels= GetFormOfWheels(wheelsForm);
|
||||
Wheels.SetCountWheels((int)(2 + Math.random() + Math.random()*2));
|
||||
}
|
||||
public DrawingGasolineTanker(int speed, float weight, Color bodyColor, IDrawningObjectWheels wheelsForm)
|
||||
{
|
||||
GasolineTanker = new EntityGasolineTanker(speed, weight, bodyColor);
|
||||
Wheels= wheelsForm;
|
||||
}
|
||||
public DrawingGasolineTanker(EntityGasolineTanker gasolineTanker,IDrawningObjectWheels wheels)
|
||||
{
|
||||
GasolineTanker = gasolineTanker;
|
||||
Wheels = wheels;
|
||||
}
|
||||
|
||||
public IDrawningObjectWheels GetFormOfWheels(int FormOfWheel){
|
||||
OrnamentForm temp = null;
|
||||
|
@ -8,6 +8,16 @@ public class DrawingImprovedGasolineTanker extends DrawingGasolineTanker {
|
||||
Wheels= GetFormOfWheels(wheelForm);
|
||||
Wheels.SetCountWheels((int)(2 + Math.random() + Math.random()*2));
|
||||
}
|
||||
public DrawingImprovedGasolineTanker(int speed, float weight, Color bodyColor, Color dopColor, boolean bodyKit, boolean antena,IDrawningObjectWheels wheelForm) {
|
||||
super(speed, weight, bodyColor, 160, 70);
|
||||
GasolineTanker=new EntityImprovedGasolineTanker(speed,weight,bodyColor,dopColor,bodyKit,antena);
|
||||
Wheels= wheelForm;
|
||||
}
|
||||
public DrawingImprovedGasolineTanker(EntityGasolineTanker gasolineTanker,IDrawningObjectWheels wheels) {
|
||||
super(gasolineTanker,wheels);
|
||||
GasolineTanker=gasolineTanker;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void DrawTransport(Graphics g) {
|
||||
|
@ -1,71 +0,0 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawingMap extends JPanel {
|
||||
private final FormMap Map;
|
||||
private AbstractMap _abstractMap;
|
||||
BufferedImage bufferedImage;
|
||||
|
||||
public DrawingMap(FormMap map){
|
||||
Map=map;
|
||||
_abstractMap = new SimpleMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.drawImage(bufferedImage,0,0,null);
|
||||
}
|
||||
|
||||
private void SetData(DrawingGasolineTanker gasolineTanker) {
|
||||
Random rand=new Random();
|
||||
gasolineTanker.SetPosition(rand.nextInt(100)+10,rand.nextInt(100)+10,getWidth(),getHeight());
|
||||
Map.SpeedLabel.setText("Speed: "+gasolineTanker.getGasolineTanker().getSpeed());
|
||||
Map.WeightLabel.setText("Weight: "+gasolineTanker.getGasolineTanker().getWeight());
|
||||
Map.BodyColorLabel.setText("Color: "+Integer.toHexString(gasolineTanker.getGasolineTanker().getBodyColor().getRGB()).substring(2));
|
||||
bufferedImage = _abstractMap.CreateMap(700,550,new DrawingObjectGasolineTanker(gasolineTanker));
|
||||
}
|
||||
public void CreateButtonAction(){
|
||||
Random rand=new Random();
|
||||
Color color1=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
|
||||
if(color1==null)
|
||||
color1=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
|
||||
DrawingGasolineTanker gasolineTanker=new DrawingGasolineTanker(rand.nextInt(50)+10,rand.nextInt(3000)+20000,color1,rand.nextInt(3));
|
||||
SetData(gasolineTanker);
|
||||
}
|
||||
public void CreateModifButtonAction(){
|
||||
Random rand=new Random();
|
||||
Color color1=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
|
||||
Color color2=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
|
||||
if(color1==null)
|
||||
color1=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
|
||||
if (color2==null)
|
||||
color2=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
|
||||
DrawingGasolineTanker gasolineTanker = new DrawingImprovedGasolineTanker(rand.nextInt(50) + 10, rand.nextInt(3000) + 20000, color1,
|
||||
color2, rand.nextBoolean(), rand.nextBoolean(),rand.nextInt(3));
|
||||
SetData(gasolineTanker);
|
||||
}
|
||||
public void DirectionButtonAction(Direction side){
|
||||
if(_abstractMap != null){
|
||||
bufferedImage = _abstractMap.MoveObject(side);
|
||||
}
|
||||
}
|
||||
|
||||
public void ComboBoxSelectorMapAction(String name){
|
||||
switch (name){
|
||||
case "Simple map":
|
||||
_abstractMap = new SimpleMap();
|
||||
break;
|
||||
case "Long map":
|
||||
_abstractMap = new LongMap();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawMap(Graphics g){
|
||||
g.drawImage(bufferedImage,0,0,null);
|
||||
}
|
||||
|
||||
}
|
230
src/FormCreater.form
Normal file
230
src/FormCreater.form
Normal file
@ -0,0 +1,230 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormCreater">
|
||||
<grid id="27dc6" binding="PictureBox" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="1076" height="604"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="1ddce" layout-manager="GridLayoutManager" row-count="3" 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>
|
||||
<grid row="0" column="1" row-span="2" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="bevel-lowered" title="Setting"/>
|
||||
<children>
|
||||
<grid id="4fd6c" layout-manager="GridLayoutManager" row-count="5" 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>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="2d416" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="bevel-lowered" title="Characteristics gasoline tanker"/>
|
||||
<children>
|
||||
<component id="5f2c7" class="javax.swing.JLabel" binding="SetSpeedLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Speed:"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="460f9" class="javax.swing.JTextField" binding="SpeedTextField">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="8647d" class="javax.swing.JTextField" binding="WeightTextField">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="635c7" class="javax.swing.JLabel" binding="SetWeightLabel">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Weight:"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="f3a26" layout-manager="GridLayoutManager" row-count="2" 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>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="bevel-lowered" title="Improved"/>
|
||||
<children>
|
||||
<component id="a7785" class="javax.swing.JCheckBox" binding="BodyKitCheckBox">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Barrel"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="42af0" class="javax.swing.JCheckBox" binding="AntennaCheckBox">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Bulb"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="7b130" layout-manager="GridLayoutManager" row-count="2" 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>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="bevel-lowered" title="Type gasoline tanker"/>
|
||||
<children>
|
||||
<component id="da325" class="javax.swing.JRadioButton" binding="BasicRadioButton">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Simple"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="a537c" class="javax.swing.JRadioButton" binding="AdvancedRadioButton">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Improved"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="b3fe8" layout-manager="GridLayoutManager" row-count="3" 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>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="bevel-lowered" title="Count wheels"/>
|
||||
<children>
|
||||
<component id="c0d0c" class="javax.swing.JRadioButton" binding="TwoRadioButton">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="2"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="ffc90" class="javax.swing.JRadioButton" binding="ThreeRadioButton">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="3"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="eb57" class="javax.swing.JRadioButton" binding="FourRadioButton">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="4"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="99a4b" layout-manager="GridLayoutManager" row-count="3" 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>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="bevel-lowered" title="Color ornament"/>
|
||||
<children>
|
||||
<component id="acf86" class="javax.swing.JRadioButton" binding="NotOrnament">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Not ornament"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="52ce4" class="javax.swing.JRadioButton" binding="RedOrnament">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Red ornament"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="4f3ee" class="javax.swing.JRadioButton" binding="GrayOrnament">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Gray ornament"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<component id="8917a" class="javax.swing.JButton" binding="ChooseButton">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Choose"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="5c309" class="javax.swing.JButton" binding="ShowGasolineTankerButton">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Show"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="1063d" layout-manager="GridLayoutManager" row-count="1" 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>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="cc2a8" layout-manager="GridLayoutManager" row-count="1" 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>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
134
src/FormCreater.java
Normal file
134
src/FormCreater.java
Normal file
@ -0,0 +1,134 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class FormCreater extends JDialog{
|
||||
private JButton ChooseButton;
|
||||
private JButton ShowGasolineTankerButton;
|
||||
private JTextField SpeedTextField;
|
||||
private JTextField WeightTextField;
|
||||
private JCheckBox BodyKitCheckBox;
|
||||
private JCheckBox AntennaCheckBox;
|
||||
private JRadioButton BasicRadioButton;
|
||||
private JRadioButton AdvancedRadioButton;
|
||||
private JRadioButton TwoRadioButton;
|
||||
private JRadioButton ThreeRadioButton;
|
||||
private JRadioButton FourRadioButton;
|
||||
private JRadioButton NotOrnament;
|
||||
private JRadioButton RedOrnament;
|
||||
private JRadioButton GrayOrnament;
|
||||
private JLabel SetSpeedLabel;
|
||||
private JLabel SetWeightLabel;
|
||||
private JPanel PictureBox;
|
||||
CountWheels wheels=null;
|
||||
IDrawningObjectWheels fwheels=null;
|
||||
private final CreaterGeneric<EntityGasolineTanker,IDrawningObjectWheels> createrGeneric=new CreaterGeneric<>(40,40);
|
||||
private DrawingGasolineTanker _gasolineTanker;
|
||||
private DrawingGasolineTanker selectedGasolineTanker;
|
||||
|
||||
ImageIcon spriteUp =new ImageIcon((new ImageIcon("Material\\KeyUp.png")).
|
||||
getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH));
|
||||
ImageIcon spriteDown =new ImageIcon((new ImageIcon("Material\\KeyDown.png")).
|
||||
getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH));
|
||||
ImageIcon spriteLeft =new ImageIcon((new ImageIcon("Material\\KeyLeft.png")).
|
||||
getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH));
|
||||
ImageIcon spriteRight =new ImageIcon((new ImageIcon("Material\\KeyRight.png")).
|
||||
getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH));
|
||||
public FormCreater(){
|
||||
setTitle("Gasoline tanker");
|
||||
setContentPane(PictureBox);
|
||||
setResizable(false);
|
||||
setSize(1000,500);
|
||||
ShowWindow();
|
||||
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
super.paint(g);
|
||||
Graphics2D g2d = (Graphics2D) PictureBox.getGraphics();
|
||||
if (_gasolineTanker != null) {
|
||||
_gasolineTanker.DrawTransport(g2d);
|
||||
}
|
||||
}
|
||||
private void ShowWindow(){
|
||||
|
||||
TwoRadioButton.addActionListener(e -> {
|
||||
wheels=CountWheels.Two;
|
||||
});
|
||||
ThreeRadioButton.addActionListener(e -> {
|
||||
wheels=CountWheels.Three;
|
||||
});
|
||||
FourRadioButton.addActionListener(e -> {
|
||||
wheels=CountWheels.Four;
|
||||
});
|
||||
|
||||
NotOrnament.addActionListener(e -> {
|
||||
if(wheels==null){
|
||||
return;
|
||||
}
|
||||
fwheels=new DrawingWheels(wheels);
|
||||
if(fwheels==null)
|
||||
return;
|
||||
fwheels.SetCountWheels(wheels.getCountWheels());
|
||||
createrGeneric.Add(fwheels);
|
||||
});
|
||||
|
||||
RedOrnament.addActionListener(e -> {
|
||||
if(wheels==null){
|
||||
return;
|
||||
}
|
||||
fwheels=new DrawingOrnamentWheelsSecond(wheels);
|
||||
if(fwheels==null)
|
||||
return;
|
||||
fwheels.SetCountWheels(wheels.getCountWheels());
|
||||
createrGeneric.Add(fwheels);
|
||||
});
|
||||
|
||||
GrayOrnament.addActionListener(e -> {
|
||||
if(wheels==null){
|
||||
return;
|
||||
}
|
||||
fwheels=new DrawingOrnamentWheelsFirst(wheels);
|
||||
if(fwheels==null)
|
||||
return;
|
||||
fwheels.SetCountWheels(wheels.getCountWheels());
|
||||
createrGeneric.Add(fwheels);
|
||||
});
|
||||
|
||||
BasicRadioButton.addActionListener(e -> {
|
||||
Color color=JColorChooser.showDialog(this,"Select body color",Color.WHITE);
|
||||
if(Integer.parseInt(SpeedTextField.getText())==0 || Integer.parseInt(WeightTextField.getText())==0 || color==null){
|
||||
return;
|
||||
}
|
||||
createrGeneric.Add(new EntityGasolineTanker(Integer.parseInt(SpeedTextField.getText()),Integer.parseInt(WeightTextField.getText()),color));
|
||||
});
|
||||
|
||||
AdvancedRadioButton.addActionListener(e -> {
|
||||
Color color1=JColorChooser.showDialog(this,"Select body color",Color.WHITE);
|
||||
if(Integer.parseInt(SpeedTextField.getText())==0 || Integer.parseInt(WeightTextField.getText())==0 || color1==null){
|
||||
return;
|
||||
}
|
||||
Color color2=JColorChooser.showDialog(this,"Select modification color",Color.WHITE);
|
||||
if(color2==null){
|
||||
return;
|
||||
}
|
||||
createrGeneric.Add(new EntityImprovedGasolineTanker(Integer.parseInt(SpeedTextField.getText()),Integer.parseInt(WeightTextField.getText()),
|
||||
color1,color2, BodyKitCheckBox.isSelected(),AntennaCheckBox.isSelected()));
|
||||
});
|
||||
|
||||
ShowGasolineTankerButton.addActionListener(e -> {
|
||||
Random rand=new Random();
|
||||
_gasolineTanker=createrGeneric.NewGasolineTankerCreating();
|
||||
_gasolineTanker.SetPosition(rand.nextInt(100),rand.nextInt(100),getWidth(),getHeight());
|
||||
repaint();
|
||||
});
|
||||
ChooseButton.addActionListener(e -> {
|
||||
selectedGasolineTanker=_gasolineTanker;
|
||||
dispose();
|
||||
});
|
||||
}
|
||||
public DrawingGasolineTanker getSelectedGasolineTanker() {
|
||||
return selectedGasolineTanker;
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormGasolineTanker">
|
||||
<grid id="27dc6" binding="PictureBox" layout-manager="GridLayoutManager" row-count="3" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="27dc6" binding="PictureBox" layout-manager="GridLayoutManager" row-count="3" column-count="6" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="572" height="400"/>
|
||||
<xy x="20" y="20" width="664" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
@ -11,7 +11,7 @@
|
||||
<grid id="1123e" layout-manager="GridLayoutManager" row-count="1" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="5" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<grid row="2" column="0" row-span="1" col-span="6" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
@ -76,7 +76,7 @@
|
||||
<grid id="39656" layout-manager="GridLayoutManager" row-count="2" 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>
|
||||
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<grid row="1" column="4" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
@ -128,7 +128,7 @@
|
||||
<grid id="d5026" layout-manager="GridLayoutManager" row-count="1" 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>
|
||||
<grid row="1" column="4" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<grid row="1" column="5" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
@ -155,6 +155,24 @@
|
||||
</hspacer>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="b72a1" layout-manager="GridLayoutManager" row-count="1" 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>
|
||||
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="d037b" class="javax.swing.JButton" binding="ButtonSelect">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Button"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
|
@ -7,6 +7,7 @@ public class FormGasolineTanker extends JFrame{
|
||||
private int Width;
|
||||
private int Height;
|
||||
DrawingField field = new DrawingField(this);
|
||||
DrawingGasolineTanker SelectedGasolineTanker;
|
||||
private JButton ButtonDown;
|
||||
private JButton ButtonRight;
|
||||
private JButton ButtonLeft;
|
||||
@ -17,6 +18,7 @@ public class FormGasolineTanker extends JFrame{
|
||||
public JLabel WeightLabel;
|
||||
public JLabel BodyColorLabel;
|
||||
private JPanel PictureBox;
|
||||
private JButton ButtonSelect;
|
||||
|
||||
public FormGasolineTanker(){
|
||||
super("Gasoline Tanker");
|
||||
@ -67,6 +69,10 @@ public class FormGasolineTanker extends JFrame{
|
||||
field.DirectionButtonAction(Direction.Down);
|
||||
ReDraw();
|
||||
});
|
||||
ButtonSelect.addActionListener(e -> {
|
||||
SelectedGasolineTanker=field.GetDrawingGasolineTanker();
|
||||
JOptionPane.showMessageDialog(PictureBox, "Gasoline tanker added.");
|
||||
});
|
||||
|
||||
addComponentListener(new ComponentAdapter() {
|
||||
@Override
|
||||
@ -88,4 +94,5 @@ public class FormGasolineTanker extends JFrame{
|
||||
PictureBox.paintComponents(graphics);
|
||||
field.Draw(graphics);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,87 +0,0 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.util.Objects;
|
||||
|
||||
public class FormMap extends JFrame {
|
||||
private int Width;
|
||||
private int Height;
|
||||
DrawingMap map = new DrawingMap(this);
|
||||
private JButton ButtonDown;
|
||||
private JButton ButtonRight;
|
||||
private JButton ButtonLeft;
|
||||
private JButton ButtonUp;
|
||||
private JButton ButtonCreate;
|
||||
private JButton ButtonCreateModif;
|
||||
public JLabel SpeedLabel;
|
||||
public JLabel WeightLabel;
|
||||
public JLabel BodyColorLabel;
|
||||
private JComboBox ComboBoxSelectorMap;
|
||||
private JPanel PictureBox;
|
||||
ImageIcon spriteUp =new ImageIcon((new ImageIcon("Material\\KeyUp.png")).
|
||||
getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH));
|
||||
ImageIcon spriteDown =new ImageIcon((new ImageIcon("Material\\KeyDown.png")).
|
||||
getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH));
|
||||
ImageIcon spriteLeft =new ImageIcon((new ImageIcon("Material\\KeyLeft.png")).
|
||||
getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH));
|
||||
ImageIcon spriteRight =new ImageIcon((new ImageIcon("Material\\KeyRight.png")).
|
||||
getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH));
|
||||
public FormMap(){
|
||||
super("Gasoline tanker");
|
||||
setContentPane(PictureBox);
|
||||
setSize(1000,700);
|
||||
Width = getWidth();
|
||||
Height = getHeight();
|
||||
ShowWindow();
|
||||
map.setBounds(0,0,Width,Height);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
private void ShowWindow(){
|
||||
ButtonCreate.addActionListener(e -> {
|
||||
map.CreateButtonAction();
|
||||
ReDraw();
|
||||
});
|
||||
ButtonCreateModif.addActionListener(e -> {
|
||||
map.CreateModifButtonAction();
|
||||
ReDraw();
|
||||
});
|
||||
ButtonUp.setIcon(spriteUp);
|
||||
ButtonUp.addActionListener(e -> {
|
||||
map.DirectionButtonAction(Direction.Up);
|
||||
ReDraw();
|
||||
});
|
||||
ButtonLeft.setIcon(spriteLeft);
|
||||
ButtonLeft.addActionListener(e -> {
|
||||
map.DirectionButtonAction(Direction.Left);
|
||||
ReDraw();
|
||||
});
|
||||
ButtonRight.setIcon(spriteRight);
|
||||
ButtonRight.addActionListener(e -> {
|
||||
map.DirectionButtonAction(Direction.Right);
|
||||
ReDraw();
|
||||
});
|
||||
ButtonDown.setIcon(spriteDown);
|
||||
ButtonDown.addActionListener(e -> {
|
||||
map.DirectionButtonAction(Direction.Down);
|
||||
ReDraw();
|
||||
});
|
||||
|
||||
ComboBoxSelectorMap.addActionListener(e -> {
|
||||
map.ComboBoxSelectorMapAction(Objects.requireNonNull(ComboBoxSelectorMap.getSelectedItem()).toString());
|
||||
ReDraw();
|
||||
});
|
||||
}
|
||||
private void ReDraw()
|
||||
{
|
||||
Graphics2D graphics = (Graphics2D) PictureBox.getGraphics();
|
||||
graphics.clearRect(0, 0, PictureBox.getWidth(), PictureBox.getHeight());
|
||||
PictureBox.paintComponents(graphics);
|
||||
map.DrawMap(graphics);
|
||||
}
|
||||
|
||||
}
|
@ -1,111 +1,108 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormMap">
|
||||
<grid id="27dc6" binding="PictureBox" layout-manager="GridLayoutManager" row-count="4" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormMapWithSetGasolineTanker">
|
||||
<grid id="27dc6" binding="MainPanel" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="572" height="400"/>
|
||||
<xy x="20" y="20" width="668" height="474"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="3d1ad" layout-manager="GridLayoutManager" row-count="1" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="42b0" binding="GroupBoxTools" layout-manager="GridLayoutManager" row-count="9" 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>
|
||||
<grid row="3" column="0" row-span="1" col-span="5" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<border type="bevel-lowered" title=" Tools"/>
|
||||
<children>
|
||||
<component id="325b7" class="javax.swing.JLabel" binding="SpeedLabel">
|
||||
<grid id="bc845" layout-manager="GridLayoutManager" row-count="1" 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>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<vspacer id="9ecc2">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
</children>
|
||||
</grid>
|
||||
<component id="52e81" class="javax.swing.JComboBox" binding="СomboBoxSelectorMap">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Speed:"/>
|
||||
<model>
|
||||
<item value="Simple map"/>
|
||||
<item value="Long map"/>
|
||||
</model>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="b7022">
|
||||
<vspacer id="f144d">
|
||||
<constraints>
|
||||
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<component id="fead2" class="javax.swing.JLabel" binding="WeightLabel">
|
||||
</vspacer>
|
||||
<component id="f5a9c" class="javax.swing.JButton" binding="ButtonAddGasolineTanker">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Weight:"/>
|
||||
<text value="Add"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="f9385" class="javax.swing.JLabel" binding="BodyColorLabel">
|
||||
<component id="ceb03" class="javax.swing.JTextField" binding="TextBoxPosition">
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="c29a2" class="javax.swing.JButton" binding="ButtonRemoveGasolineTanker">
|
||||
<constraints>
|
||||
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Color:"/>
|
||||
<text value="Remove"/>
|
||||
</properties>
|
||||
</component>
|
||||
<vspacer id="76e51">
|
||||
<constraints>
|
||||
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="42b8e" class="javax.swing.JButton" binding="ButtonShowStorage">
|
||||
<constraints>
|
||||
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Storage"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="62dd6" class="javax.swing.JButton" binding="ButtonShowOnMap">
|
||||
<constraints>
|
||||
<grid row="8" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Map"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="86b55" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="c9878" layout-manager="GridLayoutManager" row-count="2" 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>
|
||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="cb255" class="javax.swing.JButton" binding="ButtonCreate">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Create"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="269f9" class="javax.swing.JButton" binding="ButtonCreateModif">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Improved create"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="53d05" layout-manager="GridLayoutManager" row-count="2" 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>
|
||||
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="b822e" class="javax.swing.JButton" binding="ButtonUp">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="c8a05" class="javax.swing.JButton" binding="ButtonDown">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="ee84a" class="javax.swing.JButton" binding="ButtonRight">
|
||||
<constraints>
|
||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="b182f" class="javax.swing.JButton" binding="ButtonLeft">
|
||||
<component id="cac88" class="javax.swing.JButton" binding="ButtonLeft">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
@ -113,59 +110,61 @@
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="bd727" class="javax.swing.JButton" binding="ButtonDown">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="1ff1c" class="javax.swing.JButton" binding="ButtonRight">
|
||||
<constraints>
|
||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="b4d3c" class="javax.swing.JButton" binding="ButtonUp">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<component id="5081d" class="javax.swing.JComboBox" binding="ComboBoxSelectorMap">
|
||||
<constraints>
|
||||
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<model>
|
||||
<item value="Simple map"/>
|
||||
<item value="Long map"/>
|
||||
</model>
|
||||
</properties>
|
||||
</component>
|
||||
<vspacer id="ee7b4">
|
||||
<constraints>
|
||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<grid id="d0ad5" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="ad00b" binding="PictureBox" layout-manager="GridLayoutManager" row-count="1" 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>
|
||||
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<grid row="1" column="0" row-span="3" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<hspacer id="33887">
|
||||
<constraints>
|
||||
<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>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="a07b0" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<hspacer id="29fed">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<hspacer id="276f9">
|
||||
<constraints>
|
||||
<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>
|
||||
<hspacer id="7b3f3">
|
||||
<constraints>
|
||||
<grid row="2" column="2" 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>
|
||||
</hspacer>
|
||||
<grid id="91c98" layout-manager="GridLayoutManager" row-count="1" 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>
|
||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<vspacer id="43d2a">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
177
src/FormMapWithSetGasolineTanker.java
Normal file
177
src/FormMapWithSetGasolineTanker.java
Normal file
@ -0,0 +1,177 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.util.Objects;
|
||||
|
||||
public class FormMapWithSetGasolineTanker extends JFrame{
|
||||
private JPanel GroupBoxTools;
|
||||
private JComboBox СomboBoxSelectorMap;
|
||||
private JButton ButtonAddGasolineTanker;
|
||||
private JButton ButtonRemoveGasolineTanker;
|
||||
private JButton ButtonShowStorage;
|
||||
private JButton ButtonShowOnMap;
|
||||
private JButton ButtonLeft;
|
||||
private JButton ButtonDown;
|
||||
private JButton ButtonRight;
|
||||
private JButton ButtonUp;
|
||||
private JPanel MainPanel;
|
||||
private JTextField TextBoxPosition;
|
||||
private JPanel PictureBox;
|
||||
private Image bufferedImage;
|
||||
|
||||
private MapWithSetGasolineTankerGeneric<DrawingObjectGasolineTanker,AbstractMap> _mapGasolineTankerCollectionGeneric;
|
||||
|
||||
ImageIcon spriteUp =new ImageIcon((new ImageIcon("Material\\KeyUp.png")).
|
||||
getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH));
|
||||
ImageIcon spriteDown =new ImageIcon((new ImageIcon("Material\\KeyDown.png")).
|
||||
getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH));
|
||||
ImageIcon spriteLeft =new ImageIcon((new ImageIcon("Material\\KeyLeft.png")).
|
||||
getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH));
|
||||
ImageIcon spriteRight =new ImageIcon((new ImageIcon("Material\\KeyRight.png")).
|
||||
getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH));
|
||||
public FormMapWithSetGasolineTanker(){
|
||||
setTitle("Gasoline tanker");
|
||||
setContentPane(MainPanel);
|
||||
setResizable(false);
|
||||
setSize(1000,685);
|
||||
ShowWindow();
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
super.paint(g);
|
||||
|
||||
if (bufferedImage != null) {
|
||||
PictureBox.paintComponents(bufferedImage.getGraphics());
|
||||
PictureBox.getGraphics().drawImage(bufferedImage, 0, 0, null);
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowWindow(){
|
||||
|
||||
ButtonShowOnMap.addActionListener(e -> {
|
||||
if (_mapGasolineTankerCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
bufferedImage = _mapGasolineTankerCollectionGeneric.ShowOnMap();
|
||||
repaint();
|
||||
});
|
||||
|
||||
ButtonShowStorage.addActionListener(e -> {
|
||||
if (_mapGasolineTankerCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
bufferedImage = _mapGasolineTankerCollectionGeneric.ShowSet();
|
||||
repaint();
|
||||
});
|
||||
|
||||
ButtonAddGasolineTanker.addActionListener(e -> {
|
||||
if (_mapGasolineTankerCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormCreater dialog=new FormCreater();
|
||||
dialog.setSize(1200,700);
|
||||
dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
|
||||
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
dialog.setVisible(true);
|
||||
if (dialog.getSelectedGasolineTanker()!=null) {
|
||||
DrawingObjectGasolineTanker gasolineTanker = new DrawingObjectGasolineTanker(dialog.getSelectedGasolineTanker());
|
||||
|
||||
if (_mapGasolineTankerCollectionGeneric.plus(gasolineTanker) >= 0) {
|
||||
JOptionPane.showMessageDialog(this, "\n" + "Object added", "Success", JOptionPane.INFORMATION_MESSAGE);
|
||||
bufferedImage = _mapGasolineTankerCollectionGeneric.ShowSet();
|
||||
repaint();
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(this, "Failed to add object", "Error",JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ButtonRemoveGasolineTanker.addActionListener(e -> {
|
||||
String txt=TextBoxPosition.getText();
|
||||
if (txt==null||_mapGasolineTankerCollectionGeneric==null||txt.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
int result = JOptionPane.showConfirmDialog(
|
||||
this,
|
||||
"Delete object?",
|
||||
"Delete",
|
||||
JOptionPane.YES_NO_CANCEL_OPTION);
|
||||
if (result == JOptionPane.NO_OPTION)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Integer.parseInt(txt);
|
||||
if (_mapGasolineTankerCollectionGeneric.minus(pos) !=null)
|
||||
{
|
||||
JOptionPane.showMessageDialog(this,"Object added", "Success",JOptionPane.INFORMATION_MESSAGE);
|
||||
bufferedImage = _mapGasolineTankerCollectionGeneric.ShowSet();
|
||||
repaint();
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(this,"Failed to add object", "Error",JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
});
|
||||
|
||||
СomboBoxSelectorMap.addActionListener(e -> {
|
||||
AbstractMap map = null;
|
||||
|
||||
switch (СomboBoxSelectorMap.getSelectedItem().toString())
|
||||
{
|
||||
case "Simple map":
|
||||
map = new SimpleMap();
|
||||
break;
|
||||
case "Long map":
|
||||
map = new LongMap();
|
||||
break;
|
||||
}
|
||||
if (map != null)
|
||||
{
|
||||
_mapGasolineTankerCollectionGeneric = new MapWithSetGasolineTankerGeneric<>(
|
||||
PictureBox.getWidth(), PictureBox.getHeight(), map);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mapGasolineTankerCollectionGeneric = null;
|
||||
}
|
||||
});
|
||||
ButtonUp.setIcon(spriteUp);
|
||||
ButtonUp.addActionListener(e -> {
|
||||
if (_mapGasolineTankerCollectionGeneric != null) {
|
||||
bufferedImage = _mapGasolineTankerCollectionGeneric.MoveObject(Direction.Up);
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
ButtonDown.setIcon(spriteDown);
|
||||
ButtonDown.addActionListener(e -> {
|
||||
if (_mapGasolineTankerCollectionGeneric != null) {
|
||||
bufferedImage = _mapGasolineTankerCollectionGeneric.MoveObject(Direction.Down);
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
ButtonRight.setIcon(spriteRight);
|
||||
ButtonRight.addActionListener(e -> {
|
||||
if (_mapGasolineTankerCollectionGeneric != null) {
|
||||
bufferedImage = _mapGasolineTankerCollectionGeneric.MoveObject(Direction.Right);
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
ButtonLeft.setIcon(spriteLeft);
|
||||
ButtonLeft.addActionListener(e -> {
|
||||
if (_mapGasolineTankerCollectionGeneric != null) {
|
||||
bufferedImage = _mapGasolineTankerCollectionGeneric.MoveObject(Direction.Left);
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
new FormMap();
|
||||
new FormMapWithSetGasolineTanker();
|
||||
}
|
||||
}
|
125
src/MapWithSetGasolineTankerGeneric.java
Normal file
125
src/MapWithSetGasolineTankerGeneric.java
Normal file
@ -0,0 +1,125 @@
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class MapWithSetGasolineTankerGeneric <T extends IDrawingObject,U extends AbstractMap>{
|
||||
private final int _pictureWidth;
|
||||
private final int _pictureHeight;
|
||||
private final int _placeSizeWidth = 210;
|
||||
private final int _placeSizeHeight = 90;
|
||||
private final SetGasolineTankerGeneric<T> _setGasolineTanker;
|
||||
private final U _map;
|
||||
|
||||
public MapWithSetGasolineTankerGeneric(int picWidth,int picHeight, U map)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight/_placeSizeHeight;
|
||||
_setGasolineTanker = new SetGasolineTankerGeneric<>(width * height);
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_map = map;
|
||||
}
|
||||
|
||||
public int plus(T gasolineTanker)
|
||||
{
|
||||
return _setGasolineTanker.Insert(gasolineTanker);
|
||||
}
|
||||
|
||||
public T minus(int position)
|
||||
{
|
||||
return _setGasolineTanker.Remove(position);
|
||||
}
|
||||
|
||||
public Image ShowSet()
|
||||
{
|
||||
BufferedImage bmp = new BufferedImage(_pictureWidth, _pictureWidth,BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics gr = bmp.getGraphics();
|
||||
DrawBackground(gr);
|
||||
DrawGasolineTanker(gr);
|
||||
return bmp;
|
||||
}
|
||||
|
||||
public Image ShowOnMap()
|
||||
{
|
||||
Shaking();
|
||||
for (int i = 0; i < _setGasolineTanker.Count(); i++)
|
||||
{
|
||||
T gasolineTanker = _setGasolineTanker.Get(i);
|
||||
if (gasolineTanker != null)
|
||||
{
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, gasolineTanker);
|
||||
}
|
||||
}
|
||||
return new BufferedImage(_pictureWidth, _pictureHeight,1);
|
||||
}
|
||||
|
||||
public Image MoveObject(Direction direction)
|
||||
{
|
||||
if (_map != null)
|
||||
{
|
||||
return _map.MoveObject(direction);
|
||||
}
|
||||
return new BufferedImage(_pictureWidth, _pictureHeight,1);
|
||||
}
|
||||
|
||||
public void Shaking()
|
||||
{
|
||||
int j = _setGasolineTanker.Count() - 1;
|
||||
for (int i = 0; i < _setGasolineTanker.Count(); i++)
|
||||
{
|
||||
if (_setGasolineTanker.Get(i) == null)
|
||||
{
|
||||
for (; j > i; j--)
|
||||
{
|
||||
T gasolineTanker = _setGasolineTanker.Get(j);
|
||||
if (gasolineTanker != null)
|
||||
{
|
||||
_setGasolineTanker.Insert(gasolineTanker, i);
|
||||
_setGasolineTanker.Remove(j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j <= i)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawBackground(Graphics gr)
|
||||
{
|
||||
Graphics2D g=(Graphics2D)gr;
|
||||
|
||||
Color brush=Color.BLACK;
|
||||
Stroke penWide = new BasicStroke(5);
|
||||
Stroke penThin = new BasicStroke(1);
|
||||
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||
{
|
||||
g.setColor(brush);
|
||||
g.setStroke(penWide);
|
||||
g.drawLine(i * _placeSizeWidth + 10, j * _placeSizeHeight + 2, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.8), j * _placeSizeHeight + 2);
|
||||
g.drawLine(i * _placeSizeWidth + (int)(_placeSizeWidth * 0.8), j * _placeSizeHeight + 2, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.9) + 10, j * _placeSizeHeight + 2 + 20);
|
||||
g.drawLine(i * _placeSizeWidth + (int)(_placeSizeWidth * 0.9) + 10, j * _placeSizeHeight + 2 + 20, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.9) + 10, j * _placeSizeHeight + 2 + 20);
|
||||
g.setStroke(penThin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawGasolineTanker(Graphics gr)
|
||||
{
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
|
||||
for (int i = 0; i < _setGasolineTanker.Count(); i++)
|
||||
{
|
||||
if (_setGasolineTanker.Get(i) != null)
|
||||
{
|
||||
_setGasolineTanker.Get(i).SetObject(i % width * _placeSizeWidth, (height - 1 - i / width) * _placeSizeHeight, _pictureWidth, _pictureHeight);
|
||||
_setGasolineTanker.Get(i).DrawingObject(gr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
68
src/SetGasolineTankerGeneric.java
Normal file
68
src/SetGasolineTankerGeneric.java
Normal file
@ -0,0 +1,68 @@
|
||||
public class SetGasolineTankerGeneric <T extends Object>{
|
||||
private final Object[] _places;
|
||||
|
||||
public int Count() {
|
||||
return _places.length;
|
||||
}
|
||||
|
||||
public SetGasolineTankerGeneric(int count)
|
||||
{
|
||||
_places = new Object[count];
|
||||
}
|
||||
|
||||
public int Insert(T gasolineTanker)
|
||||
{
|
||||
return Insert(gasolineTanker,0);
|
||||
}
|
||||
|
||||
public int Insert(T gasolineTanker, int position)
|
||||
{
|
||||
int EmptyEl=-1;
|
||||
|
||||
if (position>=Count() || position < 0)
|
||||
return -1;
|
||||
|
||||
if (_places[position] == null)
|
||||
{
|
||||
_places[position] = gasolineTanker;
|
||||
return 1;
|
||||
}
|
||||
|
||||
else if (_places[position] != null)
|
||||
{
|
||||
for (int i = position + 1; i < Count(); i++)
|
||||
if (_places[i] == null)
|
||||
{
|
||||
EmptyEl = i;
|
||||
break;
|
||||
}
|
||||
|
||||
if (EmptyEl == -1)
|
||||
return -1;
|
||||
|
||||
for (int i = EmptyEl; i > position; i--)
|
||||
_places[i] = _places[i - 1];
|
||||
}
|
||||
|
||||
_places[position] = gasolineTanker;
|
||||
return 1;
|
||||
}
|
||||
|
||||
public T Remove(int position)
|
||||
{
|
||||
if (position >= Count() || position < 0 || _places[position]==null)
|
||||
return null;
|
||||
|
||||
T deleted =(T)_places[position];
|
||||
_places[position] = null;
|
||||
return deleted;
|
||||
}
|
||||
|
||||
public T Get(int position)
|
||||
{
|
||||
if (position >= Count() || position < 0)
|
||||
return null;
|
||||
|
||||
return (T)_places[position];
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user