gui form
This commit is contained in:
BIN
Resources/30px_arrow_down.png
Normal file
BIN
Resources/30px_arrow_down.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 244 B |
BIN
Resources/30px_arrow_left.png
Normal file
BIN
Resources/30px_arrow_left.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 249 B |
BIN
Resources/30px_arrow_right.png
Normal file
BIN
Resources/30px_arrow_right.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 254 B |
BIN
Resources/30px_arrow_up.png
Normal file
BIN
Resources/30px_arrow_up.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 257 B |
@@ -1,3 +1,5 @@
|
|||||||
|
package src;
|
||||||
|
|
||||||
public enum Direction {
|
public enum Direction {
|
||||||
Up,
|
Up,
|
||||||
Down,
|
Down,
|
||||||
100
src/DrawingBoat.java
Normal file
100
src/DrawingBoat.java
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
package src;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawingBoat {
|
||||||
|
public EntityBoat Boat;
|
||||||
|
private float _startPosX;
|
||||||
|
private float _startPosY;
|
||||||
|
private int _pictureWidth = 0;
|
||||||
|
private int _pictureHeight = 0;
|
||||||
|
private final int _boatWidth = 100;
|
||||||
|
private final int _boatHeight = 40;
|
||||||
|
|
||||||
|
public void Init(int speed, float weight, Color bodyColor) {
|
||||||
|
Boat = new EntityBoat();
|
||||||
|
Boat.Init(speed, weight, bodyColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetPosition(int x, int y, int width, int height) {
|
||||||
|
if (x > 0 && x < width - _boatWidth && y > 0 && y < height - _boatHeight) {
|
||||||
|
_startPosX = x;
|
||||||
|
_startPosY = y;
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void MoveTransport(Direction direction) {
|
||||||
|
if (_pictureWidth == 0 || _pictureHeight == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (direction) {
|
||||||
|
case Right:
|
||||||
|
if (_startPosX + _boatWidth + Boat.Step < _pictureWidth) {
|
||||||
|
_startPosX += Boat.Step;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Left:
|
||||||
|
if (_startPosX - Boat.Step > 0) {
|
||||||
|
_startPosX -= Boat.Step;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Up:
|
||||||
|
if (_startPosY - Boat.Step > 0) {
|
||||||
|
_startPosY -= Boat.Step;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Down:
|
||||||
|
if (_startPosY + _boatHeight + Boat.Step < _pictureHeight) {
|
||||||
|
_startPosY += Boat.Step;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (_startPosX < 0 || _startPosY < 0
|
||||||
|
|| _pictureHeight == 0 || _pictureWidth == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// todo доделать прорисовку
|
||||||
|
|
||||||
|
// SolidBrush brush = new SolidBrush(Boat.BodyColor);
|
||||||
|
//
|
||||||
|
// PointF[] bodyPoints = new PointF[5];
|
||||||
|
// bodyPoints[0] = new PointF(_startPosX, _startPosY);
|
||||||
|
// bodyPoints[1] = new PointF(_startPosX + _boatWidth - _boatWidth / 4, _startPosY);
|
||||||
|
// bodyPoints[2] = new PointF(_startPosX + _boatWidth, _startPosY + _boatHeight / 2);
|
||||||
|
// bodyPoints[3] = new PointF(_startPosX + _boatWidth - _boatWidth / 4, _startPosY + _boatHeight);
|
||||||
|
// bodyPoints[4] = new PointF(_startPosX, _startPosY + _boatHeight);
|
||||||
|
//
|
||||||
|
// // Отрисовка корпуса лодки
|
||||||
|
// g.FillPolygon(brush, bodyPoints);
|
||||||
|
// g.DrawPolygon(Pens.Black, bodyPoints);
|
||||||
|
//
|
||||||
|
// // Отрисовка головы лодки
|
||||||
|
// g.FillEllipse(Brushes.White, _startPosX + _boatWidth / 8, _startPosY + _boatHeight / 8,
|
||||||
|
// _boatWidth / 2, _boatHeight - _boatHeight / 4);
|
||||||
|
// g.DrawEllipse(Pens.Black, _startPosX + _boatWidth / 8, _startPosY + _boatHeight / 8,
|
||||||
|
// _boatWidth / 2, _boatHeight - _boatHeight / 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ChangeBorders(int width, int height) {
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
if (_pictureWidth <= _boatWidth || _pictureHeight <= _boatHeight) {
|
||||||
|
_pictureWidth = 0;
|
||||||
|
_pictureHeight = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (_startPosX + _boatWidth > _pictureWidth) {
|
||||||
|
_startPosX = _pictureWidth - _boatWidth;
|
||||||
|
}
|
||||||
|
if (_startPosY + _boatHeight > _pictureHeight) {
|
||||||
|
_startPosY = _pictureHeight - _boatHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
package src;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
142
src/FormBoat.form
Normal file
142
src/FormBoat.form
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="src.FormBoat">
|
||||||
|
<grid id="27dc6" binding="PanelWrapper" 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="500" height="400"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<grid id="5661e" binding="PictureBox" layout-manager="GridLayoutManager" row-count="2" 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="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>
|
||||||
|
<hspacer id="476ba">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" 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>
|
||||||
|
<vspacer id="c6a0e">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</vspacer>
|
||||||
|
<grid id="202f2" binding="PanelButtonsMove" layout-manager="GridLayoutManager" row-count="2" 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="2" 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="bf14c" class="javax.swing.JButton" binding="ButtonDown">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" 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>
|
||||||
|
<icon value="Resources/30px_arrow_down.png"/>
|
||||||
|
<label value=""/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="cbcd1" class="javax.swing.JButton" binding="ButtonUp">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" 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>
|
||||||
|
<icon value="Resources/30px_arrow_up.png"/>
|
||||||
|
<label value=""/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="ce3f1" class="javax.swing.JButton" binding="ButtonLeft">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" 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>
|
||||||
|
<icon value="Resources/30px_arrow_left.png"/>
|
||||||
|
<label value=""/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="3b5cd" class="javax.swing.JButton" binding="ButtonRight">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" 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>
|
||||||
|
<icon value="Resources/30px_arrow_right.png"/>
|
||||||
|
<label value=""/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<component id="9b1c5" class="javax.swing.JButton" binding="ButtonCreate">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="2" fill="0" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="80" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<text value="Создать"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<toolbar id="6a652" binding="StatusStrip">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="0" row-span="1" col-span="1" 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="81fb1" class="javax.swing.JLabel" binding="StatusStripLabelSpeed">
|
||||||
|
<constraints/>
|
||||||
|
<properties>
|
||||||
|
<foreground color="-16777216"/>
|
||||||
|
<text value="Скорость:"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="b564e" class="javax.swing.JLabel" binding="StatusStripLabelWeight">
|
||||||
|
<constraints/>
|
||||||
|
<properties>
|
||||||
|
<foreground color="-16777216"/>
|
||||||
|
<text value="Вес:"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="8492d" class="javax.swing.JLabel" binding="StatusStripLabelColor">
|
||||||
|
<constraints/>
|
||||||
|
<properties>
|
||||||
|
<foreground color="-16777216"/>
|
||||||
|
<text value="Цвет:"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</toolbar>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</form>
|
||||||
18
src/FormBoat.java
Normal file
18
src/FormBoat.java
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package src;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
public class FormBoat {
|
||||||
|
JPanel PanelWrapper;
|
||||||
|
private JPanel PictureBox;
|
||||||
|
private JToolBar StatusStrip;
|
||||||
|
private JLabel StatusStripLabelSpeed;
|
||||||
|
private JLabel StatusStripLabelWeight;
|
||||||
|
private JLabel StatusStripLabelColor;
|
||||||
|
private JButton ButtonCreate;
|
||||||
|
private JPanel PanelButtonsMove;
|
||||||
|
private JButton ButtonDown;
|
||||||
|
private JButton ButtonUp;
|
||||||
|
private JButton ButtonLeft;
|
||||||
|
private JButton ButtonRight;
|
||||||
|
}
|
||||||
16
src/Program.java
Normal file
16
src/Program.java
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package src;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
public class Program {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
JFrame.setDefaultLookAndFeelDecorated(false);
|
||||||
|
JFrame frame = new JFrame("Катамаран");
|
||||||
|
frame.setContentPane(new FormBoat().PanelWrapper);
|
||||||
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
frame.setLocation(500, 200);
|
||||||
|
frame.pack();
|
||||||
|
frame.setSize(1000, 500);
|
||||||
|
frame.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user