Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
9538edcc1a | |||
b5be809757 | |||
5606591132 | |||
949003d54a |
@ -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$/src" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$" 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
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?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>
|
@ -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$/../../../ирино, не трогат/!/!/!/!/RPP/ProjectAircraftCarrierHard/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
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,5 +0,0 @@
|
|||||||
public enum BlockDirection {
|
|
||||||
TwoBlocks,
|
|
||||||
FourBlocks,
|
|
||||||
SixBlocks;
|
|
||||||
}
|
|
14
src/CountBlocks.java
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
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,6 +1,9 @@
|
|||||||
|
package src;
|
||||||
|
|
||||||
public enum Direction {
|
public enum Direction {
|
||||||
Up,
|
Up(1),
|
||||||
Down,
|
Down(2),
|
||||||
Left,
|
Left(3),
|
||||||
Right;
|
Right(4);
|
||||||
|
Direction(int value){}
|
||||||
}
|
}
|
||||||
|
50
src/DrawingBlock.java
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,45 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
59
src/DrawingField.java
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
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,9 +1,11 @@
|
|||||||
|
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;
|
||||||
@ -18,10 +20,23 @@ public class DrawingWarship {
|
|||||||
{
|
{
|
||||||
Warship = new EntityWarship();
|
Warship = new EntityWarship();
|
||||||
Warship.Init(speed, weight, bodyColor);
|
Warship.Init(speed, weight, bodyColor);
|
||||||
Blocks = new DrawingBlocks();
|
Blocks= new DrawingBlock();
|
||||||
Blocks.blockDirection = BlockRandom();
|
Blocks.SetBlockCount(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)
|
||||||
@ -70,11 +85,12 @@ public class DrawingWarship {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void DrawTransport(Graphics2D g2){
|
public void DrawTransport(Graphics g){
|
||||||
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};
|
||||||
@ -104,18 +120,8 @@ public class DrawingWarship {
|
|||||||
g2.fillRect(_startPosX, _startPosY + 23, 4, 10);
|
g2.fillRect(_startPosX, _startPosY + 23, 4, 10);
|
||||||
|
|
||||||
//блоки
|
//блоки
|
||||||
Blocks.DrawBlocks(g2,_startPosX, _startPosY);
|
Blocks.DrawBlock(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,5 +1,8 @@
|
|||||||
|
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;}
|
||||||
@ -17,7 +20,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 * 100 / Weight;
|
Step = Speed * 2000 / Weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,112 +0,0 @@
|
|||||||
<?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,106 +1,138 @@
|
|||||||
|
package src;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.*;
|
||||||
import java.awt.event.ActionListener;
|
public class FormWarship extends JFrame{
|
||||||
import java.awt.event.ComponentAdapter;
|
private int Width;
|
||||||
import java.awt.event.ComponentEvent;
|
private int Height;
|
||||||
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(){
|
||||||
InitializeComponent();
|
super("Военный корабль");
|
||||||
}
|
setSize(700,400);
|
||||||
private void Draw(){
|
Width = getWidth();
|
||||||
drawingComponents.repaint();
|
Height = getHeight();
|
||||||
}
|
ShowWindow();
|
||||||
|
RefreshWindow();
|
||||||
private void InitializeComponent(){
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
setContentPane(mainPanel);
|
|
||||||
setTitle("Warship");
|
|
||||||
setSize(900,700);
|
|
||||||
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
Icon iconUp = new ImageIcon("src\\Images\\ArrowUp.jpg");
|
public void ShowWindow(){
|
||||||
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);
|
|
||||||
|
|
||||||
drawingComponents = new DrawingComponents();
|
Dimension dimen = new Dimension(30,30);
|
||||||
drawPanel.add(drawingComponents);
|
|
||||||
buttonCreate.addActionListener(new ActionListener() {
|
ButtonUp.setPreferredSize(dimen);
|
||||||
@Override
|
ButtonUp.addActionListener(e->{
|
||||||
public void actionPerformed(ActionEvent e) {
|
field.UpButtonAction();
|
||||||
Random rnd = new Random();
|
repaint();
|
||||||
_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();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
buttonLeft.addActionListener(new ActionListener() {
|
ButtonDown.setPreferredSize(dimen);
|
||||||
@Override
|
ButtonDown.addActionListener(e->{
|
||||||
public void actionPerformed(ActionEvent e) {
|
field.DownButtonAction();
|
||||||
if(_warship != null) _warship.MoveTransport(Direction.Left);
|
repaint();
|
||||||
Draw();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
buttonRight.addActionListener(new ActionListener() {
|
ButtonRight.setPreferredSize(dimen);
|
||||||
@Override
|
ButtonRight.addActionListener(e->{
|
||||||
public void actionPerformed(ActionEvent e) {
|
field.RightButtonAction();
|
||||||
if(_warship != null) _warship.MoveTransport(Direction.Right);
|
repaint();
|
||||||
Draw();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
buttonUp.addActionListener(new ActionListener() {
|
ButtonLeft.setPreferredSize(dimen);
|
||||||
@Override
|
ButtonLeft.addActionListener(e->{
|
||||||
public void actionPerformed(ActionEvent e) {
|
field.LeftButtonAction();
|
||||||
if(_warship != null) _warship.MoveTransport(Direction.Up);
|
repaint();
|
||||||
Draw();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
buttonDown.addActionListener(new ActionListener() {
|
LRPanel.setLayout(new FlowLayout(FlowLayout.CENTER,50,0));
|
||||||
@Override
|
LRPanel.setBackground(new Color(0,0,0,0));
|
||||||
public void actionPerformed(ActionEvent e) {
|
LRPanel.add(ButtonLeft);
|
||||||
if(_warship != null) _warship.MoveTransport(Direction.Down);
|
LRPanel.add(ButtonRight);
|
||||||
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();
|
||||||
});
|
});
|
||||||
|
|
||||||
drawPanel.addComponentListener(new ComponentAdapter() {
|
BottomPanel.setLayout(new FlowLayout());
|
||||||
|
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) {
|
||||||
_warship.ChangeBorders(drawPanel.getWidth(),drawPanel.getHeight());
|
super.componentResized(e);
|
||||||
Draw();
|
Width=getWidth();
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|