diff --git a/FormArtillery.form b/FormArtillery.form index d1e17c1..72a7427 100644 --- a/FormArtillery.form +++ b/FormArtillery.form @@ -53,7 +53,7 @@ - + @@ -61,11 +61,6 @@ - - - - - @@ -78,7 +73,7 @@ - + @@ -93,7 +88,7 @@ - + @@ -107,7 +102,7 @@ - + @@ -122,7 +117,7 @@ - + @@ -153,6 +148,19 @@ + + + + + + + + + + + + + diff --git a/FormArtillery.java b/FormArtillery.java index 69c29cd..8584b14 100644 --- a/FormArtillery.java +++ b/FormArtillery.java @@ -1,9 +1,6 @@ import javax.swing.*; import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.ComponentAdapter; -import java.awt.event.ComponentEvent; +import java.awt.event.*; import java.util.Random; public class FormArtillery extends JFrame { @@ -18,23 +15,21 @@ public class FormArtillery extends JFrame { private JButton buttonLeft; private JButton buttonRight; private JButton createAdvancedButton; + private JButton buttonSelect; private DrawingArtillery _artillery; + private DrawingArtillery selectedArtillery; public FormArtillery() { this.setTitle("Artillery"); this.setContentPane(artilleryPane); createButton.addActionListener(e -> { Random rnd = new Random(); - _artillery = new DrawingArtillery( - rnd.nextInt(100, 300), - rnd.nextInt(1000, 2000), - new Color( - rnd.nextInt(0, 256), - rnd.nextInt(0, 256), - rnd.nextInt(0, 256)), - rnd.nextInt(4, 7) - ); + Color color = JColorChooser.showDialog(this, "Цвет", new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256))); + if (color == null) { + color = new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)); + } + _artillery = new DrawingArtillery(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), color, rnd.nextInt(4, 7)); _artillery.setPosition(10 + rnd.nextInt(90), 10 + rnd.nextInt(90), pictureBox.getWidth(), pictureBox.getHeight()); speedLabel.setText(String.format("Скорость: %s", _artillery.getArtillery().getSpeed())); weightLabel.setText(String.format("Вес: %s", _artillery.getArtillery().getWeight())); @@ -66,18 +61,20 @@ public class FormArtillery extends JFrame { }); createAdvancedButton.addActionListener(e -> { Random rnd = new Random(); + Color color = JColorChooser.showDialog(this, "Основной цвет", Color.white); + if (color == null) { + color = new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)); + } + Color dopColor = JColorChooser.showDialog(this, "Дополнительный цвет", Color.white); + if (dopColor == null) { + dopColor = new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)); + } _artillery = new DrawingAdvancedArtillery( rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), - new Color( - rnd.nextInt(0, 256), - rnd.nextInt(0, 256), - rnd.nextInt(0, 256)), + color, rnd.nextInt(4, 7), - new Color( - rnd.nextInt(0, 256), - rnd.nextInt(0, 256), - rnd.nextInt(0, 256)), + dopColor, rnd.nextBoolean(), rnd.nextBoolean() ); @@ -87,6 +84,14 @@ public class FormArtillery extends JFrame { colorLabel.setText(String.format("Цвет: %x", _artillery.getArtillery().getBodyColor().getRGB())); repaint(); }); + buttonSelect.addActionListener(e -> { + selectedArtillery = _artillery; + dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING)); + }); + } + + public DrawingArtillery getSelectedArtillery() { + return selectedArtillery; } @Override