2023-11-04 14:33:13 +04:00
|
|
|
|
import javax.swing.*;
|
|
|
|
|
import java.awt.*;
|
|
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
|
import java.awt.event.ActionListener;
|
|
|
|
|
|
|
|
|
|
class CollectionFrame extends JComponent {
|
2023-11-15 14:22:35 +04:00
|
|
|
|
private final CarsGenericCollection<DrawTanker, DrawingObjectTanker> _tanks;
|
|
|
|
|
|
2023-11-04 14:33:13 +04:00
|
|
|
|
protected final int Width;
|
|
|
|
|
protected final int Height;
|
2023-11-15 14:22:35 +04:00
|
|
|
|
public CollectionFrame(int width, int height)
|
2023-11-04 14:33:13 +04:00
|
|
|
|
{
|
|
|
|
|
Width = width;
|
|
|
|
|
Height = height;
|
2023-11-15 14:22:35 +04:00
|
|
|
|
_tanks = new CarsGenericCollection<>(Width, Height);
|
2023-11-04 14:33:13 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void paintComponent(Graphics g) {
|
|
|
|
|
super.paintComponent(g);
|
2023-11-15 14:22:35 +04:00
|
|
|
|
g.drawImage(_tanks.ShowCars(), 0, 0, this);
|
2023-11-04 14:33:13 +04:00
|
|
|
|
super.repaint();
|
|
|
|
|
}
|
|
|
|
|
protected void ButtonAddTank_Click()
|
|
|
|
|
{
|
|
|
|
|
BaseFrame form = new BaseFrame();
|
|
|
|
|
form.setVisible(true);
|
|
|
|
|
form.buttonSelect.addActionListener(
|
|
|
|
|
new ActionListener() {
|
|
|
|
|
public void actionPerformed(ActionEvent e){
|
2023-11-15 14:22:35 +04:00
|
|
|
|
if (_tanks.plus(form.Gasoline.GetSelectedCar()) != -1)
|
2023-11-04 14:33:13 +04:00
|
|
|
|
{
|
|
|
|
|
form.dispose();
|
|
|
|
|
JOptionPane.showMessageDialog(null, "Объект добавлен", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
|
|
|
|
System.out.println("Объект добавлен");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
form.dispose();
|
|
|
|
|
JOptionPane.showMessageDialog(null, "Не удалось добавить объект", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
|
|
|
|
System.out.println("Не удалось добавить объект");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void ButtonRemoveTank_Click(String text)
|
|
|
|
|
{
|
|
|
|
|
if (JOptionPane.showConfirmDialog(null, "Delete Tanker?", "Delete", JOptionPane.YES_NO_OPTION) == JOptionPane.OK_OPTION)
|
|
|
|
|
{
|
2023-11-15 14:22:35 +04:00
|
|
|
|
if (_tanks.minus(Integer.parseInt(text)))
|
2023-11-04 14:33:13 +04:00
|
|
|
|
{
|
|
|
|
|
JOptionPane.showMessageDialog(null, "Объект удален", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
|
|
|
|
super.repaint();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
JOptionPane.showMessageDialog(null, "Не удалось удалить объект", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
super.repaint();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void ButtonUpdate_Click() {super.repaint();}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class GarageFrame extends JFrame {
|
|
|
|
|
public GarageFrame()
|
|
|
|
|
{
|
|
|
|
|
initUI();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected static final int Width = 1000;
|
|
|
|
|
protected static final int Height = 600;
|
|
|
|
|
CollectionFrame Collection;
|
|
|
|
|
private void initUI()
|
|
|
|
|
{
|
|
|
|
|
setSize(Width, Height);
|
|
|
|
|
setTitle("TankGasoline");
|
|
|
|
|
setLocationRelativeTo(null);
|
|
|
|
|
setLayout(null);
|
|
|
|
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
|
|
|
setResizable(false);
|
|
|
|
|
|
|
|
|
|
|
2023-11-15 14:22:35 +04:00
|
|
|
|
JButton addTankerButton = new JButton("Add tanker");
|
2023-11-04 14:33:13 +04:00
|
|
|
|
addTankerButton.setLayout(null);
|
|
|
|
|
addTankerButton.setBounds(Width-200, Height-550, 200, 30);
|
|
|
|
|
add(addTankerButton);
|
|
|
|
|
addTankerButton.addActionListener(new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
|
Collection.ButtonAddTank_Click();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2023-11-15 14:22:35 +04:00
|
|
|
|
JTextField indexTankerField = new JTextField();
|
2023-11-04 14:33:13 +04:00
|
|
|
|
indexTankerField.setBounds(Width- 200, Height-500, 200, 30);
|
|
|
|
|
indexTankerField.setLayout(null);
|
|
|
|
|
add(indexTankerField);
|
|
|
|
|
|
2023-11-15 14:22:35 +04:00
|
|
|
|
JButton deleteTankerButton = new JButton("Delete tanker");
|
2023-11-04 14:33:13 +04:00
|
|
|
|
deleteTankerButton.setLayout(null);
|
|
|
|
|
deleteTankerButton.setBounds(Width-200, Height-450, 200, 30);
|
|
|
|
|
add(deleteTankerButton);
|
|
|
|
|
deleteTankerButton.addActionListener(new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
|
Collection.ButtonRemoveTank_Click(indexTankerField.getText());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2023-11-15 14:22:35 +04:00
|
|
|
|
JButton updateCollectionButton = new JButton("Update collection");
|
2023-11-04 14:33:13 +04:00
|
|
|
|
updateCollectionButton.setLayout(null);
|
|
|
|
|
updateCollectionButton.setBounds(Width-200, Height-400, 200, 30);
|
|
|
|
|
add(updateCollectionButton);
|
|
|
|
|
updateCollectionButton.addActionListener(new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
|
Collection.ButtonUpdate_Click();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2023-11-04 19:58:26 +04:00
|
|
|
|
|
|
|
|
|
|
2023-11-15 14:22:35 +04:00
|
|
|
|
Collection = new CollectionFrame(Width-200, Height);
|
2023-11-04 14:33:13 +04:00
|
|
|
|
Collection.setLayout(null);
|
|
|
|
|
Collection.setBounds(0, 0, Width-200, Height);
|
|
|
|
|
add(Collection);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|