Готовая лабораторная работа 3

This commit is contained in:
Никита Белянин 2023-11-12 16:09:58 +04:00
parent 3f27d54ee7
commit 12e650cdb7

View File

@ -10,19 +10,19 @@ public class FormTank {
}
public void paintComponent(Graphics g) {
if (_drawingTank == null) {
if (_drawingVehicle == null) {
return;
}
super.paintComponents(g);
Graphics2D g2d = (Graphics2D) g;
_drawingTank.DrawTransport(g2d);
_drawingVehicle.DrawTransport(g2d);
super.repaint();
}
}
public DrawingArmoVehicle SelectedVehicle;
public boolean DialogResult = false;
public DrawingArmoVehicle _drawingTank;
public DrawingArmoVehicle _drawingVehicle;
private AbstractStrategy abstractStrategy;
Canvas canv;
static int pictureBoxWidth = 980;
@ -42,7 +42,7 @@ public class FormTank {
JButton buttonStrategysStep = new JButton("Шаг");
buttonSelectTank = new JButton("Добавить");
JComboBox<String> comboBoxStrategy = new JComboBox<String>(
JComboBox<String> ComboBoxStrategy = new JComboBox<String>(
new String[]{
"к центру",
"к краю",
@ -71,11 +71,11 @@ public class FormTank {
buttonStrategysStep.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (_drawingTank == null) {
if (_drawingVehicle == null) {
return;
}
if (comboBoxStrategy.isEnabled()) {
switch (comboBoxStrategy.getSelectedIndex()) {
if (ComboBoxStrategy.isEnabled()) {
switch (ComboBoxStrategy.getSelectedIndex()) {
case 0:
abstractStrategy = new MoveToCenter();
break;
@ -90,8 +90,8 @@ public class FormTank {
if (abstractStrategy == null) {
return;
}
abstractStrategy.SetData(new DrawingObjectTank(_drawingTank), pictureBoxWidth, pictureBoxHeight);
comboBoxStrategy.setEnabled(false);
abstractStrategy.SetData(new DrawingObjectTank(_drawingVehicle), pictureBoxWidth, pictureBoxHeight);
ComboBoxStrategy.setEnabled(false);
}
if (abstractStrategy == null) {
return;
@ -99,7 +99,7 @@ public class FormTank {
abstractStrategy.MakeStep();
Draw();
if (abstractStrategy.GetStatus() == Status.Finish) {
comboBoxStrategy.setEnabled(true);
ComboBoxStrategy.setEnabled(true);
abstractStrategy = null;
}
}
@ -121,7 +121,7 @@ public class FormTank {
if (selectedColor != null) {
coloradditional = selectedColor;
}
_drawingTank = new DrawingTank(
_drawingVehicle = new DrawingTank(
random.nextInt(100, 300),
random.nextInt(1000, 3000),
color,
@ -134,7 +134,7 @@ public class FormTank {
pictureBoxHeight,
true
);
_drawingTank.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
_drawingVehicle.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
Draw();
}
}
@ -149,7 +149,7 @@ public class FormTank {
if (selectedColor != null) {
color = selectedColor;
}
_drawingTank = new DrawingArmoVehicle(
_drawingVehicle = new DrawingArmoVehicle(
random.nextInt(100, 300),
random.nextInt(1000, 3000),
color,
@ -158,7 +158,7 @@ public class FormTank {
pictureBoxHeight
);
_drawingTank.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
_drawingVehicle.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
Draw();
}
}
@ -166,21 +166,21 @@ public class FormTank {
ActionListener actioListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (_drawingTank == null) {
if (_drawingVehicle == null) {
return;
}
switch (((JButton) (e.getSource())).getName()) {
case "up":
_drawingTank.MoveTransport(Direction.Up);
_drawingVehicle.MoveTransport(Direction.Up);
break;
case "down":
_drawingTank.MoveTransport(Direction.Down);
_drawingVehicle.MoveTransport(Direction.Down);
break;
case "left":
_drawingTank.MoveTransport(Direction.Left);
_drawingVehicle.MoveTransport(Direction.Left);
break;
case "right":
_drawingTank.MoveTransport(Direction.Right);
_drawingVehicle.MoveTransport(Direction.Right);
break;
}
Draw();
@ -201,7 +201,7 @@ public class FormTank {
down.setBounds(900, 520, 40, 40);
left.setBounds(860, 520, 40, 40);
right.setBounds(940, 520, 40, 40);
comboBoxStrategy.setBounds(pictureBoxWidth - 150, 20, 150, 20);
ComboBoxStrategy.setBounds(pictureBoxWidth - 150, 20, 150, 20);
buttonStrategysStep.setBounds(pictureBoxWidth - 150, 45, 150, 20);
buttonSelectTank.setBounds(pictureBoxWidth / 2, 530, 150, 30);
Frame.add(buttonSelectTank);
@ -212,7 +212,7 @@ public class FormTank {
Frame.add(down);
Frame.add(left);
Frame.add(right);
Frame.add(comboBoxStrategy);
Frame.add(ComboBoxStrategy);
Frame.add(buttonStrategysStep);
Frame.setVisible(true);
}