Лабораторная работа №5 (что-то работает)
This commit is contained in:
parent
ed5df725c2
commit
fcb6bf6d11
@ -100,7 +100,7 @@
|
|||||||
<text value="Создать компанию"/>
|
<text value="Создать компанию"/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
<grid id="ceabb" binding="panelCompanyTools" layout-manager="GridLayoutManager" row-count="9" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
<grid id="ceabb" binding="panelCompanyTools" layout-manager="GridLayoutManager" row-count="8" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
@ -118,17 +118,9 @@
|
|||||||
<text value="Добавление грузовика"/>
|
<text value="Добавление грузовика"/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
<component id="112e" class="javax.swing.JButton" binding="buttonAddCleaningCar">
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Добавление уборочной машины"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="8fa47" class="javax.swing.JFormattedTextField" binding="maskedTextBox">
|
<component id="8fa47" class="javax.swing.JFormattedTextField" binding="maskedTextBox">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
<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="50" height="-1"/>
|
<preferred-size width="50" height="-1"/>
|
||||||
</grid>
|
</grid>
|
||||||
</constraints>
|
</constraints>
|
||||||
@ -136,7 +128,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="af87b" class="javax.swing.JButton" binding="buttonDel">
|
<component id="af87b" class="javax.swing.JButton" binding="buttonDel">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<text value="Удалить грузовик"/>
|
<text value="Удалить грузовик"/>
|
||||||
@ -144,7 +136,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="7c328" class="javax.swing.JButton" binding="buttonGoToCheck">
|
<component id="7c328" class="javax.swing.JButton" binding="buttonGoToCheck">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<text value="Передать на тесты"/>
|
<text value="Передать на тесты"/>
|
||||||
@ -152,7 +144,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="44aef" class="javax.swing.JButton" binding="buttonRefresh">
|
<component id="44aef" class="javax.swing.JButton" binding="buttonRefresh">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<text value="Обновить"/>
|
<text value="Обновить"/>
|
||||||
@ -160,7 +152,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="5f2f8" class="javax.swing.JButton" binding="buttonAdditionalCollection">
|
<component id="5f2f8" class="javax.swing.JButton" binding="buttonAdditionalCollection">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<text value="Дополнительная коллекция"/>
|
<text value="Дополнительная коллекция"/>
|
||||||
@ -168,7 +160,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="b5aef" class="javax.swing.JButton" binding="buttonResurrected">
|
<component id="b5aef" class="javax.swing.JButton" binding="buttonResurrected">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="8" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<text value="Из удалённых"/>
|
<text value="Из удалённых"/>
|
||||||
@ -176,7 +168,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="bf6d" class="javax.swing.JButton" binding="buttonIndex">
|
<component id="bf6d" class="javax.swing.JButton" binding="buttonIndex">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<text value="Удалить через индексатор"/>
|
<text value="Удалить через индексатор"/>
|
||||||
|
@ -7,6 +7,7 @@ import javax.swing.text.MaskFormatter;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
@ -23,7 +24,6 @@ public class FormCleaningCarCollection extends JFrame{
|
|||||||
private JPanel tools;
|
private JPanel tools;
|
||||||
private JComboBox comboBoxSelectorCompany;
|
private JComboBox comboBoxSelectorCompany;
|
||||||
private JButton buttonAddTruck;
|
private JButton buttonAddTruck;
|
||||||
private JButton buttonAddCleaningCar;
|
|
||||||
private JPanel pictureBox;
|
private JPanel pictureBox;
|
||||||
private JFormattedTextField maskedTextBox;
|
private JFormattedTextField maskedTextBox;
|
||||||
private JButton buttonDel;
|
private JButton buttonDel;
|
||||||
@ -60,7 +60,6 @@ public class FormCleaningCarCollection extends JFrame{
|
|||||||
try {
|
try {
|
||||||
maskFormatter = new MaskFormatter("##");
|
maskFormatter = new MaskFormatter("##");
|
||||||
maskFormatter.setPlaceholder("00");
|
maskFormatter.setPlaceholder("00");
|
||||||
//это intellij
|
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@ -86,9 +85,13 @@ public class FormCleaningCarCollection extends JFrame{
|
|||||||
});
|
});
|
||||||
|
|
||||||
//ButtonAddTruck_Click
|
//ButtonAddTruck_Click
|
||||||
buttonAddTruck.addActionListener(e -> CreateObject("DrawningTruck"));
|
buttonAddTruck.addActionListener(e -> {
|
||||||
//ButtonAddCleaningCar_Click
|
//CreateObject("DrawningTruck");
|
||||||
buttonAddCleaningCar.addActionListener(e -> CreateObject("DrawningCleaningCar"));
|
FormTruckConfig form = new FormTruckConfig();
|
||||||
|
form.Init();
|
||||||
|
form.setVisible(true);
|
||||||
|
form.SetCompany(_company);
|
||||||
|
});
|
||||||
//ButtonDelTruck_Click
|
//ButtonDelTruck_Click
|
||||||
buttonDel.addActionListener(new ActionListener() {
|
buttonDel.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -298,6 +301,4 @@ public class FormCleaningCarCollection extends JFrame{
|
|||||||
_company.Show(e);
|
_company.Show(e);
|
||||||
}
|
}
|
||||||
public static void Show() {for (Frame i : Frame.getFrames()) {if (!i.isActive()) {i.repaint();}}}
|
public static void Show() {for (Frame i : Frame.getFrames()) {if (!i.isActive()) {i.repaint();}}}
|
||||||
// Method method = Component.class.getSuperclass().getDeclaredMethod("repaint");
|
|
||||||
// method.setAccessible(true);
|
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import CollectionGenericObjects.AbstractCompany;
|
||||||
import Drawnings.DrawningCleaningCar;
|
import Drawnings.DrawningCleaningCar;
|
||||||
import Drawnings.DrawningTruck;
|
import Drawnings.DrawningTruck;
|
||||||
import Drawnings.IDrawningWheels;
|
import Drawnings.IDrawningWheels;
|
||||||
@ -10,14 +11,19 @@ import java.awt.datatransfer.DataFlavor;
|
|||||||
import java.awt.datatransfer.StringSelection;
|
import java.awt.datatransfer.StringSelection;
|
||||||
import java.awt.datatransfer.Transferable;
|
import java.awt.datatransfer.Transferable;
|
||||||
import java.awt.datatransfer.UnsupportedFlavorException;
|
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||||
import java.awt.dnd.*;
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class FormTruckConfig extends JFrame {
|
public class FormTruckConfig extends JFrame {
|
||||||
private DrawningTruck _truck;
|
private DrawningTruck _truck;
|
||||||
|
private AbstractCompany _company;
|
||||||
private JPanel panel;
|
private JPanel panel;
|
||||||
private JPanel GroupBoxConfig;
|
private JPanel GroupBoxConfig;
|
||||||
private JLabel labelSimpleObject;
|
private JLabel labelSimpleObject;
|
||||||
@ -49,13 +55,12 @@ public class FormTruckConfig extends JFrame {
|
|||||||
setTitle("Создание объекта");
|
setTitle("Создание объекта");
|
||||||
add(panel);
|
add(panel);
|
||||||
setMinimumSize(new Dimension(900, 300));
|
setMinimumSize(new Dimension(900, 300));
|
||||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
//setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||||
setLocationRelativeTo(null);
|
setLocationRelativeTo(null);
|
||||||
|
|
||||||
buttonCancel.addActionListener(e -> this.dispose());
|
buttonCancel.addActionListener(e -> this.dispose());
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
Cursor cursor = Cursor.getDefaultCursor();
|
|
||||||
protected void Init() {
|
protected void Init() {
|
||||||
labelSimpleObject.setBorder(new LineBorder(Color.BLACK));
|
labelSimpleObject.setBorder(new LineBorder(Color.BLACK));
|
||||||
labelModifiedObject.setBorder(new LineBorder(Color.BLACK));
|
labelModifiedObject.setBorder(new LineBorder(Color.BLACK));
|
||||||
@ -64,13 +69,13 @@ public class FormTruckConfig extends JFrame {
|
|||||||
labelBodyColor.setBorder(new LineBorder(Color.BLACK));
|
labelBodyColor.setBorder(new LineBorder(Color.BLACK));
|
||||||
labelAdditionalColor.setBorder(new LineBorder(Color.BLACK));
|
labelAdditionalColor.setBorder(new LineBorder(Color.BLACK));
|
||||||
|
|
||||||
var labelObjectsMouseDown = new MouseAdapter() {
|
MouseAdapter labelObjectsMouseDown = new MouseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void mousePressed(MouseEvent e) {
|
public void mousePressed(MouseEvent e) {
|
||||||
((JLabel) e.getComponent()).getTransferHandler().exportAsDrag(((JLabel) e.getComponent()), e, TransferHandler.COPY);
|
((JLabel) e.getComponent()).getTransferHandler().exportAsDrag(((JLabel) e.getComponent()), e, TransferHandler.COPY);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var labelObjectsTransferHandler = new TransferHandler() {
|
TransferHandler labelObjectsTransferHandler = new TransferHandler() {
|
||||||
@Override
|
@Override
|
||||||
public int getSourceActions(JComponent c) {
|
public int getSourceActions(JComponent c) {
|
||||||
return TransferHandler.COPY;
|
return TransferHandler.COPY;
|
||||||
@ -99,7 +104,7 @@ public class FormTruckConfig extends JFrame {
|
|||||||
switch (data) {
|
switch (data) {
|
||||||
case "Простой":
|
case "Простой":
|
||||||
_truck = new DrawningTruck((int) spinnerSpeed.getValue(), (int) spinnerWeight.getValue(),
|
_truck = new DrawningTruck((int) spinnerSpeed.getValue(), (int) spinnerWeight.getValue(),
|
||||||
Color.BLUE);
|
Color.WHITE);
|
||||||
System.out.println("a");
|
System.out.println("a");
|
||||||
break;
|
break;
|
||||||
case "Продвинутый":
|
case "Продвинутый":
|
||||||
@ -124,7 +129,7 @@ public class FormTruckConfig extends JFrame {
|
|||||||
|
|
||||||
|
|
||||||
ArrayList<JPanel> colorList = new ArrayList<>();
|
ArrayList<JPanel> colorList = new ArrayList<>();
|
||||||
colorList.add(panelObject); colorList.add(panelWhite);colorList.add(panelBlack);
|
colorList.add(panelWhite);colorList.add(panelBlack);
|
||||||
colorList.add(panelPurple); colorList.add(panelBlue); colorList.add(panelGreen);
|
colorList.add(panelPurple); colorList.add(panelBlue); colorList.add(panelGreen);
|
||||||
colorList.add(panelGray); colorList.add(panelRed); colorList.add(panelYellow);
|
colorList.add(panelGray); colorList.add(panelRed); colorList.add(panelYellow);
|
||||||
|
|
||||||
@ -134,10 +139,20 @@ public class FormTruckConfig extends JFrame {
|
|||||||
((JPanel) e.getComponent()).getTransferHandler().exportAsDrag(((JPanel) e.getComponent()), e, TransferHandler.COPY);
|
((JPanel) e.getComponent()).getTransferHandler().exportAsDrag(((JPanel) e.getComponent()), e, TransferHandler.COPY);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
TransferHandler colorTransferHandler = new TransferHandler() {
|
||||||
|
@Override
|
||||||
|
public int getSourceActions(JComponent c) {
|
||||||
|
return TransferHandler.COPY;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected Transferable createTransferable(JComponent c) {
|
||||||
|
return new ColorTransferable(((JPanel)c).getBackground());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
for (JPanel color : colorList) {
|
for (JPanel color : colorList) {
|
||||||
color.addMouseListener(colorMouseDown);
|
color.addMouseListener(colorMouseDown);
|
||||||
color.setTransferHandler(new ColorTransferHandler());
|
color.setTransferHandler(colorTransferHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
labelBodyColor.setTransferHandler(new TransferHandler() {
|
labelBodyColor.setTransferHandler(new TransferHandler() {
|
||||||
@ -151,6 +166,7 @@ public class FormTruckConfig extends JFrame {
|
|||||||
Color color = (Color) support.getTransferable().getTransferData(ColorTransferable.colorDataFlavor);
|
Color color = (Color) support.getTransferable().getTransferData(ColorTransferable.colorDataFlavor);
|
||||||
if (_truck == null) return false;
|
if (_truck == null) return false;
|
||||||
_truck.EntityTruck.setBodyColor(color);
|
_truck.EntityTruck.setBodyColor(color);
|
||||||
|
repaint();
|
||||||
return true;
|
return true;
|
||||||
} catch (UnsupportedFlavorException | IOException e) {
|
} catch (UnsupportedFlavorException | IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -172,7 +188,7 @@ public class FormTruckConfig extends JFrame {
|
|||||||
if (_truck == null) return false;
|
if (_truck == null) return false;
|
||||||
if (_truck.EntityTruck instanceof EntityCleaningCar cleaningCar) {
|
if (_truck.EntityTruck instanceof EntityCleaningCar cleaningCar) {
|
||||||
cleaningCar.setAdditionalColor(color);
|
cleaningCar.setAdditionalColor(color);
|
||||||
//labelColor.setBackground(color);
|
repaint();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -183,6 +199,32 @@ public class FormTruckConfig extends JFrame {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
buttonAdd.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (_company == null || _truck == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DrawningTruck truck;
|
||||||
|
if (_truck instanceof DrawningCleaningCar) {
|
||||||
|
truck = new DrawningCleaningCar((EntityCleaningCar) _truck.EntityTruck, _truck.drawningWheels);
|
||||||
|
} else {
|
||||||
|
truck = new DrawningTruck(_truck.getEntityTruck(), _truck.drawningWheels);
|
||||||
|
}
|
||||||
|
if (_company._collection.Insert(truck, 0) != -1) {
|
||||||
|
dispose();
|
||||||
|
FormCleaningCarCollection.Show();
|
||||||
|
JOptionPane.showMessageDialog(null, "Объект добавлен");
|
||||||
|
//_company = null;
|
||||||
|
} else {
|
||||||
|
JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
public void SetCompany(AbstractCompany company) {
|
||||||
|
_company = company;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void paint(Graphics g) {
|
public void paint(Graphics g) {
|
||||||
@ -192,7 +234,6 @@ public class FormTruckConfig extends JFrame {
|
|||||||
e.setColor(panelObject.getBackground());
|
e.setColor(panelObject.getBackground());
|
||||||
e.fillRect(0,0, panelObject.getWidth(), panelObject.getHeight());
|
e.fillRect(0,0, panelObject.getWidth(), panelObject.getHeight());
|
||||||
_truck.DrawTransport(e);
|
_truck.DrawTransport(e);
|
||||||
System.out.println(_truck.GetPosX());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ColorTransferable implements Transferable {
|
private class ColorTransferable implements Transferable {
|
||||||
@ -218,14 +259,4 @@ public class FormTruckConfig extends JFrame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private class ColorTransferHandler extends TransferHandler {
|
|
||||||
@Override
|
|
||||||
public int getSourceActions(JComponent c) {
|
|
||||||
return TransferHandler.COPY;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
protected Transferable createTransferable(JComponent c) {
|
|
||||||
return new ColorTransferable(c.getBackground());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
class Main {
|
class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
//FormCleaningCarCollection form = new FormCleaningCarCollection();
|
FormCleaningCarCollection form = new FormCleaningCarCollection();
|
||||||
//form.setVisible(true);
|
form.setVisible(true);
|
||||||
FormTruckConfig config = new FormTruckConfig();
|
// FormTruckConfig config = new FormTruckConfig();
|
||||||
config.setVisible(true);
|
// config.setVisible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user