Minhasapov R.H. LabWork03 #3
137
FormMap.form
137
FormMap.form
@ -1,137 +0,0 @@
|
||||
<?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="ContentPanel" layout-manager="GridLayoutManager" row-count="3" column-count="7" 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="649" height="378"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<hspacer id="c78b3">
|
||||
<constraints>
|
||||
<grid row="1" column="2" row-span="1" col-span="2" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<component id="a12e7" class="javax.swing.JButton" binding="buttonUp">
|
||||
<constraints>
|
||||
<grid row="1" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<icon value="Resources/arrowUp.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="5942f" class="javax.swing.JButton" binding="buttonLeft">
|
||||
<constraints>
|
||||
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<icon value="Resources/arrowLeft.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="65b3a" class="javax.swing.JButton" binding="buttonDown">
|
||||
<constraints>
|
||||
<grid row="2" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<icon value="Resources/arrowDown.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="233b7" class="javax.swing.JButton" binding="buttonRight">
|
||||
<constraints>
|
||||
<grid row="2" column="6" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<icon value="Resources/arrowRight.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="22c" class="javax.swing.JLabel" binding="speedLabel">
|
||||
<constraints>
|
||||
<grid row="2" 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="Скорость:"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="98c1e" class="javax.swing.JLabel" binding="weightLabel">
|
||||
<constraints>
|
||||
<grid row="2" column="1" 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="Вес:"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="252d3" class="javax.swing.JLabel" binding="colorLabel">
|
||||
<constraints>
|
||||
<grid row="2" column="2" 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="Цвет:"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="7e6d3" class="javax.swing.JButton" binding="buttonCreate">
|
||||
<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="Создать"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="f3e60" class="javax.swing.JButton" binding="buttonCreateModif">
|
||||
<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>
|
||||
<grid id="98ed5" 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>
|
||||
<grid row="0" column="0" row-span="1" col-span="7" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="ee7c6" class="javax.swing.JComboBox" binding="comboBoxMapSelector">
|
||||
<constraints>
|
||||
<grid row="0" 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>
|
||||
<model>
|
||||
<item value="Простая карта"/>
|
||||
<item value="Свалка карта"/>
|
||||
</model>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="4e1e1">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<vspacer id="d19f">
|
||||
<constraints>
|
||||
<grid row="1" 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>
|
116
FormMap.java
116
FormMap.java
@ -1,116 +0,0 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.util.Random;
|
||||
|
||||
public class FormMap extends JFrame {
|
||||
private JPanel ContentPanel;
|
||||
private JButton buttonCreate;
|
||||
private JLabel speedLabel;
|
||||
private JLabel weightLabel;
|
||||
private JLabel colorLabel;
|
||||
private JButton buttonLeft;
|
||||
private JButton buttonDown;
|
||||
private JButton buttonRight;
|
||||
private JButton buttonUp;
|
||||
private JPanel pictureBox;
|
||||
private JButton buttonCreateModif;
|
||||
private JComboBox<String> comboBoxMapSelector;
|
||||
|
||||
private AbstractMap _abstractMap;
|
||||
private Image imageBuffer;
|
||||
|
||||
public FormMap(){
|
||||
setTitle("Трактор");
|
||||
setContentPane(ContentPanel);
|
||||
setSize(800, 500);
|
||||
_abstractMap = new SimpleMap();
|
||||
|
||||
// Обработка нажатия кнопки "Создать"
|
||||
buttonCreate.addActionListener(e->{
|
||||
Random rnd = new Random();
|
||||
var _tracktor = new DrawningTracktor(
|
||||
rnd.nextInt(100, 300),
|
||||
rnd.nextInt(1000, 2000),
|
||||
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)),
|
||||
rnd.nextInt(3,8)
|
||||
);
|
||||
setData(_tracktor);
|
||||
});
|
||||
|
||||
// Обработка нажатия кнопки "Модификация"
|
||||
buttonCreateModif.addActionListener(e->{
|
||||
Random rnd = new Random();
|
||||
var _tracktor = new DrawningTrackedVehicle(
|
||||
rnd.nextInt(100, 300),
|
||||
rnd.nextInt(1000, 2000),
|
||||
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)),
|
||||
rnd.nextInt(3,8),
|
||||
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)),
|
||||
rnd.nextBoolean(),
|
||||
rnd.nextBoolean()
|
||||
);
|
||||
setData(_tracktor);
|
||||
});
|
||||
|
||||
buttonUp.addActionListener(e->{
|
||||
if (_abstractMap != null){
|
||||
imageBuffer = _abstractMap.MoveObject(Direction.Up);
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
|
||||
buttonLeft.addActionListener(e->{
|
||||
if (_abstractMap != null){
|
||||
imageBuffer = _abstractMap.MoveObject(Direction.Left);
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
|
||||
buttonDown.addActionListener(e->{
|
||||
if (_abstractMap != null){
|
||||
imageBuffer = _abstractMap.MoveObject(Direction.Down);
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
|
||||
buttonRight.addActionListener(e->{
|
||||
if (_abstractMap != null){
|
||||
imageBuffer = _abstractMap.MoveObject(Direction.Right);
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
|
||||
comboBoxMapSelector.addItemListener(e->{
|
||||
if (e.getStateChange()== ItemEvent.SELECTED){
|
||||
switch (e.getItem().toString()) {
|
||||
case "Простая карта" -> _abstractMap = new SimpleMap();
|
||||
case "Свалка карта" -> _abstractMap = new DumpMap();
|
||||
}
|
||||
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setData(DrawningTracktor _tracktor) {
|
||||
Random rnd = new Random();
|
||||
_tracktor.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100), pictureBox.getWidth(), pictureBox.getHeight());
|
||||
speedLabel.setText("Скорость: " + _tracktor.getTracktor().getSpeed());
|
||||
weightLabel.setText("Вес: " + _tracktor.getTracktor().getWeight());
|
||||
colorLabel.setText("Цвет: " + String.format("%h",_tracktor.getTracktor().getBodyColor()));
|
||||
imageBuffer = _abstractMap.CreateMap(pictureBox.getWidth(), pictureBox.getHeight(), new DrawningObjectExcavator(_tracktor));
|
||||
|
||||
repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g){
|
||||
super.paint(g);
|
||||
Graphics2D g2d = (Graphics2D)pictureBox.getGraphics();
|
||||
if (imageBuffer != null){
|
||||
pictureBox.paintComponents(imageBuffer.getGraphics());
|
||||
g2d.drawImage(imageBuffer,0,0,null);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user