Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
be91b54c2b | |||
460a7750b1 | |||
cc5bd478e0 | |||
b057110fbe |
2
.idea/AircraftCarrier_Hard.iml
generated
@ -3,7 +3,7 @@
|
|||||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
<exclude-output />
|
<exclude-output />
|
||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
15
.idea/git_toolbox_prj.xml
generated
@ -1,15 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="GitToolBoxProjectSettings">
|
|
||||||
<option name="commitMessageIssueKeyValidationOverride">
|
|
||||||
<BoolValueOverride>
|
|
||||||
<option name="enabled" value="true" />
|
|
||||||
</BoolValueOverride>
|
|
||||||
</option>
|
|
||||||
<option name="commitMessageValidationEnabledOverride">
|
|
||||||
<BoolValueOverride>
|
|
||||||
<option name="enabled" value="true" />
|
|
||||||
</BoolValueOverride>
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
2
.idea/misc.xml
generated
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11.0.5" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11.0.5" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/../../../ирино, не трогат/!/!/!/!/RPP/ProjectAircraftCarrierHard/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
5
src/BlockDirection.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
public enum BlockDirection {
|
||||||
|
TwoBlocks,
|
||||||
|
FourBlocks,
|
||||||
|
SixBlocks;
|
||||||
|
}
|
@ -1,14 +0,0 @@
|
|||||||
package src;
|
|
||||||
|
|
||||||
public enum CountBlocks {
|
|
||||||
TwoBlocks(2),
|
|
||||||
FourBlocks(4),
|
|
||||||
SixBlocks(6);
|
|
||||||
private final int Value;
|
|
||||||
CountBlocks(int count){
|
|
||||||
Value=count;
|
|
||||||
}
|
|
||||||
public int GetBlockCount(){
|
|
||||||
return Value;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +1,6 @@
|
|||||||
package src;
|
|
||||||
|
|
||||||
public enum Direction {
|
public enum Direction {
|
||||||
Up(1),
|
Up,
|
||||||
Down(2),
|
Down,
|
||||||
Left(3),
|
Left,
|
||||||
Right(4);
|
Right;
|
||||||
Direction(int value){}
|
|
||||||
}
|
}
|
||||||
|
@ -1,50 +0,0 @@
|
|||||||
package src;
|
|
||||||
import java.awt.*;
|
|
||||||
|
|
||||||
public class DrawingBlock {
|
|
||||||
private CountBlocks _block;
|
|
||||||
|
|
||||||
public void SetBlockCount(int count){
|
|
||||||
for (CountBlocks temp: CountBlocks.values()){
|
|
||||||
if (temp.GetBlockCount() == count){
|
|
||||||
_block=temp;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DrawBlock(Graphics2D g, int _startPosX, int _startPosY) {
|
|
||||||
Graphics2D g2 = (Graphics2D) g;
|
|
||||||
if (_block.GetBlockCount() <= 2) {
|
|
||||||
g2.setColor(Color.GRAY);
|
|
||||||
g2.fillRect(_startPosX + 15, _startPosY + 10, 10, 10);
|
|
||||||
g2.setColor(Color.BLACK);
|
|
||||||
g2.drawRect(_startPosX + 15, _startPosY + 10, 10, 10);
|
|
||||||
g2.setColor(Color.GRAY);
|
|
||||||
g2.fillRect(_startPosX + 15, _startPosY + 20, 10, 10);
|
|
||||||
g2.setColor(Color.BLACK);
|
|
||||||
g2.drawRect(_startPosX + 15, _startPosY + 20, 10, 10);
|
|
||||||
}
|
|
||||||
if (_block.GetBlockCount() <= 4) {
|
|
||||||
g2.setColor(Color.GRAY);
|
|
||||||
g2.fillRect(_startPosX+25,_startPosY+10,10,10);
|
|
||||||
g2.setColor(Color.BLACK);
|
|
||||||
g2.drawRect(_startPosX+25,_startPosY+10,10,10);
|
|
||||||
g2.setColor(Color.GRAY);
|
|
||||||
g2.fillRect(_startPosX+25,_startPosY+20,10,10);
|
|
||||||
g2.setColor(Color.BLACK);
|
|
||||||
g2.drawRect(_startPosX+25,_startPosY+20,10,10);
|
|
||||||
}
|
|
||||||
if (_block.GetBlockCount() <= 6) {
|
|
||||||
g2.setColor(Color.GRAY);
|
|
||||||
g2.fillRect(_startPosX+35,_startPosY+10,10,10);
|
|
||||||
g2.setColor(Color.BLACK);
|
|
||||||
g2.drawRect(_startPosX+35,_startPosY+10,10,10);
|
|
||||||
g2.setColor(Color.GRAY);
|
|
||||||
g2.fillRect(_startPosX+35,_startPosY+20,10,10);
|
|
||||||
g2.setColor(Color.BLACK);
|
|
||||||
g2.drawRect(_startPosX+35,_startPosY+20,10,10);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
45
src/DrawingBlocks.java
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawingBlocks {
|
||||||
|
BlockDirection blockDirection;
|
||||||
|
public void DrawBlocks(Graphics2D g2, int _startPosX, int _startPosY){
|
||||||
|
switch(blockDirection){
|
||||||
|
case TwoBlocks:
|
||||||
|
g2.setColor(Color.GRAY);
|
||||||
|
g2.fillRect(_startPosX + 15, _startPosY + 10, 10, 10);
|
||||||
|
g2.fillRect(_startPosX + 15, _startPosY + 20, 10, 10);
|
||||||
|
g2.setColor(Color.BLACK);
|
||||||
|
g2.drawRect(_startPosX + 15, _startPosY + 10, 10, 10);
|
||||||
|
g2.drawRect(_startPosX + 15, _startPosY + 20, 10, 10);
|
||||||
|
break;
|
||||||
|
case FourBlocks:
|
||||||
|
g2.setColor(Color.GRAY);
|
||||||
|
g2.fillRect(_startPosX + 15, _startPosY + 10, 10, 10);
|
||||||
|
g2.fillRect(_startPosX + 15, _startPosY + 20, 10, 10);
|
||||||
|
g2.fillRect(_startPosX + 25, _startPosY + 10, 10, 10);
|
||||||
|
g2.fillRect(_startPosX + 25, _startPosY + 20, 10, 10);
|
||||||
|
g2.setColor(Color.BLACK);
|
||||||
|
g2.drawRect(_startPosX + 15, _startPosY + 10, 10, 10);
|
||||||
|
g2.drawRect(_startPosX + 15, _startPosY + 20, 10, 10);
|
||||||
|
g2.drawRect(_startPosX + 25, _startPosY + 10, 10, 10);
|
||||||
|
g2.drawRect(_startPosX + 25, _startPosY + 20, 10, 10);
|
||||||
|
break;
|
||||||
|
case SixBlocks:
|
||||||
|
g2.setColor(Color.GRAY);
|
||||||
|
g2.fillRect(_startPosX + 15, _startPosY + 10, 10, 10);
|
||||||
|
g2.fillRect(_startPosX + 15, _startPosY + 20, 10, 10);
|
||||||
|
g2.fillRect(_startPosX + 25, _startPosY + 10, 10, 10);
|
||||||
|
g2.fillRect(_startPosX + 25, _startPosY + 20, 10, 10);
|
||||||
|
g2.fillRect(_startPosX + 35, _startPosY + 10, 10, 10);
|
||||||
|
g2.fillRect(_startPosX + 35, _startPosY + 20, 10, 10);
|
||||||
|
g2.setColor(Color.BLACK);
|
||||||
|
g2.drawRect(_startPosX + 15, _startPosY + 10, 10, 10);
|
||||||
|
g2.drawRect(_startPosX + 15, _startPosY + 20, 10, 10);
|
||||||
|
g2.drawRect(_startPosX + 25, _startPosY + 10, 10, 10);
|
||||||
|
g2.drawRect(_startPosX + 25, _startPosY + 20, 10, 10);
|
||||||
|
g2.drawRect(_startPosX + 35, _startPosY + 10, 10, 10);
|
||||||
|
g2.drawRect(_startPosX + 35, _startPosY + 20, 10, 10);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
22
src/DrawingComponents.java
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawingComponents extends JComponent {
|
||||||
|
public DrawingWarship warship;
|
||||||
|
public DrawingComponents(){
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
public void SetDrawingWarship(DrawingWarship warship){
|
||||||
|
this.warship = warship;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paintComponent(Graphics g){
|
||||||
|
super.paintComponent(g);
|
||||||
|
Graphics2D g2 = (Graphics2D) g;
|
||||||
|
if(warship != null){
|
||||||
|
warship.DrawTransport(g2);
|
||||||
|
}
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
}
|
@ -1,59 +0,0 @@
|
|||||||
package src;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class DrawingField extends JPanel {
|
|
||||||
private final FormWarship Field;
|
|
||||||
DrawingWarship _warship;
|
|
||||||
public DrawingField(FormWarship field) {
|
|
||||||
this.Field = field;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
protected void paintComponent(Graphics g) {
|
|
||||||
super.paintComponent(g);
|
|
||||||
Graphics2D g2 =(Graphics2D)g;
|
|
||||||
if (_warship!=null)
|
|
||||||
_warship.DrawTransport(g2);
|
|
||||||
else return;
|
|
||||||
}
|
|
||||||
public void UpButtonAction(){
|
|
||||||
if (_warship!=null)
|
|
||||||
_warship.MoveTransport(Direction.Up);
|
|
||||||
else
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
public void DownButtonAction(){
|
|
||||||
if (_warship!=null)
|
|
||||||
_warship.MoveTransport(Direction.Down);
|
|
||||||
else
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
public void RightButtonAction(){
|
|
||||||
if (_warship!=null)
|
|
||||||
_warship.MoveTransport(Direction.Right);
|
|
||||||
else
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
public void LeftButtonAction(){
|
|
||||||
if (_warship!=null)
|
|
||||||
_warship.MoveTransport(Direction.Left);
|
|
||||||
else
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
public void CreateButtonAction(){
|
|
||||||
Random rand=new Random();
|
|
||||||
_warship=new DrawingWarship();
|
|
||||||
_warship.Init(rand.nextInt(50)+10,rand.nextInt(3000)+20000,new Color(rand.nextInt(256),rand.nextInt(256),rand.nextInt(256)));
|
|
||||||
_warship.SetPosition(rand.nextInt(100)+10,rand.nextInt(100)+10,getWidth(),getHeight());
|
|
||||||
Field.SpeedLabel.setText("Скорость: "+_warship.GetWarship().GetSpeed());
|
|
||||||
Field.WeightLabel.setText("Вес: "+_warship.GetWarship().GetWeight());
|
|
||||||
Field.BodyColorLabel.setText("Цвет: "+Integer.toHexString(_warship.GetWarship().GetBodyColor().getRGB()).substring(2));
|
|
||||||
}
|
|
||||||
public void ResizeField(){
|
|
||||||
if (_warship!=null)
|
|
||||||
_warship.ChangeBorders(getWidth(),getHeight());
|
|
||||||
else return;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +1,9 @@
|
|||||||
package src;
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class DrawingWarship {
|
public class DrawingWarship {
|
||||||
private EntityWarship Warship;
|
private EntityWarship Warship;
|
||||||
public DrawingBlock Blocks;
|
|
||||||
public EntityWarship GetWarship(){return Warship;}
|
public EntityWarship GetWarship(){return Warship;}
|
||||||
|
public DrawingBlocks Blocks;
|
||||||
|
|
||||||
private int _startPosX;
|
private int _startPosX;
|
||||||
private int _startPosY;
|
private int _startPosY;
|
||||||
@ -20,23 +18,10 @@ public class DrawingWarship {
|
|||||||
{
|
{
|
||||||
Warship = new EntityWarship();
|
Warship = new EntityWarship();
|
||||||
Warship.Init(speed, weight, bodyColor);
|
Warship.Init(speed, weight, bodyColor);
|
||||||
Blocks= new DrawingBlock();
|
Blocks = new DrawingBlocks();
|
||||||
Blocks.SetBlockCount(BlockRandom());
|
Blocks.blockDirection = BlockRandom();
|
||||||
}
|
|
||||||
public int BlockRandom(){
|
|
||||||
Random rand = new Random();
|
|
||||||
int resRand = rand.nextInt(3);
|
|
||||||
if(resRand == 0){
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
if(resRand == 1){
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
if(resRand == 2){
|
|
||||||
return 6;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetPosition(int x, int y, int width, int height)
|
public void SetPosition(int x, int y, int width, int height)
|
||||||
{
|
{
|
||||||
if (width >= x + _warshipWidth && height >= y + _warshipHeight && x >= 0 && y >= 0)
|
if (width >= x + _warshipWidth && height >= y + _warshipHeight && x >= 0 && y >= 0)
|
||||||
@ -85,12 +70,11 @@ public class DrawingWarship {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void DrawTransport(Graphics g){
|
public void DrawTransport(Graphics2D g2){
|
||||||
if (_startPosX < 0 || _startPosY < 0 || _pictureHeight == null || _pictureWidth == null)
|
if (_startPosX < 0 || _startPosY < 0 || _pictureHeight == null || _pictureWidth == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Graphics2D g2 = (Graphics2D) g;
|
|
||||||
//главная палуба
|
//главная палуба
|
||||||
int[] pointXWarship = {_startPosX + 4, _startPosX + 94, _startPosX + 114, _startPosX + 94, _startPosX + 4};
|
int[] pointXWarship = {_startPosX + 4, _startPosX + 94, _startPosX + 114, _startPosX + 94, _startPosX + 4};
|
||||||
int[] pointYWarship = {_startPosY, _startPosY, _startPosY + 20, _startPosY + 40, _startPosY + 40};
|
int[] pointYWarship = {_startPosY, _startPosY, _startPosY + 20, _startPosY + 40, _startPosY + 40};
|
||||||
@ -120,8 +104,18 @@ public class DrawingWarship {
|
|||||||
g2.fillRect(_startPosX, _startPosY + 23, 4, 10);
|
g2.fillRect(_startPosX, _startPosY + 23, 4, 10);
|
||||||
|
|
||||||
//блоки
|
//блоки
|
||||||
Blocks.DrawBlock(g2, _startPosX, _startPosY);
|
Blocks.DrawBlocks(g2,_startPosX, _startPosY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BlockDirection BlockRandom(){
|
||||||
|
Random rand = new Random();
|
||||||
|
int resRand = rand.nextInt(3);
|
||||||
|
if(resRand == 0) return BlockDirection.TwoBlocks;
|
||||||
|
if(resRand == 1) return BlockDirection.FourBlocks;
|
||||||
|
if(resRand == 2) return BlockDirection.SixBlocks;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public void ChangeBorders(int width, int height)
|
public void ChangeBorders(int width, int height)
|
||||||
{
|
{
|
||||||
_pictureWidth = width;
|
_pictureWidth = width;
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
package src;
|
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class EntityWarship {
|
public class EntityWarship {
|
||||||
private int Speed;
|
private int Speed;
|
||||||
public int GetSpeed(){return Speed;}
|
public int GetSpeed(){return Speed;}
|
||||||
@ -20,7 +17,7 @@ public class EntityWarship {
|
|||||||
Speed = speed <= 0 ? rnd.nextInt(100) + 50 : speed;
|
Speed = speed <= 0 ? rnd.nextInt(100) + 50 : speed;
|
||||||
Weight = weight <= 0 ? rnd.nextInt(30)+40 : weight;
|
Weight = weight <= 0 ? rnd.nextInt(30)+40 : weight;
|
||||||
BodyColor= bodyColor;
|
BodyColor= bodyColor;
|
||||||
Step = Speed * 2000 / Weight;
|
Step = Speed * 100 / Weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
112
src/FormWarship.form
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormWarship">
|
||||||
|
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="4" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<xy x="23" y="20" width="961" height="517"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<component id="80b72" class="javax.swing.JButton" binding="buttonCreate">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" 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>
|
||||||
|
<text value="Create"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<hspacer id="3f3da">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
<component id="32714" class="javax.swing.JButton" binding="buttonLeft">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" 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>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<toolbar id="3697c" binding="toolBar">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" column="0" row-span="1" col-span="5" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||||
|
<preferred-size width="-1" height="20"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<component id="7dd11" class="javax.swing.JLabel" binding="toolBarLabelSpeed">
|
||||||
|
<constraints/>
|
||||||
|
<properties>
|
||||||
|
<text value="Speed"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="9db36" class="javax.swing.JLabel" binding="toolBarLabelWieght">
|
||||||
|
<constraints/>
|
||||||
|
<properties>
|
||||||
|
<text value="Weight"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="3d477" class="javax.swing.JLabel" binding="toolBarLabelColor">
|
||||||
|
<constraints/>
|
||||||
|
<properties>
|
||||||
|
<text value="Color"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</toolbar>
|
||||||
|
<component id="55933" class="javax.swing.JButton" binding="buttonRight">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" 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>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="82cc1" class="javax.swing.JButton" binding="buttonUp">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" 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>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="bb79e" class="javax.swing.JButton" binding="buttonDown">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" 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>
|
||||||
|
<enabled value="true"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<grid id="dfecd" binding="drawPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="5" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children/>
|
||||||
|
</grid>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</form>
|
@ -1,138 +1,106 @@
|
|||||||
package src;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.*;
|
import java.awt.event.ActionEvent;
|
||||||
public class FormWarship extends JFrame{
|
import java.awt.event.ActionListener;
|
||||||
private int Width;
|
import java.awt.event.ComponentAdapter;
|
||||||
private int Height;
|
import java.awt.event.ComponentEvent;
|
||||||
|
import java.util.Random;
|
||||||
JPanel BottomPanel = new JPanel();
|
|
||||||
JPanel CreatePanel = new JPanel();
|
|
||||||
JPanel BottomAndCreatePanel = new JPanel();
|
|
||||||
JPanel DimentionPanel = new JPanel();
|
|
||||||
JPanel UPanel = new JPanel();
|
|
||||||
JPanel DPanel = new JPanel();
|
|
||||||
JPanel LRPanel = new JPanel();
|
|
||||||
|
|
||||||
JLabel SpeedLabel = new JLabel("Скорость: ");
|
|
||||||
JLabel WeightLabel = new JLabel("Вес: ");
|
|
||||||
JLabel BodyColorLabel = new JLabel("Цвет: ");
|
|
||||||
|
|
||||||
DrawingField field = new DrawingField(this);
|
|
||||||
|
|
||||||
JButton ButtonCreate=new JButton("Создать");
|
|
||||||
|
|
||||||
Icon iconUp = new ImageIcon("Resource\\arrowUp.jpg");
|
|
||||||
JButton ButtonUp = new JButton(iconUp);
|
|
||||||
|
|
||||||
Icon iconDown = new ImageIcon("Resource\\arrowDown.jpg");
|
|
||||||
JButton ButtonDown = new JButton(iconDown);
|
|
||||||
|
|
||||||
Icon iconRight = new ImageIcon("Resource\\arrowRight.jpg");
|
|
||||||
JButton ButtonRight = new JButton(iconRight);
|
|
||||||
|
|
||||||
Icon iconLeft = new ImageIcon("Resource\\arrowLeft.jpg");
|
|
||||||
JButton ButtonLeft = new JButton(iconLeft);
|
|
||||||
|
|
||||||
|
public class FormWarship extends JFrame {
|
||||||
|
private DrawingWarship _warship;
|
||||||
|
public DrawingComponents drawingComponents;
|
||||||
|
private JPanel mainPanel;
|
||||||
|
private JButton buttonCreate;
|
||||||
|
private JButton buttonLeft;
|
||||||
|
private JButton buttonUp;
|
||||||
|
private JButton buttonDown;
|
||||||
|
private JButton buttonRight;
|
||||||
|
private JToolBar toolBar;
|
||||||
|
private JLabel toolBarLabelSpeed;
|
||||||
|
private JLabel toolBarLabelWieght;
|
||||||
|
private JLabel toolBarLabelColor;
|
||||||
|
private JPanel drawPanel;
|
||||||
|
|
||||||
public FormWarship(){
|
public FormWarship(){
|
||||||
super("Военный корабль");
|
InitializeComponent();
|
||||||
setSize(700,400);
|
}
|
||||||
Width = getWidth();
|
private void Draw(){
|
||||||
Height = getHeight();
|
drawingComponents.repaint();
|
||||||
ShowWindow();
|
|
||||||
RefreshWindow();
|
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
setVisible(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ShowWindow(){
|
private void InitializeComponent(){
|
||||||
|
setContentPane(mainPanel);
|
||||||
|
setTitle("Warship");
|
||||||
|
setSize(900,700);
|
||||||
|
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||||
|
setVisible(true);
|
||||||
|
|
||||||
Dimension dimen = new Dimension(30,30);
|
Icon iconUp = new ImageIcon("src\\Images\\ArrowUp.jpg");
|
||||||
|
buttonUp.setIcon(iconUp);
|
||||||
|
Icon iconDown = new ImageIcon("src\\Images\\ArrowDown.jpg");
|
||||||
|
buttonDown.setIcon(iconDown);
|
||||||
|
Icon iconLeft = new ImageIcon("src\\Images\\ArrowLeft.jpg");
|
||||||
|
buttonLeft.setIcon(iconLeft);
|
||||||
|
Icon iconRight = new ImageIcon("src\\Images\\ArrowRight.jpg");
|
||||||
|
buttonRight.setIcon(iconRight);
|
||||||
|
|
||||||
ButtonUp.setPreferredSize(dimen);
|
drawingComponents = new DrawingComponents();
|
||||||
ButtonUp.addActionListener(e->{
|
drawPanel.add(drawingComponents);
|
||||||
field.UpButtonAction();
|
buttonCreate.addActionListener(new ActionListener() {
|
||||||
repaint();
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
Random rnd = new Random();
|
||||||
|
_warship = new DrawingWarship();
|
||||||
|
_warship.Init(rnd.nextInt(200) + 100, rnd.nextInt(1000) + 1000,
|
||||||
|
new Color(rnd.nextInt(256),rnd.nextInt(256),rnd.nextInt(256)));
|
||||||
|
_warship.SetPosition(rnd.nextInt(90) + 10, rnd.nextInt(90) + 10, drawPanel.getWidth(), drawPanel.getHeight());
|
||||||
|
toolBarLabelSpeed.setText("Color: " + _warship.GetWarship().GetSpeed() + " ");
|
||||||
|
toolBarLabelWieght.setText("Weight: " + _warship.GetWarship().GetWeight() + " ");
|
||||||
|
toolBarLabelColor.setText("Color: " + _warship.GetWarship().GetBodyColor().getRed() + " " +
|
||||||
|
_warship.GetWarship().GetBodyColor().getGreen() + " " + _warship.GetWarship().GetBodyColor().getBlue());
|
||||||
|
drawingComponents.SetDrawingWarship(_warship);
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ButtonDown.setPreferredSize(dimen);
|
buttonLeft.addActionListener(new ActionListener() {
|
||||||
ButtonDown.addActionListener(e->{
|
@Override
|
||||||
field.DownButtonAction();
|
public void actionPerformed(ActionEvent e) {
|
||||||
repaint();
|
if(_warship != null) _warship.MoveTransport(Direction.Left);
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ButtonRight.setPreferredSize(dimen);
|
buttonRight.addActionListener(new ActionListener() {
|
||||||
ButtonRight.addActionListener(e->{
|
@Override
|
||||||
field.RightButtonAction();
|
public void actionPerformed(ActionEvent e) {
|
||||||
repaint();
|
if(_warship != null) _warship.MoveTransport(Direction.Right);
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ButtonLeft.setPreferredSize(dimen);
|
buttonUp.addActionListener(new ActionListener() {
|
||||||
ButtonLeft.addActionListener(e->{
|
@Override
|
||||||
field.LeftButtonAction();
|
public void actionPerformed(ActionEvent e) {
|
||||||
repaint();
|
if(_warship != null) _warship.MoveTransport(Direction.Up);
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
LRPanel.setLayout(new FlowLayout(FlowLayout.CENTER,50,0));
|
buttonDown.addActionListener(new ActionListener() {
|
||||||
LRPanel.setBackground(new Color(0,0,0,0));
|
@Override
|
||||||
LRPanel.add(ButtonLeft);
|
public void actionPerformed(ActionEvent e) {
|
||||||
LRPanel.add(ButtonRight);
|
if(_warship != null) _warship.MoveTransport(Direction.Down);
|
||||||
|
Draw();
|
||||||
UPanel.setLayout(new FlowLayout());
|
}
|
||||||
UPanel.setBackground(new Color(0,0,0,0));
|
|
||||||
UPanel.add(ButtonUp);
|
|
||||||
|
|
||||||
DPanel.setLayout(new FlowLayout());
|
|
||||||
DPanel.setBackground(new Color(0,0,0,0));
|
|
||||||
DPanel.add(ButtonDown);
|
|
||||||
|
|
||||||
DimentionPanel.setLayout(new BoxLayout(DimentionPanel,BoxLayout.Y_AXIS));
|
|
||||||
DimentionPanel.setBackground(new Color(0,0,0,0));
|
|
||||||
DimentionPanel.add(UPanel);
|
|
||||||
DimentionPanel.add(LRPanel);
|
|
||||||
DimentionPanel.add(DPanel);
|
|
||||||
add(DimentionPanel);
|
|
||||||
|
|
||||||
CreatePanel.setLayout(new FlowLayout());
|
|
||||||
CreatePanel.setBackground(new Color(0,0,0,0));
|
|
||||||
CreatePanel.add(ButtonCreate);
|
|
||||||
ButtonCreate.addActionListener(e->{
|
|
||||||
field.CreateButtonAction();
|
|
||||||
repaint();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
BottomPanel.setLayout(new FlowLayout());
|
drawPanel.addComponentListener(new ComponentAdapter() {
|
||||||
BottomPanel.setBackground(new Color(0,0,0,0));
|
|
||||||
BottomPanel.add(SpeedLabel);
|
|
||||||
BottomPanel.add(WeightLabel);
|
|
||||||
BottomPanel.add(BodyColorLabel);
|
|
||||||
|
|
||||||
BottomAndCreatePanel.setLayout(new BoxLayout(BottomAndCreatePanel,BoxLayout.Y_AXIS));
|
|
||||||
BottomAndCreatePanel.setBackground(new Color(0,0,0,0));
|
|
||||||
BottomAndCreatePanel.add(CreatePanel);
|
|
||||||
BottomAndCreatePanel.add(BottomPanel);
|
|
||||||
|
|
||||||
add(BottomAndCreatePanel);
|
|
||||||
add(field);
|
|
||||||
|
|
||||||
addComponentListener(new ComponentAdapter() {
|
|
||||||
@Override
|
@Override
|
||||||
public void componentResized(ComponentEvent e) {
|
public void componentResized(ComponentEvent e) {
|
||||||
super.componentResized(e);
|
_warship.ChangeBorders(drawPanel.getWidth(),drawPanel.getHeight());
|
||||||
Width=getWidth();
|
Draw();
|
||||||
Height=getHeight();
|
|
||||||
|
|
||||||
field.ResizeField();
|
|
||||||
repaint();
|
|
||||||
RefreshWindow();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
public void RefreshWindow(){
|
|
||||||
field.setBounds(0,0,Width,Height);
|
|
||||||
BottomAndCreatePanel.setBounds(-220,Height-110,Width,80);
|
|
||||||
DimentionPanel.setBounds(Width-170,Height-170,190,140);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
@ -1,6 +1,6 @@
|
|||||||
package src;
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
new FormWarship();
|
new FormWarship();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|