Лабораторная работа 4. Усложненная часть
This commit is contained in:
parent
48e2dfaf6c
commit
41281740e9
@ -24,6 +24,10 @@ public class FormAirFighter extends JFrame implements ComponentListener{
|
||||
public DrawningAirFighter GetSelectedAirFighter(){
|
||||
return SelectedAirFighter;
|
||||
}
|
||||
public void SetAirFighter(DrawningObjectAirFighter AirFighter){
|
||||
_airFighter = AirFighter._airFighter;
|
||||
SetData();
|
||||
}
|
||||
|
||||
// Слушатель кнопки направления
|
||||
private ActionListener actionListenerDirection = new ActionListener() {
|
||||
|
@ -7,8 +7,9 @@ import java.awt.event.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
|
||||
public class FormMapWithSetAirFighters extends JFrame {
|
||||
private JLabel panelForDrawing;
|
||||
@ -18,6 +19,7 @@ public class FormMapWithSetAirFighters extends JFrame {
|
||||
private JButton buttonRight;
|
||||
private JList<String> listStorage;
|
||||
private DefaultListModel<String> listModel;
|
||||
private Queue<DrawningObjectAirFighter> queueDeletedObjects = new LinkedList<DrawningObjectAirFighter>();
|
||||
private final HashMap<String, AbstractMap> _mapDict = new HashMap<String, AbstractMap>() {{
|
||||
put("Простая карта", new SimpleMap());
|
||||
put("Карта шторма", new StormMap());
|
||||
@ -92,12 +94,12 @@ public class FormMapWithSetAirFighters extends JFrame {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (mapComboBox.getSelectedIndex() == -1 || nameStorage.getText().isEmpty() || nameStorage.getText() == null)
|
||||
{
|
||||
JOptionPane.showMessageDialog(panelToolsForMap, "Не все данные заполнены");
|
||||
JOptionPane.showMessageDialog(panelForDrawing, "Не все данные заполнены");
|
||||
return;
|
||||
}
|
||||
if (!_mapDict.keySet().contains(mapComboBox.getSelectedItem().toString()))
|
||||
{
|
||||
JOptionPane.showMessageDialog(panelToolsForMap,"Нет такой карты");
|
||||
JOptionPane.showMessageDialog(panelForDrawing,"Нет такой карты");
|
||||
return;
|
||||
}
|
||||
_mapsCollection.AddMap(nameStorage.getText(),
|
||||
@ -131,7 +133,7 @@ public class FormMapWithSetAirFighters extends JFrame {
|
||||
{
|
||||
return;
|
||||
}
|
||||
int confirm = JOptionPane.showOptionDialog(panelToolsForMap,
|
||||
int confirm = JOptionPane.showOptionDialog(panelForDrawing,
|
||||
String.format("Удалить карту %s", listStorage.getSelectedValue()),
|
||||
"Exit Confirmation", JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.QUESTION_MESSAGE, null, null, null);
|
||||
@ -143,6 +145,29 @@ public class FormMapWithSetAirFighters extends JFrame {
|
||||
}
|
||||
});
|
||||
panelToolsForMap.add(buttonRemoveMap);
|
||||
// Кнопка вызова формы
|
||||
JButton buttonOpenForm = new JButton("Открыть форму");
|
||||
buttonOpenForm.setBounds(0, 250, 160, 30);
|
||||
buttonOpenForm.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
var passedObject = queueDeletedObjects.poll();
|
||||
if(passedObject != null) {
|
||||
FormAirFighter form = new FormAirFighter();
|
||||
form.setSize(500, 500);
|
||||
form.setVisible(true);
|
||||
form.SetAirFighter(passedObject);
|
||||
form.addWindowListener (new WindowAdapter () {
|
||||
public void windowClosing (WindowEvent e) {
|
||||
e.getWindow ().dispose ();
|
||||
}
|
||||
});
|
||||
}else{
|
||||
JOptionPane.showMessageDialog(panelForDrawing, "Очередь пуста");
|
||||
}
|
||||
}
|
||||
});
|
||||
panelToolsForMap.add(buttonOpenForm);
|
||||
// Панель инструментов
|
||||
JPanel panelTools = new JPanel();
|
||||
panelTools.setBounds(800, 300, 200, 400);
|
||||
@ -171,13 +196,13 @@ public class FormMapWithSetAirFighters extends JFrame {
|
||||
JOptionPane.QUESTION_MESSAGE, null, null, null);
|
||||
if (confirm == JOptionPane.YES_OPTION){
|
||||
if(form.GetSelectedAirFighter() == null) {
|
||||
JOptionPane.showMessageDialog(panelTools, "Объект не удалось добавить");
|
||||
JOptionPane.showMessageDialog(panelForDrawing, "Объект не удалось добавить");
|
||||
return;
|
||||
}
|
||||
DrawningObjectAirFighter airFighter = new DrawningObjectAirFighter(form.GetSelectedAirFighter());
|
||||
if (_mapsCollection.get(listStorage.getSelectedValue().toString()).Add(airFighter) == 0)
|
||||
{
|
||||
JOptionPane.showMessageDialog(panelTools, "Объект добавлен");
|
||||
JOptionPane.showMessageDialog(panelForDrawing, "Объект добавлен");
|
||||
panelForDrawing.setIcon(new ImageIcon(_mapsCollection.get(listStorage.getSelectedValue().toString()).ShowSet()));
|
||||
}
|
||||
}
|
||||
@ -222,14 +247,16 @@ public class FormMapWithSetAirFighters extends JFrame {
|
||||
return;
|
||||
}
|
||||
int pos = Integer.parseInt(textFieldIndex.getText());
|
||||
if (_mapsCollection.get(listStorage.getSelectedValue().toString()).Remove(pos) != null) {
|
||||
JOptionPane.showMessageDialog(panelTools, "Объект удален");
|
||||
var deletedObject = _mapsCollection.get(listStorage.getSelectedValue().toString()).Remove(pos);
|
||||
if (deletedObject != null) {
|
||||
JOptionPane.showMessageDialog(panelForDrawing, "Объект удален");
|
||||
panelForDrawing.setIcon(new ImageIcon(_mapsCollection.get(listStorage.getSelectedValue().toString()).ShowSet()));
|
||||
queueDeletedObjects.add(deletedObject);
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(panelTools, "Не удалось удалить объект");
|
||||
JOptionPane.showMessageDialog(panelForDrawing, "Не удалось удалить объект");
|
||||
}
|
||||
}catch (Exception ex){
|
||||
JOptionPane.showMessageDialog(panelTools, "Неккоректный ввод");
|
||||
JOptionPane.showMessageDialog(panelForDrawing, "Неккоректный ввод");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -140,4 +140,7 @@ public class MapWithSetAirFightersGeneric <T extends IDrawningObject, U extends
|
||||
}
|
||||
}
|
||||
}
|
||||
public T GetAirFighterInList(int ind){
|
||||
return _setAirFighters.Get(ind);
|
||||
}
|
||||
}
|
||||
|
@ -40,5 +40,11 @@ public class MapsCollection {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public DrawningObjectAirFighter get(String name, int index){
|
||||
if (_mapStorages.containsKey(name))
|
||||
{
|
||||
return _mapStorages.get(name).GetAirFighterInList(index);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user