New form has been created. General work is done
This commit is contained in:
parent
a2e79b08bd
commit
7758a3b7cc
@ -53,7 +53,7 @@
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="fa947" binding="pictureBox" layout-manager="GridLayoutManager" row-count="3" column-count="6" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="fa947" binding="pictureBox" layout-manager="GridLayoutManager" row-count="3" column-count="7" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
@ -63,7 +63,7 @@
|
||||
<children>
|
||||
<hspacer id="f89d0">
|
||||
<constraints>
|
||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<vspacer id="402e3">
|
||||
@ -73,12 +73,12 @@
|
||||
</vspacer>
|
||||
<vspacer id="bbd8c">
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="271ef" class="javax.swing.JButton" binding="buttonUp">
|
||||
<constraints>
|
||||
<grid row="1" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<grid row="1" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
@ -93,7 +93,7 @@
|
||||
</component>
|
||||
<component id="4b967" class="javax.swing.JButton" binding="buttonDown">
|
||||
<constraints>
|
||||
<grid row="2" column="4" 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="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
@ -107,7 +107,7 @@
|
||||
</component>
|
||||
<component id="2e663" class="javax.swing.JButton" binding="buttonLeft">
|
||||
<constraints>
|
||||
<grid row="2" column="3" 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="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
@ -122,7 +122,7 @@
|
||||
</component>
|
||||
<component id="c2d76" class="javax.swing.JButton" binding="buttonRight">
|
||||
<constraints>
|
||||
<grid row="2" column="5" 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="6" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
@ -137,7 +137,7 @@
|
||||
</component>
|
||||
<component id="7bc68" class="javax.swing.JButton" binding="createButton">
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="2" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<alignmentX value="0.0"/>
|
||||
@ -145,6 +145,14 @@
|
||||
<text value="Создать"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="27408" class="javax.swing.JButton" binding="createAdvancedButton">
|
||||
<constraints>
|
||||
<grid row="2" column="2" 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>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
|
@ -1,5 +1,7 @@
|
||||
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.util.Random;
|
||||
@ -15,6 +17,7 @@ public class FormArtillery extends JFrame {
|
||||
private JButton buttonDown;
|
||||
private JButton buttonLeft;
|
||||
private JButton buttonRight;
|
||||
private JButton createAdvancedButton;
|
||||
|
||||
private DrawingArtillery _artillery;
|
||||
|
||||
@ -61,12 +64,35 @@ public class FormArtillery extends JFrame {
|
||||
if (_artillery != null) _artillery.moveTransport(Direction.Down);
|
||||
repaint();
|
||||
});
|
||||
createAdvancedButton.addActionListener(e -> {
|
||||
Random rnd = new Random();
|
||||
_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)),
|
||||
rnd.nextInt(4, 7),
|
||||
new Color(
|
||||
rnd.nextInt(0, 256),
|
||||
rnd.nextInt(0, 256),
|
||||
rnd.nextInt(0, 256)),
|
||||
rnd.nextBoolean(),
|
||||
rnd.nextBoolean()
|
||||
);
|
||||
_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()));
|
||||
colorLabel.setText(String.format("Цвет: %x", _artillery.getArtillery().getBodyColor().getRGB()));
|
||||
repaint();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
super.paint(g);
|
||||
Graphics2D g2d = (Graphics2D) artilleryPane.getGraphics();
|
||||
Graphics2D g2d = (Graphics2D) pictureBox.getGraphics();
|
||||
if (_artillery != null) {
|
||||
_artillery.drawTransport(g2d);
|
||||
}
|
||||
|
158
FormMap.form
Normal file
158
FormMap.form
Normal file
@ -0,0 +1,158 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormMap">
|
||||
<grid id="27dc6" binding="artilleryPane" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="630" height="420"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<minimumSize width="80" height="50"/>
|
||||
<preferredSize width="640" height="480"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="57516" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="dcb7f" class="javax.swing.JLabel" binding="speedLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="998a6" class="javax.swing.JLabel" binding="weightLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="cffd1" class="javax.swing.JLabel" binding="colorLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="52641" binding="pictureBox" layout-manager="GridLayoutManager" row-count="4" column-count="6" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="6937b" class="javax.swing.JButton" binding="buttonUp">
|
||||
<constraints>
|
||||
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<borderPainted value="true"/>
|
||||
<contentAreaFilled value="false"/>
|
||||
<icon value="Resources/ArrowUp.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="48a84">
|
||||
<constraints>
|
||||
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<vspacer id="f9d1a">
|
||||
<constraints>
|
||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="e761a" class="javax.swing.JButton" binding="buttonDown">
|
||||
<constraints>
|
||||
<grid row="3" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<contentAreaFilled value="false"/>
|
||||
<icon value="Resources/ArrowDown.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="b99d6" class="javax.swing.JButton" binding="buttonLeft">
|
||||
<constraints>
|
||||
<grid row="3" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<contentAreaFilled value="false"/>
|
||||
<icon value="Resources/ArrowLeft.png"/>
|
||||
<label value=""/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="7f134" class="javax.swing.JButton" binding="buttonRight">
|
||||
<constraints>
|
||||
<grid row="3" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<contentAreaFilled value="false"/>
|
||||
<icon value="Resources/ArrowRight.png"/>
|
||||
<label value=""/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="fc5b2" class="javax.swing.JButton" binding="createButton">
|
||||
<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"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<alignmentX value="0.0"/>
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<text value="Создать"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="65e99" class="javax.swing.JButton" binding="createAdvancedButton">
|
||||
<constraints>
|
||||
<grid row="3" column="1" 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="80160" class="javax.swing.JComboBox" binding="comboBoxSelectorMap">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<model>
|
||||
<item value="Простая карта"/>
|
||||
<item value="Лесная карта"/>
|
||||
</model>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
110
FormMap.java
Normal file
110
FormMap.java
Normal file
@ -0,0 +1,110 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
import java.util.Random;
|
||||
|
||||
public class FormMap extends JFrame {
|
||||
private JPanel artilleryPane;
|
||||
private JLabel speedLabel;
|
||||
private JLabel weightLabel;
|
||||
private JLabel colorLabel;
|
||||
private JPanel pictureBox;
|
||||
private JButton buttonUp;
|
||||
private JButton buttonDown;
|
||||
private JButton buttonLeft;
|
||||
private JButton buttonRight;
|
||||
private JButton createButton;
|
||||
private JButton createAdvancedButton;
|
||||
private JComboBox comboBoxSelectorMap;
|
||||
|
||||
private AbstractMap _abstractMap;
|
||||
private Image bufferedImage;
|
||||
|
||||
public FormMap() {
|
||||
this.setTitle("Artillery");
|
||||
this.setContentPane(artilleryPane);
|
||||
|
||||
_abstractMap = new SimpleMap();
|
||||
|
||||
createButton.addActionListener(e -> {
|
||||
Random rnd = new Random();
|
||||
var artillery = new DrawingArtillery(
|
||||
rnd.nextInt(100, 300),
|
||||
rnd.nextInt(1000, 2000),
|
||||
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
|
||||
rnd.nextInt(4, 6 + 1)
|
||||
);
|
||||
setData(artillery);
|
||||
});
|
||||
buttonLeft.setForeground(new Color(0, 0, 0, 0));
|
||||
buttonRight.setForeground(new Color(0, 0, 0, 0));
|
||||
buttonUp.setForeground(new Color(0, 0, 0, 0));
|
||||
buttonDown.setForeground(new Color(0, 0, 0, 0));
|
||||
buttonLeft.addActionListener(e -> {
|
||||
if (_abstractMap != null) {
|
||||
bufferedImage = _abstractMap.moveObject(Direction.Left);
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
buttonRight.addActionListener(e -> {
|
||||
if (_abstractMap != null) {
|
||||
bufferedImage = _abstractMap.moveObject(Direction.Right);
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
buttonUp.addActionListener(e -> {
|
||||
if (_abstractMap != null) {
|
||||
bufferedImage = _abstractMap.moveObject(Direction.Up);
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
buttonDown.addActionListener(e -> {
|
||||
if (_abstractMap != null) {
|
||||
bufferedImage = _abstractMap.moveObject(Direction.Down);
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
createAdvancedButton.addActionListener(e -> {
|
||||
Random rnd = new Random();
|
||||
var artillery = new DrawingAdvancedArtillery(
|
||||
rnd.nextInt(100, 300),
|
||||
rnd.nextInt(1000, 2000),
|
||||
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
|
||||
rnd.nextInt(4, 6 + 1),
|
||||
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
|
||||
rnd.nextBoolean(),
|
||||
rnd.nextBoolean()
|
||||
);
|
||||
setData(artillery);
|
||||
});
|
||||
comboBoxSelectorMap.addItemListener(e -> {
|
||||
if (e.getStateChange() == ItemEvent.SELECTED) {
|
||||
switch (e.getItem().toString()) {
|
||||
case "Простая карта" -> _abstractMap = new SimpleMap();
|
||||
case "Лесная карта" -> _abstractMap = new ForestMap();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setData(DrawingArtillery artillery) {
|
||||
Random rnd = new Random();
|
||||
artillery.setPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100), pictureBox.getWidth(), pictureBox.getHeight());
|
||||
speedLabel.setText(String.format("Скорость: %d", artillery.artillery.getSpeed()));
|
||||
weightLabel.setText(String.format("Вес: %f", artillery.artillery.getWeight()));
|
||||
colorLabel.setText(String.format("Цвет: %x", artillery.getArtillery().getBodyColor().getRGB()));
|
||||
bufferedImage = _abstractMap.createMap(pictureBox.getWidth(), pictureBox.getHeight(), new DrawingObjectArtillery(artillery));
|
||||
repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
super.paint(g);
|
||||
|
||||
if (bufferedImage != null) {
|
||||
pictureBox.paintComponents(bufferedImage.getGraphics());
|
||||
pictureBox.getGraphics().drawImage(bufferedImage, 0, 0, null);
|
||||
}
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@ import javax.swing.*;
|
||||
|
||||
public class Program {
|
||||
public static void main(String[] args) {
|
||||
FormArtillery form = new FormArtillery();
|
||||
FormMap form = new FormMap();
|
||||
form.setSize(640, 480);
|
||||
form.setVisible(true);
|
||||
form.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||
|
Loading…
Reference in New Issue
Block a user