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

This commit is contained in:
Никита Белянин 2023-11-12 15:31:20 +04:00
parent 585424fb62
commit 17d9a3f417

View File

@ -49,23 +49,23 @@ public class FormTank {
}); });
JButton up = new JButton(); JButton up = new JButton();
up.setName("up"); up.setName("up");
ImageIcon iconUp = new ImageIcon("Tank//Resources//KeyUp.png"); ImageIcon iconUp = new ImageIcon("Resources//KeyUp.png");
up.setIcon(iconUp); up.setIcon(iconUp);
JButton down = new JButton(); JButton down = new JButton();
down.setName("down"); down.setName("down");
ImageIcon iconDown = new ImageIcon("Tank//Resources//KeyDown.png"); ImageIcon iconDown = new ImageIcon("Resources//KeyDown.png");
down.setIcon(iconDown); down.setIcon(iconDown);
JButton left = new JButton(); JButton left = new JButton();
left.setName("left"); left.setName("left");
ImageIcon iconLeft = new ImageIcon("Tank//Resources//KeyLeft.png"); ImageIcon iconLeft = new ImageIcon("Resources//KeyLeft.png");
left.setIcon(iconLeft); left.setIcon(iconLeft);
JButton right = new JButton(); JButton right = new JButton();
right.setName("right"); right.setName("right");
ImageIcon iconRight = new ImageIcon("Tank//Resources//KeyRight.png"); ImageIcon iconRight = new ImageIcon("Resources//KeyRight.png");
right.setIcon(iconRight); right.setIcon(iconRight);
buttonStrategysStep.addActionListener( buttonStrategysStep.addActionListener(
@ -86,13 +86,11 @@ public class FormTank {
abstractStrategy = null; abstractStrategy = null;
break; break;
} }
;
if (abstractStrategy == null) { if (abstractStrategy == null) {
return; return;
} }
abstractStrategy.SetData(new abstractStrategy.SetData(new DrawingObjectTank(_drawingTank), pictureBoxWidth, pictureBoxHeight);
DrawingObjectTank(_drawingTank), pictureBoxWidth,
pictureBoxHeight);
comboBoxStrategy.setEnabled(false); comboBoxStrategy.setEnabled(false);
} }
if (abstractStrategy == null) { if (abstractStrategy == null) {
@ -110,7 +108,6 @@ public class FormTank {
buttonCreateTank.addActionListener( buttonCreateTank.addActionListener(
new ActionListener() { new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
System.out.println(e.getActionCommand());
Random random = new Random(); Random random = new Random();
Color color = new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)); Color color = new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256));
// Вызываем диалоговое окно выбора цвета // Вызываем диалоговое окно выбора цвета
@ -118,18 +115,18 @@ public class FormTank {
if (selectedColor != null) { if (selectedColor != null) {
color = selectedColor; color = selectedColor;
} }
Color color2 = new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)); Color coloradditional = new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256));
// Вызываем диалоговое окно выбора цвета // Вызываем диалоговое окно выбора цвета
selectedColor = JColorChooser.showDialog(Frame, "Выберите цвет", Color.WHITE); selectedColor = JColorChooser.showDialog(Frame, "Выберите цвет", Color.WHITE);
if (selectedColor != null) { if (selectedColor != null) {
color2 = selectedColor; coloradditional = selectedColor;
} }
_drawingTank = new DrawingTank( _drawingTank = new DrawingTank(
random.nextInt(100, 300), random.nextInt(100, 300),
random.nextInt(1000, 3000), random.nextInt(1000, 3000),
color, color,
random.nextInt(2, 5), random.nextInt(2, 5),
color2, coloradditional,
true, true,
true, true,
true, true,
@ -145,7 +142,6 @@ public class FormTank {
buttonCreate.addActionListener( buttonCreate.addActionListener(
new ActionListener() { new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
System.out.println(e.getActionCommand());
Random random = new Random(); Random random = new Random();
Color color = new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)); Color color = new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256));
// Вызываем диалоговое окно выбора цвета // Вызываем диалоговое окно выбора цвета
@ -170,7 +166,6 @@ public class FormTank {
ActionListener actioListener = new ActionListener() { ActionListener actioListener = new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
System.out.println(((JButton) (e.getSource())).getName());
if (_drawingTank == null) { if (_drawingTank == null) {
return; return;
} }