clear
This commit is contained in:
parent
c968474e79
commit
55025611d1
BIN
.vs/slnx.sqlite
BIN
.vs/slnx.sqlite
Binary file not shown.
@ -39,7 +39,7 @@ public class DrawingArmoredVehicle{
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
private IDrawingRoller roller;
|
||||
protected IDrawingRoller roller;
|
||||
|
||||
Random rnd = new Random();
|
||||
public int Count;
|
||||
@ -74,6 +74,13 @@ public class DrawingArmoredVehicle{
|
||||
_ArmoredVehicleHeight = ArmoredVehicleHeight + 50;
|
||||
_ArmoredVehicleWidth = ArmoredVehicleWidth + 150;
|
||||
}
|
||||
|
||||
public DrawingArmoredVehicle(ArmoredVehicleEntity machine, IDrawingRoller rollers)
|
||||
{
|
||||
ArmoredVehicle = machine;
|
||||
roller = rollers;
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
|
@ -9,7 +9,14 @@ public class DrawingTank extends DrawingArmoredVehicle{
|
||||
ArmoredVehicle = new TankEntity(speed, weight, bodyColor, dopColor, machineGun, tower);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public DrawingTank(ArmoredVehicleEntity tank, IDrawingRoller roll)
|
||||
{
|
||||
super(tank, roll);
|
||||
ArmoredVehicle = (TankEntity)tank;
|
||||
roller = roll;
|
||||
}
|
||||
@Override
|
||||
public void DrawTransport(Graphics2D g)
|
||||
{
|
||||
if (!"TankEntity".equals(ArmoredVehicle.getClass().getName()))
|
||||
|
@ -82,7 +82,7 @@
|
||||
<Component id="MapComboBox" pref="165" max="32767" attributes="0"/>
|
||||
<Component id="AddMachineButton" max="32767" attributes="0"/>
|
||||
<Component id="TextBoxPosition" alignment="0" max="32767" attributes="0"/>
|
||||
<Component id="button1" alignment="0" max="32767" attributes="0"/>
|
||||
<Component id="DeleteButton" alignment="0" max="32767" attributes="0"/>
|
||||
<Component id="StoreButton" alignment="0" max="32767" attributes="0"/>
|
||||
<Component id="MapButton" alignment="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
@ -121,7 +121,7 @@
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="TextBoxPosition" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="button1" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="DeleteButton" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="StoreButton" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
@ -182,13 +182,13 @@
|
||||
<Property name="name" type="java.lang.String" value="TextBoxPosition" noResource="true"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="java.awt.Button" name="button1">
|
||||
<Component class="java.awt.Button" name="DeleteButton">
|
||||
<Properties>
|
||||
<Property name="label" type="java.lang.String" value="Удалить машину"/>
|
||||
<Property name="name" type="java.lang.String" value="DeleteMachineButton" noResource="true"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="button1MouseClicked"/>
|
||||
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="DeleteButtonMouseClicked"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="java.awt.Button" name="StoreButton">
|
||||
|
@ -29,7 +29,7 @@ private Image img;
|
||||
MapComboBox = new javax.swing.JComboBox<>();
|
||||
AddMachineButton = new java.awt.Button();
|
||||
TextBoxPosition = new java.awt.TextField();
|
||||
button1 = new java.awt.Button();
|
||||
DeleteButton = new java.awt.Button();
|
||||
StoreButton = new java.awt.Button();
|
||||
MapButton = new java.awt.Button();
|
||||
RightButton = new java.awt.Button();
|
||||
@ -61,11 +61,11 @@ private Image img;
|
||||
|
||||
TextBoxPosition.setName("TextBoxPosition"); // NOI18N
|
||||
|
||||
button1.setLabel("Удалить машину");
|
||||
button1.setName("DeleteMachineButton"); // NOI18N
|
||||
button1.addMouseListener(new java.awt.event.MouseAdapter() {
|
||||
DeleteButton.setLabel("Удалить машину");
|
||||
DeleteButton.setName("DeleteMachineButton"); // NOI18N
|
||||
DeleteButton.addMouseListener(new java.awt.event.MouseAdapter() {
|
||||
public void mouseClicked(java.awt.event.MouseEvent evt) {
|
||||
button1MouseClicked(evt);
|
||||
DeleteButtonMouseClicked(evt);
|
||||
}
|
||||
});
|
||||
|
||||
@ -137,7 +137,7 @@ private Image img;
|
||||
.addComponent(MapComboBox, 0, 165, Short.MAX_VALUE)
|
||||
.addComponent(AddMachineButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(TextBoxPosition, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(button1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(DeleteButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(StoreButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(MapButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
.addContainerGap())
|
||||
@ -168,7 +168,7 @@ private Image img;
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(TextBoxPosition, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(button1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(DeleteButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(StoreButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
@ -252,7 +252,7 @@ private Image img;
|
||||
JOptionPane.showMessageDialog(null, "Не выбрана карта");
|
||||
return;
|
||||
}
|
||||
MapForm form = new MapForm();
|
||||
PolimorphForm form = new PolimorphForm();
|
||||
form.setVisible(true);
|
||||
form.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
@ -275,7 +275,7 @@ private Image img;
|
||||
|
||||
}//GEN-LAST:event_AddMachineButtonMouseClicked
|
||||
|
||||
private void button1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_button1MouseClicked
|
||||
private void DeleteButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_DeleteButtonMouseClicked
|
||||
if (TextBoxPosition.getText().equals(""))
|
||||
{
|
||||
return;
|
||||
@ -295,7 +295,7 @@ private Image img;
|
||||
JOptionPane.showMessageDialog(null, "Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
}//GEN-LAST:event_button1MouseClicked
|
||||
}//GEN-LAST:event_DeleteButtonMouseClicked
|
||||
|
||||
private void StoreButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_StoreButtonMouseClicked
|
||||
if (_mapCollectionGeneric == null)
|
||||
@ -367,6 +367,7 @@ private Image img;
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private java.awt.Button AddMachineButton;
|
||||
private java.awt.Button DeleteButton;
|
||||
private java.awt.Button DownButton;
|
||||
private javax.swing.JPanel InstrumentPanel;
|
||||
private java.awt.Button LeftButton;
|
||||
@ -377,7 +378,6 @@ private Image img;
|
||||
private java.awt.Button StoreButton;
|
||||
private java.awt.TextField TextBoxPosition;
|
||||
private java.awt.Button UpButton;
|
||||
private java.awt.Button button1;
|
||||
private javax.swing.JLabel jLabel1;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
|
@ -285,37 +285,6 @@ public class MapForm extends JFrame{
|
||||
_ArmoredVehicle.DrawTransport(gr);
|
||||
return img;
|
||||
}
|
||||
// public static void main(String args[]) {
|
||||
// /* Set the Nimbus look and feel */
|
||||
// //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
|
||||
// /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
|
||||
// * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
|
||||
// */
|
||||
// try {
|
||||
// for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
|
||||
// if ("Nimbus".equals(info.getName())) {
|
||||
// javax.swing.UIManager.setLookAndFeel(info.getClassName());
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// } catch (ClassNotFoundException ex) {
|
||||
// java.util.logging.Logger.getLogger(MapForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
// } catch (InstantiationException ex) {
|
||||
// java.util.logging.Logger.getLogger(MapForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
// } catch (IllegalAccessException ex) {
|
||||
// java.util.logging.Logger.getLogger(MapForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
// } catch (javax.swing.UnsupportedLookAndFeelException ex) {
|
||||
// java.util.logging.Logger.getLogger(MapForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
// }
|
||||
// //</editor-fold>
|
||||
//
|
||||
// /* Create and display the form */
|
||||
// java.awt.EventQueue.invokeLater(new Runnable() {
|
||||
// public void run() {
|
||||
// new MapForm().setVisible(true);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private java.awt.Button CreateButton;
|
||||
private java.awt.Button CreateTankButton;
|
||||
|
45
ArmoredVehicle/src/PolimorphClass.java
Normal file
45
ArmoredVehicle/src/PolimorphClass.java
Normal file
@ -0,0 +1,45 @@
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
public class PolimorphClass <M extends ArmoredVehicleEntity, R extends IDrawingRoller> {
|
||||
Object[] machines;
|
||||
Object[] rollers;
|
||||
|
||||
int machineCount = 0;
|
||||
int rollersCount = 0;
|
||||
|
||||
public PolimorphClass(int machineCount, int rollersCount) {
|
||||
machines = new Object[machineCount];
|
||||
rollers = new Object[rollersCount];
|
||||
}
|
||||
|
||||
public int AddEntity(M machine)
|
||||
{
|
||||
if(machineCount < machines.length){
|
||||
machines[machineCount] = machine;
|
||||
return machineCount++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int AddRollers(R rolls)
|
||||
{
|
||||
if(rollersCount < rollers.length){
|
||||
rollers[rollersCount]=rolls;
|
||||
return rollersCount++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public DrawingArmoredVehicle CreateMachine() {
|
||||
int iMachine = new Random().nextInt(machineCount);
|
||||
int iRoller = new Random().nextInt(rollersCount);
|
||||
M selectedMachine = (M)machines[iMachine];
|
||||
R selectedRoller = (R)rollers[iRoller];
|
||||
if (selectedMachine instanceof TankEntity) {
|
||||
return new DrawingTank(selectedMachine, selectedRoller);
|
||||
}
|
||||
return new DrawingArmoredVehicle(selectedMachine, selectedRoller);
|
||||
}
|
||||
}
|
@ -10,13 +10,15 @@ import javax.swing.JColorChooser;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MapForm extends JFrame{
|
||||
public class PolimorphForm extends JFrame{
|
||||
|
||||
|
||||
|
||||
private DrawingArmoredVehicle _ArmoredVehicle;
|
||||
private DrawingArmoredVehicle SelectedMachine;
|
||||
|
||||
protected PolimorphClass<ArmoredVehicleEntity, IDrawingRoller> polymorphMachine;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
@ -179,18 +181,34 @@ public class MapForm extends JFrame{
|
||||
pack();
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
public MapForm() {
|
||||
public PolimorphForm() {
|
||||
initComponents();
|
||||
LeftButton.setLabel("<");
|
||||
RightButton.setLabel(">");
|
||||
UpButton.setLabel("/\\");
|
||||
DownButton.setLabel("\\/");
|
||||
polymorphMachine = new PolimorphClass<ArmoredVehicleEntity, IDrawingRoller>(50, 50);
|
||||
}
|
||||
private void CreateButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_CreateButtonMouseClicked
|
||||
Random rnd = new Random();
|
||||
Color newColor = JColorChooser.showDialog(null, "Choose a color", Color.RED);
|
||||
_ArmoredVehicle = new DrawingArmoredVehicle(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
||||
newColor);
|
||||
|
||||
Color newColor = JColorChooser.showDialog(null, "Choose a color", Color.RED);
|
||||
IDrawingRoller roll = null;
|
||||
switch (rnd.nextInt(3)) {
|
||||
case (0) -> roll = new Roller(newColor);
|
||||
case (1) -> roll = new DrawingFirstRoller(newColor);
|
||||
case (2) -> roll = new DrawingSecondRoller(newColor);
|
||||
}
|
||||
int c= rnd.nextInt(4, 6);
|
||||
roll.setCount(c);
|
||||
|
||||
ArmoredVehicleEntity machine = new ArmoredVehicleEntity(rnd.nextInt(300), rnd.nextInt(2000),
|
||||
newColor);
|
||||
|
||||
polymorphMachine.AddRollers(roll);
|
||||
polymorphMachine.AddEntity(machine);
|
||||
_ArmoredVehicle = polymorphMachine.CreateMachine();
|
||||
_ArmoredVehicle.Count = c;
|
||||
SetData();
|
||||
Draw();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user