2. В форму добавлено меню (нужно подправить поле отрисовки)

This commit is contained in:
prodigygirl 2022-11-20 15:40:45 +04:00
parent e0cb8ba7b4
commit a051a7a3fb
2 changed files with 48 additions and 1 deletions

View File

@ -160,7 +160,7 @@
<grid id="e184c" binding="drawPanel" custom-create="true" 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"/>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>

View File

@ -41,6 +41,19 @@ public class FormMapWithArmoredCars extends JFrame{
setBounds(100, 100, 1000, 700);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JMenuBar jMenuBar = new JMenuBar();
JMenu jMenu = new JMenu("Файл");
JMenuItem itemSave = new JMenuItem("Сохранение");
itemSave.addActionListener(e -> saveActionMenuBar());
JMenuItem itemLoad = new JMenuItem("Загрузка");
itemLoad.addActionListener(e -> loadActionMenuBar());
jMenu.add(itemSave);
jMenu.add(itemLoad);
jMenuBar.add(jMenu);
// поместим меню в наше окно
setJMenuBar(jMenuBar);
//toolBar.add(jMenu);
mapSelectorComboBox.removeAllItems();
for (var elem : _mapsDict.keySet())
{
@ -233,4 +246,38 @@ public class FormMapWithArmoredCars extends JFrame{
JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
}
}
private void saveActionMenuBar() {
FileDialog fd = new FileDialog(this, "Choose a file", FileDialog.LOAD);
fd.setFile("*.txt");
fd.setVisible(true);
String filename = fd.getFile();
if (filename != null) {
if (_mapsCollection.SaveData(fd.getDirectory() + filename))
{
JOptionPane.showMessageDialog(null, "Сохранение прошло успешно");
}
else {
JOptionPane.showMessageDialog(null, "Не сохранилось");
}
}
}
private void loadActionMenuBar() {
FileDialog fd = new FileDialog(this, "Choose a file", FileDialog.LOAD);
fd.setFile("*.txt");
fd.setVisible(true);
String filename = fd.getFile();
if (filename != null) {
if (_mapsCollection.LoadData(fd.getDirectory() + filename))
{
JOptionPane.showMessageDialog(null, "Загрузка прошла успешно");
ReloadMaps();
}
else {
JOptionPane.showMessageDialog(null, "Не загрузилось");
}
}
}
}