Исправления и добавления функционала
This commit is contained in:
parent
202cf0a590
commit
123fae95d6
@ -41,6 +41,10 @@ public class DrawingArmoredCar {
|
||||
this.carHeight = carHeight;
|
||||
}
|
||||
|
||||
public void SetCaterpillar(IDrawingCaterpillar caterpillar) {
|
||||
this.drawingCaterpillar = caterpillar;
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y, int width, int height) {
|
||||
if (x >= 0 && y >= 0 && x + carWidth < width && y + carHeight < height) {
|
||||
startPosX = x;
|
||||
|
@ -26,7 +26,6 @@ public class FormArmoredCar extends JFrame{
|
||||
public FormArmoredCar() {
|
||||
super("Бронированная машина");
|
||||
setBounds(100, 100, 700, 700);
|
||||
//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
|
||||
addComponentListener(new ComponentAdapter() {
|
||||
|
@ -44,7 +44,7 @@ public class FormMapWithArmoredCars extends JFrame{
|
||||
}
|
||||
if (map != null)
|
||||
{
|
||||
_mapArmoredCarsCollectionGeneric = new MapWithSetArmoredCarsGeneric<DrawingObjectArmoredCar, AbstractMap>(
|
||||
_mapArmoredCarsCollectionGeneric = new MapWithSetArmoredCarsGeneric<>(
|
||||
drawPanel.getWidth(), drawPanel.getHeight(), map);
|
||||
}
|
||||
else
|
||||
@ -56,7 +56,31 @@ public class FormMapWithArmoredCars extends JFrame{
|
||||
buttonAddArmoredCar.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
AddArmoredCar();
|
||||
if (_mapArmoredCarsCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormArmoredCar form = new FormArmoredCar();
|
||||
form.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowDeactivated(WindowEvent e) {
|
||||
if (form.getSelectedCar() == null)
|
||||
return;
|
||||
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, "Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
buttonRemoveArmoredCar.addActionListener(new ActionListener() {
|
||||
@ -66,21 +90,20 @@ public class FormMapWithArmoredCars extends JFrame{
|
||||
{
|
||||
return;
|
||||
}
|
||||
JOptionPane.showConfirmDialog (null,"Удаление - заглушка", "Удаление - заглушка", JOptionPane.YES_NO_OPTION);
|
||||
// if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
// int pos = Integer.parseInt(maskedTextBoxPosition.getText());
|
||||
// if (_mapArmoredCarsCollectionGeneric.remove(pos) != null)
|
||||
// {
|
||||
// MessageBox.Show("Объект удален");
|
||||
// img = _mapArmoredCarsCollectionGeneric.ShowSet();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// MessageBox.Show("Не удалось удалить объект");
|
||||
// }
|
||||
int res = JOptionPane.showConfirmDialog (null,"Удалить объект?",
|
||||
"Удаление", JOptionPane.YES_NO_OPTION);
|
||||
if (res == JOptionPane.YES_OPTION) {
|
||||
int pos = Integer.parseInt(maskedTextBoxPosition.getText());
|
||||
if (_mapArmoredCarsCollectionGeneric.remove(pos) != null)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Объект удален");
|
||||
img = _mapArmoredCarsCollectionGeneric.ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
buttonShowStorage.addActionListener(new ActionListener() {
|
||||
@ -149,29 +172,4 @@ 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, "Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user