PIbd-23_Nasyrov_A_G_Lab5_hard #5
@ -13,11 +13,26 @@ public class DrawningAirplane {
|
||||
protected int _startPosX;
|
||||
protected int _startPosY;
|
||||
protected IDraw DrawningIlluminators;
|
||||
private int _airplaneWidth = 200;
|
||||
private int _airplaneHeight = 78;
|
||||
public int _airplaneWidth = 200;
|
||||
public int _airplaneHeight = 78;
|
||||
public int _illuminatorsNumb;
|
||||
public EntityAirplane EntityAirplane(){
|
||||
return EntityAirplane;
|
||||
}
|
||||
public void ChangeColor(Color col){
|
||||
EntityAirplane.BodyColor = col;
|
||||
}
|
||||
public void ChangeIDraw(IDraw obj){
|
||||
DrawningIlluminators = obj;
|
||||
obj.ChangeIlluminatorNumb(_illuminatorsNumb);
|
||||
//obj.ChangeWheelsNumb(_wheelNumb);
|
||||
obj.ChangeX(_startPosX);
|
||||
obj.ChangeY(_startPosY);
|
||||
}
|
||||
public void ChangeIlluminatorNumb(int numb){
|
||||
_illuminatorsNumb = numb;
|
||||
DrawningIlluminators.ChangeIlluminatorNumb(numb);
|
||||
}
|
||||
public DrawningAirplane(int speed, double weight, Color bodyColor, int width, int height){
|
||||
if(width <= _airplaneWidth || height <= _airplaneHeight)
|
||||
return;
|
||||
|
@ -11,6 +11,10 @@ public class DrawningAirplaneWithRadar extends DrawningAirplane {
|
||||
EntityAirplane = new EntityAirplaneWithRadar(speed, weight, bodyColor, additionalColor, radar,dopBak);
|
||||
}
|
||||
}
|
||||
public void ChangeAddColor(Color col){
|
||||
((EntityAirplaneWithRadar)EntityAirplane).AdditionalColor = col;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawAirplane(Graphics2D g2d){
|
||||
if(!(EntityAirplane instanceof EntityAirplaneWithRadar)){
|
||||
|
@ -3,7 +3,7 @@ import java.awt.*;
|
||||
public class EntityAirplane {
|
||||
private int Speed;
|
||||
private double Weight, Step;
|
||||
private Color BodyColor;
|
||||
public Color BodyColor;
|
||||
public int Speed(){
|
||||
return Speed;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package src.Entities;
|
||||
import java.awt.*;
|
||||
public class EntityAirplaneWithRadar extends EntityAirplane {
|
||||
private Color AdditionalColor;
|
||||
public Color AdditionalColor;
|
||||
private boolean Radar;
|
||||
private boolean DopBak;
|
||||
public Color AdditionalColor(){return AdditionalColor;}
|
||||
|
@ -20,25 +20,27 @@ public class FormAirplaneCollection {
|
||||
private int pictureBoxWidth = 630;
|
||||
private int pictureBoxHeight = 426;
|
||||
CollectionCanvas canv;
|
||||
void Draw(){
|
||||
if(canv == null)
|
||||
|
||||
void Draw() {
|
||||
if (canv == null)
|
||||
return;
|
||||
canv.repaint();
|
||||
}
|
||||
private void ReloadObjects(){
|
||||
|
||||
private void ReloadObjects() {
|
||||
int index = listBoxStorages.getSelectedIndex();
|
||||
listBoxModel.clear();
|
||||
List<String> keys = _storage.Keys();
|
||||
for(int i = 0; i < keys.size(); i++){
|
||||
for (int i = 0; i < keys.size(); i++) {
|
||||
listBoxModel.addElement(keys.get(i));
|
||||
}
|
||||
if(listBoxModel.size() > 0 && (index == -1 || index >= listBoxModel.size()))
|
||||
if (listBoxModel.size() > 0 && (index == -1 || index >= listBoxModel.size()))
|
||||
listBoxStorages.setSelectedIndex(0);
|
||||
else if(listBoxModel.size() > 0)
|
||||
else if (listBoxModel.size() > 0)
|
||||
listBoxStorages.setSelectedIndex(index);
|
||||
}
|
||||
|
||||
public FormAirplaneCollection(){
|
||||
public FormAirplaneCollection() {
|
||||
AirplaneTrashCollection<DrawningAirplane> _trashCollection = new AirplaneTrashCollection<>();
|
||||
JButton callTrashButton = new JButton("Мусор");
|
||||
_storage = new AirplaneGenericStorage(pictureBoxWidth, pictureBoxHeight);
|
||||
@ -48,20 +50,20 @@ public class FormAirplaneCollection {
|
||||
JTextField storageName = new JTextField();
|
||||
JButton addStorageButton = new JButton("Добавить набор");
|
||||
listBoxModel = new DefaultListModel<>();
|
||||
listBoxStorages= new JList<>(listBoxModel);
|
||||
listBoxStorages = new JList<>(listBoxModel);
|
||||
scrollPane.setViewportView(listBoxStorages);
|
||||
JButton delStorageButton = new JButton("Удалить набор");
|
||||
//toolBox.setBounds(623,12, 227, 80);
|
||||
JFrame collectionFrame = new JFrame();
|
||||
collectionFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||
collectionFrame.setSize(880,497);
|
||||
collectionFrame.setSize(880, 497);
|
||||
toolBox.setBounds(623, 12, 227, 426);
|
||||
canv.setBounds(12,12,pictureBoxWidth,pictureBoxHeight);
|
||||
canv.setBounds(12, 12, pictureBoxWidth, pictureBoxHeight);
|
||||
JButton addButton = new JButton("Добавить");
|
||||
JButton removeButton = new JButton("Удалить");
|
||||
JButton refreshButton = new JButton("Обновить");
|
||||
JTextField airplaneNumb = new JTextField();
|
||||
GridLayout lay = new GridLayout(9,1);
|
||||
GridLayout lay = new GridLayout(9, 1);
|
||||
toolBox.add(storageName);
|
||||
toolBox.add(addStorageButton);
|
||||
toolBox.add(scrollPane);
|
||||
@ -81,7 +83,7 @@ public class FormAirplaneCollection {
|
||||
addStorageButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(storageName.getText() == null)
|
||||
if (storageName.getText() == null)
|
||||
return;
|
||||
_storage.AddSet(storageName.getText());
|
||||
ReloadObjects();
|
||||
@ -91,7 +93,7 @@ public class FormAirplaneCollection {
|
||||
delStorageButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(listBoxStorages.getSelectedIndex() == -1) {
|
||||
if (listBoxStorages.getSelectedIndex() == -1) {
|
||||
return;
|
||||
}
|
||||
_storage.DelSet(listBoxStorages.getSelectedValue());
|
||||
@ -102,7 +104,7 @@ public class FormAirplaneCollection {
|
||||
callTrashButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(_trashCollection.GetSize() == 0)
|
||||
if (_trashCollection.GetSize() == 0)
|
||||
return;
|
||||
FormAirplaneWithRadar form = new FormAirplaneWithRadar();
|
||||
form.ChangeAirplane(_trashCollection.GetTop());
|
||||
@ -113,23 +115,28 @@ public class FormAirplaneCollection {
|
||||
addButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(listBoxStorages.getSelectedIndex() == -1) {
|
||||
if (listBoxStorages.getSelectedIndex() == -1) {
|
||||
return;
|
||||
}
|
||||
AirplaneGenericCollection<DrawningAirplane, DrawningObjectAirplane> _airplanes = _storage.Get(listBoxStorages.getSelectedValue());
|
||||
FormAirplaneWithRadar form = new FormAirplaneWithRadar();
|
||||
form.buttonSelect.addActionListener(new ActionListener() {
|
||||
FormAirplaneConfig form = new FormAirplaneConfig();
|
||||
form.addButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_airplanes.Insert(form.SelectedAirplane()))
|
||||
{
|
||||
if (_airplanes.Insert(form._airplane)) {
|
||||
JOptionPane.showMessageDialog(null, "Объект добавлен", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
||||
Draw();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "Не удалось добавить объект", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
form.AirplaneFrame.dispose();
|
||||
form.frameConfig.dispose();
|
||||
Draw();
|
||||
}
|
||||
});
|
||||
form.cancelButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
form.frameConfig.dispose();
|
||||
Draw();
|
||||
}
|
||||
});
|
||||
@ -138,19 +145,18 @@ public class FormAirplaneCollection {
|
||||
removeButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(listBoxStorages.getSelectedIndex() == -1) {
|
||||
if (listBoxStorages.getSelectedIndex() == -1) {
|
||||
return;
|
||||
}
|
||||
AirplaneGenericCollection<DrawningAirplane, DrawningObjectAirplane> _airplanes = _storage.Get(listBoxStorages.getSelectedValue());
|
||||
if(_airplanes == null) {
|
||||
if (_airplanes == null) {
|
||||
return;
|
||||
}
|
||||
String tmp = airplaneNumb.getText();
|
||||
int numb;
|
||||
try{
|
||||
try {
|
||||
numb = Integer.parseInt(tmp);
|
||||
}
|
||||
catch(Exception ex){
|
||||
} catch (Exception ex) {
|
||||
JOptionPane.showMessageDialog(null, "Введите число", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
||||
return;
|
||||
}
|
||||
@ -166,11 +172,11 @@ public class FormAirplaneCollection {
|
||||
refreshButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(listBoxStorages.getSelectedIndex() == -1) {
|
||||
if (listBoxStorages.getSelectedIndex() == -1) {
|
||||
return;
|
||||
}
|
||||
AirplaneGenericCollection<DrawningAirplane, DrawningObjectAirplane> _airplanes = _storage.Get(listBoxStorages.getSelectedValue());
|
||||
if(_airplanes == null) {
|
||||
if (_airplanes == null) {
|
||||
return;
|
||||
}
|
||||
_airplanes.ShowAirplanes();
|
||||
@ -178,21 +184,24 @@ public class FormAirplaneCollection {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class CollectionCanvas extends JComponent {
|
||||
public AirplaneGenericStorage _storage;
|
||||
public JList<String> listBoxStorages;
|
||||
public CollectionCanvas(){
|
||||
}
|
||||
@Override
|
||||
public void paintComponent (Graphics g){
|
||||
if (listBoxStorages == null || listBoxStorages.getSelectedIndex() == -1){
|
||||
return;
|
||||
|
||||
class CollectionCanvas extends JComponent {
|
||||
public AirplaneGenericStorage _storage;
|
||||
public JList<String> listBoxStorages;
|
||||
|
||||
public CollectionCanvas() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
if (listBoxStorages == null || listBoxStorages.getSelectedIndex() == -1) {
|
||||
return;
|
||||
}
|
||||
super.paintComponents(g);
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
g2d.drawImage(_storage.Get(listBoxStorages.getSelectedValue()).ShowAirplanes(), 0, 0, this);
|
||||
super.repaint();
|
||||
}
|
||||
super.paintComponents (g) ;
|
||||
Graphics2D g2d = (Graphics2D)g;
|
||||
g2d.drawImage(_storage.Get(listBoxStorages.getSelectedValue()).ShowAirplanes(), 0, 0, this);
|
||||
super.repaint();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user