Code almost ready
This commit is contained in:
parent
2895044e8b
commit
f69fe262f8
@ -17,7 +17,7 @@ public class FormElectricLocomotive {
|
||||
public JComboBox comboBoxStrategy;
|
||||
private JButton buttonStep;
|
||||
private JButton buttonCreateLocomotive;
|
||||
private JButton ButtonSelectLocomotive;
|
||||
public JButton ButtonSelectLocomotive;
|
||||
public DrawingLocomotive SelectedLocomotive;
|
||||
public boolean IsSelect = false;
|
||||
|
||||
|
@ -58,7 +58,7 @@
|
||||
<text value="Удалить локо"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="25553" class="javax.swing.JTextField" binding="textField1" default-binding="true">
|
||||
<component id="25553" class="javax.swing.JTextField" binding="textFieldNumber">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
|
@ -3,55 +3,72 @@ package ProjectElectricLocomotive;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class FormLocomotiveCollections extends JFrame {
|
||||
public class FormLocomotiveCollections {
|
||||
private JPanel MainPanel;
|
||||
private JPanel pictureBoxCollections;
|
||||
private JPanel Instruments;
|
||||
private JButton ButtonAddLocomotive;
|
||||
private JTextField textField1;
|
||||
private JTextField textFieldNumber;
|
||||
private JButton ButtonRefreshCollection;
|
||||
private JButton ButtonRemoveLocomotive;
|
||||
public DrawingLocomotive loco;
|
||||
FormElectricLocomotive _formElectricLocomotive;
|
||||
private final LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive> _locomotives;
|
||||
|
||||
public JPanel getPictureBoxCollections() {
|
||||
return MainPanel;
|
||||
}
|
||||
public FormLocomotiveCollections()
|
||||
{
|
||||
_locomotives = new LocomotiveGenericCollection<>(pictureBoxCollections.getWidth(),
|
||||
pictureBoxCollections.getHeight());
|
||||
|
||||
ButtonAddLocomotive.addActionListener(e->{
|
||||
FormElectricLocomotive form = new FormElectricLocomotive();
|
||||
VisFormElectricLocomotive();
|
||||
public FormLocomotiveCollections() {
|
||||
_locomotives = new LocomotiveGenericCollection<>(400, 300);
|
||||
|
||||
if (_locomotives == null) return;
|
||||
|
||||
loco = form._drawingLocomotive;
|
||||
if(loco != null) {
|
||||
//проверяем, удалось ли нам загрузить объект
|
||||
if (_locomotives.AddOverload(loco) != -1 && form.IsSelect == true) {
|
||||
JOptionPane.showMessageDialog(getPictureBoxCollections(), "Объект добавлен");
|
||||
Refresh();
|
||||
//pictureBoxCollections = _locomotives.ShowLocomotives();
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(getPictureBoxCollections(), "Не удалось добавить объект");
|
||||
ButtonAddLocomotive.addActionListener(e -> {
|
||||
FrameElectricLocomotive frameElectricLocomotive = new FrameElectricLocomotive();
|
||||
frameElectricLocomotive.setVisible(true);
|
||||
frameElectricLocomotive._formLocomotiveCollection.ButtonSelectLocomotive.addActionListener(e2 -> {
|
||||
loco = frameElectricLocomotive._formLocomotiveCollection._drawingLocomotive;
|
||||
frameElectricLocomotive.dispose();
|
||||
if (loco != null) {
|
||||
//проверяем, удалось ли нам загрузить объект
|
||||
if (_locomotives.AddOverload(loco) != -1) {
|
||||
JOptionPane.showMessageDialog(getPictureBoxCollections(), "Объект добавлен");
|
||||
Refresh();
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(getPictureBoxCollections(), "Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
ButtonRemoveLocomotive.addActionListener(e->{
|
||||
try {
|
||||
int pos = Integer.parseInt(textFieldNumber.getText());
|
||||
if (_locomotives.SubOverload(pos) != null) {
|
||||
Refresh();
|
||||
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
||||
"Объект удален",
|
||||
"Успех",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
||||
"Не удалось удалить объект",
|
||||
"Ошибка",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
||||
"Неверное значение",
|
||||
"Ошибка",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
});
|
||||
}
|
||||
public void VisFormElectricLocomotive(){
|
||||
setTitle("ElectroLoco");
|
||||
_formElectricLocomotive = new FormElectricLocomotive();
|
||||
setContentPane(_formElectricLocomotive.getPictureBox());
|
||||
setDefaultLookAndFeelDecorated(false);
|
||||
setLocation(200, 500);
|
||||
pack();
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
public void Refresh(){
|
||||
ButtonRefreshCollection.addActionListener(e->{
|
||||
Refresh();
|
||||
});
|
||||
}
|
||||
public void Refresh() {
|
||||
Graphics g = pictureBoxCollections.getGraphics();
|
||||
pictureBoxCollections.paint(g);
|
||||
_locomotives.ShowLocomotives(g);
|
||||
|
18
ProjectElectricLocomotive/FrameElectricLocomotive.java
Normal file
18
ProjectElectricLocomotive/FrameElectricLocomotive.java
Normal file
@ -0,0 +1,18 @@
|
||||
package ProjectElectricLocomotive;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class FrameElectricLocomotive extends JFrame {
|
||||
public FormElectricLocomotive _formLocomotiveCollection;
|
||||
public FrameElectricLocomotive() {
|
||||
super();
|
||||
setTitle("ElectroLoco");
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
_formLocomotiveCollection = new FormElectricLocomotive();
|
||||
setContentPane(_formLocomotiveCollection.getPictureBox());
|
||||
setDefaultLookAndFeelDecorated(false);
|
||||
setLocation(500, 200);
|
||||
pack();
|
||||
setVisible(true);
|
||||
}
|
||||
}
|
18
ProjectElectricLocomotive/FrameLocomotiveCollection.java
Normal file
18
ProjectElectricLocomotive/FrameLocomotiveCollection.java
Normal file
@ -0,0 +1,18 @@
|
||||
package ProjectElectricLocomotive;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class FrameLocomotiveCollection extends JFrame {
|
||||
public FormLocomotiveCollections _formLocomotiveCollections;
|
||||
public FrameLocomotiveCollection(){
|
||||
super();
|
||||
setTitle("LocoCollection");
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
_formLocomotiveCollections = new FormLocomotiveCollections();
|
||||
setContentPane(_formLocomotiveCollections.getPictureBoxCollections());
|
||||
setDefaultLookAndFeelDecorated(false);
|
||||
setLocation(400, 50);
|
||||
pack();
|
||||
setVisible(true);
|
||||
}
|
||||
}
|
@ -8,7 +8,7 @@ public class LocomotiveGenericCollection<T extends DrawingLocomotive,U extends I
|
||||
private final int _pictureWidth;
|
||||
private final int _pictureHeight;
|
||||
//ширина/высота занимаемого места
|
||||
private final int _placeSizeWidth = 85;
|
||||
private final int _placeSizeWidth = 150;
|
||||
private final int _placeSizeHeight = 50;
|
||||
|
||||
/// Набор объектов
|
||||
|
@ -3,6 +3,6 @@ package ProjectElectricLocomotive;
|
||||
public class Main {
|
||||
public static void main(String[] args)
|
||||
{
|
||||
MainFrameElectricLocomotive mainFrameElectricLocomotive = new MainFrameElectricLocomotive();
|
||||
FrameLocomotiveCollection mainFrame = new FrameLocomotiveCollection();
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +0,0 @@
|
||||
package ProjectElectricLocomotive;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class MainFrameElectricLocomotive extends JFrame {
|
||||
private FormElectricLocomotive _formElectricLocomotive;
|
||||
private FormLocomotiveCollections _formLocomotiveCollections;
|
||||
|
||||
public MainFrameElectricLocomotive() {
|
||||
super();
|
||||
setTitle("ElectroLoco");
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
//_formElectricLocomotive = new FormElectricLocomotive();
|
||||
_formLocomotiveCollections = new FormLocomotiveCollections();
|
||||
//setContentPane(_formElectricLocomotive.getPictureBox());
|
||||
setContentPane(_formLocomotiveCollections.getPictureBoxCollections());
|
||||
setDefaultLookAndFeelDecorated(false);
|
||||
setLocation(500, 200);
|
||||
pack();
|
||||
setVisible(true);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user