4 lab not formatted
This commit is contained in:
parent
bbc0734544
commit
d168f11ea6
10
.idea/uiDesigner.xml
generated
10
.idea/uiDesigner.xml
generated
@ -86,11 +86,6 @@
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
@ -99,6 +94,11 @@
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="ProjectElectricLocomotive.FormElectricLocomotive">
|
||||
<grid id="27dc6" binding="pictureBox" layout-manager="GridLayoutManager" row-count="6" column-count="6" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="27dc6" binding="pictureBox" custom-create="true" layout-manager="GridLayoutManager" row-count="6" column-count="6" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="24" y="37" width="663" height="500"/>
|
||||
|
@ -5,11 +5,11 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.Random;
|
||||
|
||||
public class FormElectricLocomotive {
|
||||
public class FormElectricLocomotive extends JDialog{
|
||||
public DrawingLocomotive _drawingLocomotive;
|
||||
AbstractStrategy _abstractStrategy;
|
||||
private JButton buttonCreateElectricLocomotive;
|
||||
private JPanel pictureBox;
|
||||
public JComponent pictureBox;
|
||||
private JButton buttonUp;
|
||||
private JButton buttonDown;
|
||||
private JButton buttonLeft;
|
||||
@ -21,10 +21,27 @@ public class FormElectricLocomotive {
|
||||
public DrawingLocomotive SelectedLocomotive;
|
||||
public boolean IsSelect = false;
|
||||
|
||||
public JPanel getPictureBox()
|
||||
public JComponent getPictureBox()
|
||||
{
|
||||
return pictureBox;
|
||||
}
|
||||
|
||||
private class Canvas extends JPanel{
|
||||
public Canvas(){
|
||||
}
|
||||
public void paintComponent (Graphics g){
|
||||
if (_drawingLocomotive == null){
|
||||
return;
|
||||
}
|
||||
|
||||
Graphics2D g2d = (Graphics2D)g;
|
||||
g2d.setColor(getBackground());
|
||||
g2d.fillRect(0, 0, getWidth(), getHeight());
|
||||
super.paintComponents(g);
|
||||
_drawingLocomotive.DrawTransport(g2d);
|
||||
super.repaint();
|
||||
}
|
||||
}
|
||||
public FormElectricLocomotive()
|
||||
{
|
||||
buttonUp.setName("buttonUp");
|
||||
@ -34,11 +51,18 @@ public class FormElectricLocomotive {
|
||||
|
||||
buttonCreateLocomotive.addActionListener(e -> {
|
||||
Random rnd = new Random();
|
||||
Color color = JColorChooser.showDialog(null, "Цвет", null);
|
||||
_drawingLocomotive = new DrawingLocomotive(rnd.nextInt(100, 300),
|
||||
rnd.nextInt(1000, 3000), color,
|
||||
Color color = JColorChooser.showDialog(
|
||||
null,
|
||||
"Цвет",
|
||||
null
|
||||
);
|
||||
_drawingLocomotive = new DrawingLocomotive(
|
||||
rnd.nextInt(100, 300),
|
||||
rnd.nextInt(1000, 3000),
|
||||
color,
|
||||
pictureBox.getWidth(),
|
||||
pictureBox.getHeight());
|
||||
pictureBox.getHeight()
|
||||
);
|
||||
|
||||
_drawingLocomotive.SetWheelsCount(rnd.nextInt(2, 5));
|
||||
_drawingLocomotive.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100));
|
||||
@ -93,9 +117,10 @@ public class FormElectricLocomotive {
|
||||
if (_abstractStrategy == null) {
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData(new
|
||||
DrawingObjectLocomotive(_drawingLocomotive), pictureBox.getWidth(),
|
||||
pictureBox.getHeight());
|
||||
_abstractStrategy.SetData(
|
||||
new DrawingObjectLocomotive(_drawingLocomotive), pictureBox.getWidth(),
|
||||
pictureBox.getHeight()
|
||||
);
|
||||
comboBoxStrategy.setEnabled(false);
|
||||
}
|
||||
if (_abstractStrategy == null) {
|
||||
@ -136,11 +161,11 @@ public class FormElectricLocomotive {
|
||||
buttonRight.addActionListener(buttonMoveClickedListener);
|
||||
}
|
||||
public void Draw() {
|
||||
if (_drawingLocomotive.EntityLocomotive == null) {
|
||||
return;
|
||||
}
|
||||
Graphics g = pictureBox.getGraphics();
|
||||
pictureBox.paint(g);
|
||||
_drawingLocomotive.DrawTransport(g);
|
||||
pictureBox.repaint();
|
||||
}
|
||||
|
||||
private void createUIComponents(){
|
||||
pictureBox = new Canvas();
|
||||
pictureBox.setBounds(new Rectangle(400, 300));
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import java.util.Stack;
|
||||
//готовая лаба 3
|
||||
|
||||
public class FormLocomotiveCollections {
|
||||
FormElectricLocomotive formElectricLocomotive;
|
||||
private JPanel MainPanel;
|
||||
private JPanel pictureBoxCollections;
|
||||
private JPanel Instruments;
|
||||
@ -24,19 +25,16 @@ public class FormLocomotiveCollections {
|
||||
public DrawingLocomotive loco;
|
||||
final LocomotivesGenericStorage _storage;
|
||||
FrameElectricLocomotive _frameRemovedLocomotives;
|
||||
|
||||
private Stack<DrawingLocomotive> stackRemoveObjects;
|
||||
private Stack<DrawingLocomotive> _stackRemoveObjects;
|
||||
FrameDopClassParameters frameDopClassParameters;
|
||||
// LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive> _locomotives;
|
||||
public JPanel getPictureBoxCollections() {
|
||||
return MainPanel;
|
||||
}
|
||||
|
||||
|
||||
public FormLocomotiveCollections() {
|
||||
//_locomotives = new LocomotiveGenericCollection<>(400, 300);
|
||||
_storage = new LocomotivesGenericStorage(/*pictureBoxCollections.getWidth(), pictureBoxCollections.getHeight()*/400,300);
|
||||
stackRemoveObjects = new Stack<>();
|
||||
formElectricLocomotive = new FormElectricLocomotive();
|
||||
_storage = new LocomotivesGenericStorage(400,300);
|
||||
_stackRemoveObjects = new Stack<>();
|
||||
listBoxStorage.addListSelectionListener(this::listBoxObjectsSelectedIndexChanged);
|
||||
|
||||
ButtonAddObject.addActionListener(e ->
|
||||
@ -95,40 +93,6 @@ public class FormLocomotiveCollections {
|
||||
});
|
||||
|
||||
ButtonRemoveLocomotive.addActionListener(e -> {
|
||||
/*if (listBoxStorage.getSelectedIndex() == -1) {
|
||||
return;
|
||||
}
|
||||
var obj = _storage.get(listBoxStorage.getSelectedValue().toString());
|
||||
if (obj == null) {
|
||||
return;
|
||||
}
|
||||
int pos = 0;
|
||||
try {
|
||||
pos = Integer.parseInt(textFieldNumber.getText());
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
||||
"Неверное значение",
|
||||
"Ошибка",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
DrawingLocomotive deletedLoco = obj.SubOverload(pos);
|
||||
if (deletedLoco != null) {
|
||||
// logic for push deleted loco in stack
|
||||
stackRemoveObjects.push(deletedLoco);
|
||||
Refresh();
|
||||
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
||||
"Объект удален",
|
||||
"Успех",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
||||
"Не удалось удалить объект",
|
||||
"Ошибка",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}*/
|
||||
|
||||
if (listBoxStorage.getSelectedIndex() == -1) {
|
||||
return;
|
||||
}
|
||||
@ -161,19 +125,19 @@ public class FormLocomotiveCollections {
|
||||
}
|
||||
DrawingLocomotive removedPlane = obj.SubOverload(pos);
|
||||
if (removedPlane != null) {
|
||||
stackRemoveObjects.push(removedPlane);
|
||||
_stackRemoveObjects.push(removedPlane);
|
||||
Refresh();
|
||||
|
||||
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
||||
"Объект удален",
|
||||
"Успех",
|
||||
JOptionPane.INFORMATION_MESSAGE);Refresh();
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
||||
"Не удалось удалить объект",
|
||||
"Ошибка",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
ButtonRefreshCollection.addActionListener(e -> {
|
||||
@ -181,7 +145,7 @@ public class FormLocomotiveCollections {
|
||||
});
|
||||
|
||||
Button_OpenFormRemovedLocomotives.addActionListener(e -> {
|
||||
if(stackRemoveObjects.empty()) {
|
||||
if(_stackRemoveObjects.empty()) {
|
||||
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
||||
"Вы ничего не удалили, кажется...",
|
||||
"ой",
|
||||
@ -189,10 +153,9 @@ public class FormLocomotiveCollections {
|
||||
return;
|
||||
}
|
||||
_frameRemovedLocomotives = new FrameElectricLocomotive();
|
||||
_frameRemovedLocomotives._formElectricLocomotive._drawingLocomotive = stackRemoveObjects.pop();
|
||||
_frameRemovedLocomotives._formElectricLocomotive._drawingLocomotive = _stackRemoveObjects.pop();
|
||||
_frameRemovedLocomotives.setVisible(true);
|
||||
_frameRemovedLocomotives._formElectricLocomotive.Draw();
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
package ProjectElectricLocomotive;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
public class SetGeneric<T extends DrawingLocomotive>{
|
||||
private ArrayList<T> _places;
|
||||
@ -17,7 +15,7 @@ public class SetGeneric<T extends DrawingLocomotive>{
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
maxCount = count;
|
||||
_places = new ArrayList<T>(count);
|
||||
_places = new ArrayList<>(count);
|
||||
}
|
||||
|
||||
public int Insert(T loco)
|
||||
@ -27,7 +25,7 @@ public class SetGeneric<T extends DrawingLocomotive>{
|
||||
|
||||
public int Insert(T loco, int position)
|
||||
{
|
||||
if(position < 0 || position > Count())
|
||||
if(position < 0 || position > maxCount)
|
||||
return -1;
|
||||
else
|
||||
{
|
||||
@ -43,7 +41,6 @@ public class SetGeneric<T extends DrawingLocomotive>{
|
||||
else
|
||||
{
|
||||
T plane = _places.get(position);
|
||||
_places.remove(position);
|
||||
_places.set(position, null);
|
||||
return plane;
|
||||
}
|
||||
@ -69,35 +66,4 @@ public class SetGeneric<T extends DrawingLocomotive>{
|
||||
return _places;
|
||||
}
|
||||
|
||||
/* public Iterable<T> GetLocomotives(final Integer maxLocomotives) {
|
||||
return new Iterable<T>() {
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return new Iterator<T>() {
|
||||
private int currentIndex = 0;
|
||||
private int count = 0;
|
||||
|
||||
//есть ли в коллекции еще место (значения)
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return currentIndex < _places.size() &&
|
||||
(maxLocomotives == null || count < maxLocomotives);
|
||||
}
|
||||
|
||||
//ну и, соответственно, переходим к следующему, если хэз некст == true
|
||||
@Override
|
||||
public T next() {
|
||||
if (hasNext()) {
|
||||
count++;
|
||||
return _places.get(currentIndex++);
|
||||
}
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
};
|
||||
}
|
||||
};*/
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user