Lab3 Java HARD Петрушин Егор ПИбд-22 #3

Closed
Egor_Petrushin wants to merge 5 commits from Lab3 into Lab2
6 changed files with 48 additions and 11 deletions
Showing only changes of commit 20c3c33579 - Show all commits

View File

@ -4,6 +4,8 @@ import java.awt.geom.Path2D;
import SelfPropelledArtilleryUnit.DirectionType;
import SelfPropelledArtilleryUnit.Entities.EntitySPAU;
import SelfPropelledArtilleryUnit.MovementStrategy.DrawningObjectSPAU;
import SelfPropelledArtilleryUnit.MovementStrategy.IMoveableObject;
public class DrawningSPAU {
@ -219,5 +221,10 @@ public class DrawningSPAU {
default:
return false;
}
}
public IMoveableObject GetMoveableObject() {
return new DrawningObjectSPAU(this);
}
}

View File

@ -13,7 +13,6 @@ import SelfPropelledArtilleryUnit.MovementStrategy.Status;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import java.awt.image.BufferedImage;
import java.util.Random;
@ -23,6 +22,7 @@ public class FormSPAU extends JFrame {
private JButton buttonCreate;
private JButton buttonCreateParent;
private JButton buttonStep;
private JButton buttonSelectSPAU;
private JComboBox<String> comboBoxStrategy;
private JComboBox<String> comboBoxRoll;
private JButton buttonUp;
@ -35,6 +35,12 @@ public class FormSPAU extends JFrame {
private JTextField wheelsTextField;
private JLabel wheelsLabel;
private DrawningSPAU SelectedSPAU;
public DrawningSPAU GetSelectedSPAU() {
return SelectedSPAU;
}
public FormSPAU() {
initComponents();
}
@ -104,6 +110,13 @@ public class FormSPAU extends JFrame {
}
});
// ButtonSelectSPAU
buttonSelectSPAU = new JButton("Выбрать");
mainPanel.add(buttonSelectSPAU);
buttonSelectSPAU.setLocation(new Point(759, 90));
buttonSelectSPAU.setBounds(794, 85, 76, 30);
buttonSelectSPAU.addActionListener(e -> buttonSelectSPAU_Click(e));
// comboBoxRoll
comboBoxRoll = new JComboBox<>();
@ -203,6 +216,19 @@ public class FormSPAU extends JFrame {
drawningSPAU.SetPosition(random.nextInt(90) + 20, random.nextInt(90) + 20);
Draw();
}
}
private void buttonSelectSPAU_Click(ActionEvent e) {
SelectedSPAU = drawningSPAU;
//DialogResult = DialogResult.OK;
}
protected void buttonStep_Click (ActionEvent e) {

View File

@ -76,15 +76,17 @@ public class FormSPAUCollection extends JFrame {
private void ButtonAddSPAU_Click(ActionEvent e) {
FormSPAU form = new FormSPAU();
/*
if (form.showDialog() == JOptionPane.OK_OPTION) {
int addedIndex = _SPAUs.add(form.getSelectedSPAU());
int addedIndex = _SPAUs.add(form.GetSelectedSPAU());
if (addedIndex != -1 && addedIndex <= countPlaces) {
JOptionPane.showMessageDialog(this, "Об<EFBFBD><EFBFBD>ект добавлен");
JOptionPane.showMessageDialog(this, "Объект добавлен");
pictureBoxCollection.setIcon(new ImageIcon(_SPAUs.showSPAUs()));
} else {
JOptionPane.showMessageDialog(this, "Не удалось добавить объект");
}
}
*/
}
private void ButtonRemoveSPAU_Click(ActionEvent e) {

View File

@ -3,8 +3,6 @@ package SelfPropelledArtilleryUnit.Generics;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;
import SelfPropelledArtilleryUnit.DrawningObjects.DrawningSPAU;
import SelfPropelledArtilleryUnit.MovementStrategy.IMoveableObject;
@ -15,21 +13,21 @@ public class SPAUGenericCollection<T extends DrawningSPAU, U extends IMoveableOb
private final int _pictureHeight;
private final int _placeSizeWidth = 210;
private final int _placeSizeHeight = 90;
private final List<T> _collection;
private final SetGeneric<T> _collection;
public SPAUGenericCollection(int picWidth, int picHeight) {
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = new ArrayList<>(width * height);
_collection = new SetGeneric<T>(width * height);
}
public boolean add(T obj) {
public int add(T obj) {
if (obj == null) {
return false;
return -1;
}
return _collection.add(obj);
return _collection.insert(obj);
}
public boolean remove(int pos) {

View File

@ -13,6 +13,10 @@ public class SetGeneric<T> {
return insert(spau, 0);
}
public int size(){
return count;
}
public int insert(T spau, int position) {
if (position < 0 || spau == null) {
return -1;

View File

@ -4,7 +4,7 @@ import javax.swing.*;
public class SelfPropelledArtilleryUnit {
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
FormSPAU form = new FormSPAU();
FormSPAUCollection form = new FormSPAUCollection();
form.setSize(900, 500);
form.setVisible(true);
});