Коммит на паре

This commit is contained in:
111 2022-10-25 17:43:59 +04:00
parent 63425cea3d
commit bb46f1fc74
5 changed files with 121 additions and 54 deletions

View File

@ -22,7 +22,7 @@
<border type="none"/>
<children/>
</grid>
<grid id="7c72e" layout-manager="GridLayoutManager" row-count="2" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="7c72e" layout-manager="GridLayoutManager" row-count="2" 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>
<grid row="3" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="true"/>
@ -40,7 +40,7 @@
</component>
<component id="f4d6e" class="javax.swing.JButton" binding="buttonRight">
<constraints>
<grid row="1" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<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"/>
</constraints>
<properties>
<icon value="Right.png"/>
@ -49,7 +49,7 @@
</component>
<component id="12974" class="javax.swing.JButton" binding="buttonUp">
<constraints>
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="0" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<enabled value="true"/>
@ -60,7 +60,7 @@
</component>
<component id="da478" class="javax.swing.JButton" binding="buttonDown">
<constraints>
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="1" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<icon value="Down.png"/>
@ -69,7 +69,7 @@
</component>
<component id="43d8e" class="javax.swing.JButton" binding="buttonLeft">
<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"/>
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<icon value="Left.png"/>
@ -85,6 +85,14 @@
<text value="Модификация"/>
</properties>
</component>
<component id="7c1e4" class="javax.swing.JButton" binding="buttonSelectArmoredCar">
<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>
</children>
</grid>
<component id="2cd31" class="javax.swing.JLabel" binding="labelSpeed">

View File

@ -18,13 +18,16 @@ public class FormArmoredCar extends JFrame{
private JLabel labelWeight;
private JLabel labelColor;
private JButton buttonCreate_Modif;
private JButton buttonSelectArmoredCar;
private DrawingArmoredCar armoredCar;
private DrawingArmoredCar selectedCar;
public boolean DialogResult = false;
public FormArmoredCar() {
super("Бронированная машина");
setBounds(100, 100, 700, 700);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent componentEvent) {
@ -43,8 +46,9 @@ public class FormArmoredCar extends JFrame{
@Override
public void actionPerformed(ActionEvent actionEvent) {
Random rnd = new Random();
armoredCar = new DrawingArmoredCar(rnd.nextInt(100,300), rnd.nextInt(1000, 2000),
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)));
Color newColor = JColorChooser.showDialog(null, "Choose a color", Color.RED);
armoredCar = new DrawingArmoredCar(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
newColor);
setData();
}
@ -93,16 +97,26 @@ public class FormArmoredCar extends JFrame{
@Override
public void actionPerformed(ActionEvent e) {
Random rnd = new Random();
Color newColor = JColorChooser.showDialog(null, "Choose a color", Color.RED);
Color newColorDop = JColorChooser.showDialog(null, "Choose a color", Color.RED);
armoredCar = new DrawingTank(rnd.nextInt(100, 300), rnd.nextInt(1000,
2000),
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0,
256)),
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0,
256)),
1==rnd.nextInt(0, 2), 1==rnd.nextInt(0, 2));
newColor,
newColorDop,
1 == rnd.nextInt(0, 2), 1 == rnd.nextInt(0, 2));
setData();
}
});
buttonSelectArmoredCar.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (armoredCar != null) {
selectedCar = armoredCar;
DialogResult = true;
dispose();
}
}
});
}
private void createUIComponents() {
@ -119,6 +133,10 @@ public class FormArmoredCar extends JFrame{
};
}
public DrawingArmoredCar getSelectedCar() {
return selectedCar;
}
private void setData()
{
Random rnd = new Random();

View File

@ -1,7 +1,6 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.*;
public class FormMapWithArmoredCars extends JFrame{
private JButton buttonAddArmoredCar;
@ -57,25 +56,7 @@ public class FormMapWithArmoredCars extends JFrame{
buttonAddArmoredCar.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (_mapArmoredCarsCollectionGeneric == null)
{
return;
}
FormArmoredCar form = new FormArmoredCar();
JOptionPane.showMessageDialog(null, "Добавление - заглушка");
// if (form.ShowDialog() == DialogResult.OK)
// {
// DrawingObjectArmoredCar armoredCar = new DrawingObjectArmoredCar(form.SelectedCar);
// if (_mapArmoredCarsCollectionGeneric.add(armoredCar) > -1)
// {
// MessageBox.Show("Объект добавлен");
// img = _mapArmoredCarsCollectionGeneric.ShowSet();
// }
// else
// {
// MessageBox.Show("Не удалось добавить объект");
// }
// }
AddArmoredCar();
}
});
buttonRemoveArmoredCar.addActionListener(new ActionListener() {
@ -85,7 +66,7 @@ public class FormMapWithArmoredCars extends JFrame{
{
return;
}
JOptionPane.showMessageDialog(null, "Удаление - заглушка");
JOptionPane.showConfirmDialog (null,"Удаление - заглушка", "Удаление - заглушка", JOptionPane.YES_NO_OPTION);
// if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
// {
// return;
@ -128,6 +109,34 @@ public class FormMapWithArmoredCars extends JFrame{
setContentPane(mainPanel);
setVisible(true);
buttonLeft.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
img = _mapArmoredCarsCollectionGeneric.MoveObject(Direction.Left);
repaint();
}
});
buttonUp.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
img = _mapArmoredCarsCollectionGeneric.MoveObject(Direction.Up);
repaint();
}
});
buttonDown.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
img = _mapArmoredCarsCollectionGeneric.MoveObject(Direction.Down);
repaint();
}
});
buttonRight.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
img = _mapArmoredCarsCollectionGeneric.MoveObject(Direction.Right);
repaint();
}
});
}
private void createUIComponents() {
@ -140,4 +149,29 @@ public class FormMapWithArmoredCars extends JFrame{
}
};
}
private void AddArmoredCar() {
if (_mapArmoredCarsCollectionGeneric == null)
{
return;
}
FormArmoredCar form = new FormArmoredCar();
form.addWindowListener(new WindowAdapter() {
@Override
public void windowDeactivated(WindowEvent e) {
DrawingObjectArmoredCar armoredCar = new DrawingObjectArmoredCar(form.getSelectedCar());
if (_mapArmoredCarsCollectionGeneric.add(armoredCar) > -1)
{
if (form.DialogResult)
JOptionPane.showMessageDialog(null, "Объект добавлен");
img = _mapArmoredCarsCollectionGeneric.ShowSet();
repaint();
}
else
{
JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
}
}
});
}
}

View File

@ -9,7 +9,7 @@ public class MapWithSetArmoredCarsGeneric<T extends IDrawingObject, U extends Ab
private int _placeSizeWidth = 210;
private int _placeSizeHeight = 90;
private int _placeSizeHeight = 110;
private SetArmoredCarsGeneric<T> _setCars;
@ -47,7 +47,7 @@ public class MapWithSetArmoredCarsGeneric<T extends IDrawingObject, U extends Ab
public Image ShowOnMap()
{
Shaking();
for (int i = 0; i < _setCars.Count; i++)
for (int i = 0; i < _setCars.getCount(); i++)
{
var car = _setCars.Get(i);
if (car != null)
@ -69,8 +69,8 @@ public class MapWithSetArmoredCarsGeneric<T extends IDrawingObject, U extends Ab
private void Shaking()
{
int j = _setCars.Count - 1;
for (int i = 0; i < _setCars.Count; i++)
int j = _setCars.getCount() - 1;
for (int i = 0; i < _setCars.getCount(); i++)
{
if (_setCars.Get(i) == null)
{
@ -95,27 +95,35 @@ public class MapWithSetArmoredCarsGeneric<T extends IDrawingObject, U extends Ab
private void DrawBackground(Graphics g)
{
Color colorRoad = Color.GRAY;
Color colorBox = new Color(99, 99, 99);
Color colorBox = new Color(110, 69, 19, 255);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++)
{
g.setColor(colorRoad);
g.fillRect(i * _placeSizeWidth, j * _placeSizeHeight, _placeSizeWidth, _placeSizeHeight);
g.drawLine(i * _placeSizeWidth, j * _placeSizeHeight,
i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
g.setColor(colorBox);
int boxSize = _placeSizeWidth / 7;
g.fillRect(i * _placeSizeWidth + _placeSizeWidth / 2,
j * _placeSizeHeight + _placeSizeHeight / 5, boxSize, boxSize);
g.drawRect(i * _placeSizeWidth + _placeSizeWidth / 2,
j * _placeSizeHeight + _placeSizeHeight / 5, boxSize, boxSize);
g.fillRect(i * _placeSizeWidth + _placeSizeWidth / 2 - boxSize / 2,
j * _placeSizeHeight + _placeSizeHeight / 5 + boxSize, boxSize, boxSize);
g.drawRect( i * _placeSizeWidth + _placeSizeWidth / 2 - boxSize / 2,
j * _placeSizeHeight + _placeSizeHeight / 5 + boxSize, boxSize, boxSize);
g.fillRect(i * _placeSizeWidth + _placeSizeWidth / 2 + boxSize / 2,
j * _placeSizeHeight + _placeSizeHeight / 5 + boxSize, boxSize, boxSize);
g.setColor(Color.BLACK);
g.drawLine(i * _placeSizeWidth, j * _placeSizeHeight,
i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
g.drawRect(i * _placeSizeWidth + _placeSizeWidth / 2,
j * _placeSizeHeight + _placeSizeHeight / 5, boxSize, boxSize);
g.drawRect( i * _placeSizeWidth + _placeSizeWidth / 2 - boxSize / 2,
j * _placeSizeHeight + _placeSizeHeight / 5 + boxSize, boxSize, boxSize);
g.drawRect( i * _placeSizeWidth + _placeSizeWidth / 2 + boxSize / 2,
j * _placeSizeHeight + _placeSizeHeight / 5 + boxSize, boxSize, boxSize);
}
@ -127,7 +135,7 @@ public class MapWithSetArmoredCarsGeneric<T extends IDrawingObject, U extends Ab
private void DrawArmoredCars(Graphics g)
{
int width = _pictureWidth / _placeSizeWidth;
for (int i = 0; i < _setCars.Count; i++)
for (int i = 0; i < _setCars.getCount(); i++)
{
if (_setCars.Get(i) != null) {
_setCars.Get(i).SetObject(i % width * _placeSizeWidth + 5, i / width * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);

View File

@ -3,7 +3,6 @@ import java.util.ArrayList;
public class SetArmoredCarsGeneric<T> {
private T[] _places;
public int Count = getCount();
public SetArmoredCarsGeneric(int count)
{
@ -21,14 +20,14 @@ public class SetArmoredCarsGeneric<T> {
public int Insert(T armoredCar, int position)
{
if (position < 0 || position >= Count)
if (position < 0 || position >= getCount())
return -1;
if (!(_places[position] == null))
{
int index_empty = -1;
// поиск первого пустого элемента
for (int i = position + 1; i < Count; i++)
for (int i = position + 1; i < getCount(); i++)
{
if (_places[i] == null)
{
@ -51,7 +50,7 @@ public class SetArmoredCarsGeneric<T> {
public T Remove(int position)
{
if (position < 0 || position >= Count)
if (position < 0 || position >= getCount())
return null;
T armoredCar = _places[position];
_places[position] = null;
@ -60,7 +59,7 @@ public class SetArmoredCarsGeneric<T> {
public T Get(int position)
{
if (position < 0 || position >= Count)
if (position < 0 || position >= getCount())
return null;
return _places[position];
}