готово!!!
This commit is contained in:
parent
facad042be
commit
bcc4a0d32f
@ -74,7 +74,6 @@ public class FormAirbus extends JFrame {
|
|||||||
buttonDown.setIcon(new ImageIcon("images\\KeyDown.png"));
|
buttonDown.setIcon(new ImageIcon("images\\KeyDown.png"));
|
||||||
|
|
||||||
setSize(800,500);
|
setSize(800,500);
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
setLayout(null);
|
setLayout(null);
|
||||||
|
|
||||||
buttonCreateAirbus.setBounds(12, 355, 130, 25);
|
buttonCreateAirbus.setBounds(12, 355, 130, 25);
|
||||||
|
@ -26,9 +26,11 @@ public class FormAirbusCollection extends JFrame {
|
|||||||
// работа с наборами
|
// работа с наборами
|
||||||
private JButton buttonAddStorage;
|
private JButton buttonAddStorage;
|
||||||
private JButton buttonDeleteStorage;
|
private JButton buttonDeleteStorage;
|
||||||
|
private JButton buttonGetDeleted;
|
||||||
private JTextField textFieldStorage;
|
private JTextField textFieldStorage;
|
||||||
private JList<String> listStorage;
|
private JList<String> listStorage;
|
||||||
private DefaultListModel<String> listModel;
|
private DefaultListModel<String> listModel;
|
||||||
|
LinkedList<DrawningAirbus> linkedListDeleted;
|
||||||
|
|
||||||
private JTextField textFieldNumber;
|
private JTextField textFieldNumber;
|
||||||
|
|
||||||
@ -37,8 +39,9 @@ public class FormAirbusCollection extends JFrame {
|
|||||||
FormAirbusCollection() {
|
FormAirbusCollection() {
|
||||||
listModel = new DefaultListModel<String>();
|
listModel = new DefaultListModel<String>();
|
||||||
listStorage = new JList<String>(listModel);
|
listStorage = new JList<String>(listModel);
|
||||||
//_airbus = new AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus> (pictureBoxWidth, pictureBoxHeight);
|
_airbus = new AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus> (pictureBoxWidth, pictureBoxHeight);
|
||||||
_storage = new AirbusGenericStorage(pictureBoxWidth, pictureBoxHeight);
|
_storage = new AirbusGenericStorage(pictureBoxWidth, pictureBoxHeight);
|
||||||
|
linkedListDeleted = new LinkedList<DrawningAirbus>();
|
||||||
canvas = new Canvas();
|
canvas = new Canvas();
|
||||||
|
|
||||||
JFrame frame = new JFrame("Коллекция аэробусов");
|
JFrame frame = new JFrame("Коллекция аэробусов");
|
||||||
@ -53,6 +56,8 @@ public class FormAirbusCollection extends JFrame {
|
|||||||
buttonDeleteAirbus.setMargin(new Insets(0, 0, 0, 0));
|
buttonDeleteAirbus.setMargin(new Insets(0, 0, 0, 0));
|
||||||
buttonUpdate = new JButton("Обновить");
|
buttonUpdate = new JButton("Обновить");
|
||||||
buttonUpdate.setMargin(new Insets(0, 0, 0, 0));
|
buttonUpdate.setMargin(new Insets(0, 0, 0, 0));
|
||||||
|
buttonGetDeleted = new JButton("Загрузить удалёнки");
|
||||||
|
buttonGetDeleted.setMargin(new Insets(0, 0, 0, 0));
|
||||||
buttonGenerateAirbus = new JButton("Форма генерации");
|
buttonGenerateAirbus = new JButton("Форма генерации");
|
||||||
buttonGenerateAirbus.setMargin(new Insets(0,0,0,0));
|
buttonGenerateAirbus.setMargin(new Insets(0,0,0,0));
|
||||||
|
|
||||||
@ -71,7 +76,8 @@ public class FormAirbusCollection extends JFrame {
|
|||||||
textFieldNumber.setBounds(pictureBoxWidth, buttonAddAirbus.getY()+30, 120, 25);
|
textFieldNumber.setBounds(pictureBoxWidth, buttonAddAirbus.getY()+30, 120, 25);
|
||||||
buttonDeleteAirbus.setBounds(pictureBoxWidth, textFieldNumber.getY()+30, 120, 25);
|
buttonDeleteAirbus.setBounds(pictureBoxWidth, textFieldNumber.getY()+30, 120, 25);
|
||||||
buttonUpdate.setBounds(pictureBoxWidth, buttonDeleteAirbus.getY()+30, 120, 25);
|
buttonUpdate.setBounds(pictureBoxWidth, buttonDeleteAirbus.getY()+30, 120, 25);
|
||||||
buttonGenerateAirbus.setBounds(pictureBoxWidth, buttonUpdate.getY()+30, 120, 25);
|
buttonGetDeleted.setBounds(pictureBoxWidth, buttonUpdate.getY()+30, 120, 25);
|
||||||
|
buttonGenerateAirbus.setBounds(pictureBoxWidth, buttonGetDeleted.getY()+30, 120, 25);
|
||||||
canvas.setBounds(0,0,pictureBoxWidth, pictureBoxHeight);
|
canvas.setBounds(0,0,pictureBoxWidth, pictureBoxHeight);
|
||||||
|
|
||||||
add(canvas);
|
add(canvas);
|
||||||
@ -83,12 +89,14 @@ public class FormAirbusCollection extends JFrame {
|
|||||||
add(buttonDeleteAirbus);
|
add(buttonDeleteAirbus);
|
||||||
add(buttonUpdate);
|
add(buttonUpdate);
|
||||||
add(buttonGenerateAirbus);
|
add(buttonGenerateAirbus);
|
||||||
|
add(buttonGetDeleted);
|
||||||
add(textFieldNumber);
|
add(textFieldNumber);
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
|
|
||||||
// логика формы
|
// логика формы
|
||||||
buttonAddStorage.addActionListener(AddStorageListener);
|
buttonAddStorage.addActionListener(AddStorageListener);
|
||||||
buttonDeleteStorage.addActionListener(DeleteStorageListener);
|
buttonDeleteStorage.addActionListener(DeleteStorageListener);
|
||||||
|
buttonGetDeleted.addActionListener(GetDeletedListener);
|
||||||
listStorage.addListSelectionListener(listSelectionListener);
|
listStorage.addListSelectionListener(listSelectionListener);
|
||||||
|
|
||||||
buttonAddAirbus.addActionListener(AddAirbusListener);
|
buttonAddAirbus.addActionListener(AddAirbusListener);
|
||||||
@ -106,9 +114,6 @@ public class FormAirbusCollection extends JFrame {
|
|||||||
{
|
{
|
||||||
listModel.addElement(_storage.Keys().get(i));
|
listModel.addElement(_storage.Keys().get(i));
|
||||||
}
|
}
|
||||||
for (String key : _storage.Keys()) {
|
|
||||||
listModel.addElement(key);
|
|
||||||
}
|
|
||||||
if (listModel.size() > 0 && (index == -1 || index >= listModel.size()))
|
if (listModel.size() > 0 && (index == -1 || index >= listModel.size()))
|
||||||
{
|
{
|
||||||
listStorage.setSelectedIndex(0);
|
listStorage.setSelectedIndex(0);
|
||||||
@ -156,6 +161,23 @@ public class FormAirbusCollection extends JFrame {
|
|||||||
ReloadObject();
|
ReloadObject();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// загрузить удалёнки
|
||||||
|
ActionListener GetDeletedListener = new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (linkedListDeleted.size() == 0)
|
||||||
|
{
|
||||||
|
JOptionPane.showMessageDialog(null, "Нет удалённых аэробусов", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
FormAirbus form = new FormAirbus();
|
||||||
|
form._drawningAirbus = linkedListDeleted.getLast();
|
||||||
|
linkedListDeleted.removeLast();
|
||||||
|
canvas.repaint();
|
||||||
|
}
|
||||||
|
};
|
||||||
// конец секции работы с наборами
|
// конец секции работы с наборами
|
||||||
|
|
||||||
ActionListener OpenGenerationForm = new ActionListener()
|
ActionListener OpenGenerationForm = new ActionListener()
|
||||||
@ -172,18 +194,26 @@ public class FormAirbusCollection extends JFrame {
|
|||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
FormAirbus form = new FormAirbus();
|
|
||||||
|
if (listStorage.getSelectedIndex() == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var obj = _storage.get(listStorage.getSelectedValue());
|
||||||
|
if (obj == null)
|
||||||
|
return;
|
||||||
|
|
||||||
// выбор аэробуса на второй форме
|
// выбор аэробуса на второй форме
|
||||||
|
FormAirbus form = new FormAirbus();
|
||||||
form.buttonSelectAirbus.addActionListener(
|
form.buttonSelectAirbus.addActionListener(
|
||||||
new ActionListener() {
|
new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
|
||||||
DrawningAirbus selectedAirbus = form._drawningAirbus;
|
DrawningAirbus selectedAirbus = form._drawningAirbus;
|
||||||
form.dispose();
|
form.dispose();
|
||||||
if (selectedAirbus != null) {
|
if (selectedAirbus != null) {
|
||||||
if (_airbus.Add(selectedAirbus) != -1) {
|
if (obj.Add(selectedAirbus) != -1) {
|
||||||
JOptionPane.showMessageDialog(null, "Объект добавлен");
|
JOptionPane.showMessageDialog(null, "Объект добавлен");
|
||||||
_airbus.ShowAirbus();
|
|
||||||
canvas.repaint();
|
canvas.repaint();
|
||||||
} else {
|
} else {
|
||||||
JOptionPane.showMessageDialog(null, "Не удалось добавить объект", "Ошибка", JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(null, "Не удалось добавить объект", "Ошибка", JOptionPane.ERROR_MESSAGE);
|
||||||
@ -196,6 +226,7 @@ public class FormAirbusCollection extends JFrame {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// удалить аэробус
|
||||||
ActionListener DeleteAirbusListener = new ActionListener()
|
ActionListener DeleteAirbusListener = new ActionListener()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@ -214,12 +245,20 @@ public class FormAirbusCollection extends JFrame {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
int pos = Integer.parseInt(textFieldStorage.getText());
|
int pos = Integer.parseInt(textFieldNumber.getText());
|
||||||
var deleted = obj.Remove(pos);
|
// запоминаем удалёнку
|
||||||
|
DrawningAirbus deleted = obj.GetT(pos);
|
||||||
|
if (obj.Remove(pos)) {
|
||||||
// добавить в список удалёнок
|
// добавить в список удалёнок
|
||||||
|
linkedListDeleted.add(deleted);
|
||||||
JOptionPane.showMessageDialog(null, "Объект удален", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
JOptionPane.showMessageDialog(null, "Объект удален", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
||||||
canvas.repaint();
|
canvas.repaint();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
JOptionPane.showMessageDialog(null, "Не удалось удалить объект", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
JOptionPane.showMessageDialog(null, "Не удалось удалить объект", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
JOptionPane.showMessageDialog(null, "Не удалось удалить объект", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
||||||
@ -228,21 +267,17 @@ public class FormAirbusCollection extends JFrame {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// обновить
|
||||||
ActionListener UpdateAirbusListener = new ActionListener()
|
ActionListener UpdateAirbusListener = new ActionListener()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
_airbus.ShowAirbus();
|
|
||||||
canvas.repaint();
|
canvas.repaint();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Canvas extends JComponent {
|
class Canvas extends JComponent {
|
||||||
public AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus> airbus;
|
public Canvas() {}
|
||||||
|
|
||||||
public Canvas() {
|
|
||||||
airbus = _airbus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void paintComponent(Graphics g) {
|
public void paintComponent(Graphics g) {
|
||||||
super.paintComponents(g);
|
super.paintComponents(g);
|
||||||
@ -255,8 +290,8 @@ public class FormAirbusCollection extends JFrame {
|
|||||||
if (obj == null)
|
if (obj == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (airbus.ShowAirbus() != null)
|
if (obj.ShowAirbus() != null)
|
||||||
g.drawImage(airbus.ShowAirbus(), 0, 0, this);
|
g.drawImage(obj.ShowAirbus(), 0, 0, this);
|
||||||
|
|
||||||
super.repaint();
|
super.repaint();
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,14 @@ public class AirbusGenericCollection<T extends DrawningAirbus, U extends IMoveab
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// получение объекта DrawningAirbus
|
||||||
|
public T GetT(int pos)
|
||||||
|
{
|
||||||
|
if (_collection.Get(pos) != null)
|
||||||
|
return (T)_collection.GetAirbus().get(pos);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// вывод всего набора
|
// вывод всего набора
|
||||||
public BufferedImage ShowAirbus()
|
public BufferedImage ShowAirbus()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user