Compare commits

...

4 Commits

7 changed files with 733 additions and 0 deletions

View File

@ -0,0 +1,36 @@
import java.awt.Color;
import java.util.Random;
class ArmoredVehicleEntity {
/// <summary>
/// Скорость
/// </summary>
public int Speed;
/// <summary>
/// Вес
/// </summary>
public float Weight;
/// <summary>
/// Цвет
/// </summary>
public Color BodyColor;
/// <summary>
/// Шаг перемещения
/// </summary>
public float Step;
/// <summary>
/// Инициализация полей объекта-класса
/// </summary>
/// <param name="speed"></param>
/// <param name="weight"></param>
/// <param name="bodyColor"></param>
/// <returns></returns>
public void Init(int speed, float weight, Color bodyColor)
{
Random rnd = new Random();
Speed = speed <= 0 ? rnd.nextInt(50, 150) : speed;
Weight = weight <= 0 ? rnd.nextInt(40, 70) : weight;
Step = Speed * 100 / Weight;
BodyColor = bodyColor;
}
}

View File

@ -0,0 +1,6 @@
public enum CountRollers {
Four,
Five,
Six
}

View File

@ -0,0 +1,8 @@
public enum Direction {
Up,
Down,
Left,
Right;
}

View File

@ -0,0 +1,198 @@
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.Random;
import javax.swing.JPanel;
public class DrawingArmoredVehicle extends JPanel{
/// <summary>
/// Класс-сущность
/// </summary>
public ArmoredVehicleEntity ArmoredVehicle;
/// <summary>
/// Левая координата отрисовки
/// </summary>
private float _startPosX;
/// <summary>
/// Верхняя кооридната отрисовки
/// </summary>
private float _startPosY;
/// <summary>
/// Ширина окна отрисовки
/// </summary>
private int _pictureWidth = 0;
/// <summary>
/// Высота окна отрисовки
/// </summary>
private int _pictureHeight = 0;
/// <summary>
/// Ширина отрисовки
/// </summary>
private int _ArmoredVehicleWidth = 210;
/// <summary>
/// Высота отрисовки
/// </summary>
private int _ArmoredVehicleHeight = 50;
/// <summary>
/// Инициализация свойств
/// </summary>
private Roller rolls = new Roller();;
Random rnd = new Random();
public int Count;
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес </param>
/// <param name="bodyColor">Цвет</param>
public void Init(int speed, float weight, Color bodyColor)
{
ArmoredVehicle = new ArmoredVehicleEntity();
ArmoredVehicle.Init(speed, weight, bodyColor);
Count = 6 - rnd.nextInt(0, 3);
}
/// <summary>
/// Установка позиции
/// </summary>
/// <param name="x">Координата X</param>
/// <param name="y">Координата Y</param>
/// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param>
public void SetPosition(int x, int y, int width, int height)
{
if(x > 0 && x < width)
{
_startPosX = x;
}
else
{
_startPosX = 0;
}
if(y > 20 && y < height)
{
_startPosY = y;
}
else
{
_startPosY = 0;
}
if(width >= _ArmoredVehicleWidth && height >= _ArmoredVehicleHeight)
{
_pictureWidth = width;
_pictureHeight = height;
}
repaint();
}
/// <summary>
/// Изменение направления пермещения
/// </summary>
/// <param name="direction">Направление</param>
public void MoveTransport(Direction direction)
{
if (_pictureWidth == 0 || _pictureHeight == 0)
{
return;
}
switch (direction)
{
// вправо
case Right:
if (_startPosX + _ArmoredVehicleWidth + ArmoredVehicle.Step < _pictureWidth)
{
_startPosX += ArmoredVehicle.Step;
}
break;
//влево
case Left:
if (_startPosX - ArmoredVehicle.Step > 0)
{
_startPosX -= ArmoredVehicle.Step;
}
break;
//вверх
case Up:
if (_startPosY - ArmoredVehicle.Step > 0)
{
_startPosY -= ArmoredVehicle.Step;
}
break;
//вниз
case Down:
if (_startPosY + _ArmoredVehicleHeight + ArmoredVehicle.Step < _pictureHeight)
{
_startPosY += ArmoredVehicle.Step;
}
break;
}
super.repaint();
}
/// <summary>
/// Отрисовка
/// </summary>
/// <param name="g"></param>
@Override
public void paint(Graphics gr) {
if (_startPosX < 0 || _startPosY < 0
|| _pictureHeight==0 || _pictureWidth==0)
{
return;
}
gr.clearRect(0, 0, _pictureHeight+500, _pictureWidth+500);
super.paintComponent(gr);
Graphics2D g = (Graphics2D) gr;
Color color = ArmoredVehicle.BodyColor != null ?
ArmoredVehicle.BodyColor : Color.BLACK;
g.setColor(color);
g.fillRect((int)_startPosX + 50, (int)_startPosY, 100, 40);
g.fillRect((int)_startPosX + 15, (int)_startPosY+20, 200, 20);
//контур
g.drawRect((int)_startPosX + 50, (int)_startPosY, 100, 20);
g.drawRect((int)_startPosX + 15, (int)_startPosY+20, 200, 20);
g.drawOval((int)_startPosX + 15, (int)_startPosY + 25, 200, 35);
rolls.Init(Count, color, _startPosX, _startPosY, _ArmoredVehicleWidth);
rolls.paint(gr);
super.repaint();
g.dispose();
}
/// <summary>
/// Смена границ формы отрисовки
/// </summary>
/// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param>
public void ChangeBorders(int width, int height)
{
_pictureWidth = width;
_pictureHeight = height;
if (_pictureWidth <= _ArmoredVehicleWidth || _pictureHeight <= _ArmoredVehicleHeight)
{
_pictureWidth = 0;
_pictureHeight = 0;
return;
}
if (_startPosX + _ArmoredVehicleWidth > _pictureWidth)
{
_startPosX = _pictureWidth - _ArmoredVehicleWidth;
}
if (_startPosY + _ArmoredVehicleHeight > _pictureHeight)
{
_startPosY = _pictureHeight - _ArmoredVehicleHeight;
}
super.repaint();
}
}

View File

@ -0,0 +1,164 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.9" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="3"/>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[444, 303]"/>
</Property>
<Property name="name" type="java.lang.String" value="MainFrame" noResource="true"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="444" max="32767" attributes="0"/>
<Group type="103" rootIndex="1" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="DrawPanel" pref="438" max="32767" attributes="0"/>
</Group>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="309" max="32767" attributes="0"/>
<Group type="103" rootIndex="1" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="32767" attributes="0"/>
<Component id="DrawPanel" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JPanel" name="DrawPanel">
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new javax.swing.JPanel(){&#xa; Graphics2D g2;}"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
<SubComponents>
<Component class="java.awt.TextField" name="PropertyText">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="4" gridWidth="2" gridHeight="1" fill="0" ipadX="322" ipadY="0" insetsTop="10" insetsLeft="0" insetsBottom="10" insetsRight="0" anchor="18" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="java.awt.Button" name="CreateButton">
<Properties>
<Property name="actionCommand" type="java.lang.String" value="Create"/>
<Property name="label" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="&quot;&#x421;&#x43e;&#x437;&#x434;&#x430;&#x442;&#x44c;&quot;" type="code"/>
</Property>
<Property name="name" type="java.lang.String" value="CreateButton" noResource="true"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="CreateButtonMouseClicked"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="2" gridWidth="1" gridHeight="2" fill="0" ipadX="67" ipadY="0" insetsTop="13" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="18" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="java.awt.Button" name="UpButton">
<Properties>
<Property name="actionCommand" type="java.lang.String" value="Up"/>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Default Cursor"/>
</Property>
<Property name="label" type="java.lang.String" value="&#x2191;"/>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[30, 30]"/>
</Property>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="UpButtonMouseClicked"/>
</Events>
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new java.awt.Button()"/>
<AuxValue name="JavaCodeGenerator_CreateCodePre" type="java.lang.String" value="ImageIcon arrowUp = new ImageIcon(&quot;C:\\Users\\Alena\\Desktop\\New Folder\\JavaApplication4\\src\\Resources\\arrowUp.jpg&quot;);"/>
</AuxValues>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="4" gridY="0" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="160" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="18" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="java.awt.Button" name="LeftButton">
<Properties>
<Property name="actionCommand" type="java.lang.String" value="Left"/>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[30, 30]"/>
</Property>
<Property name="name" type="java.lang.String" value="LeftButton" noResource="true"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="LeftButtonMouseClicked"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="1" gridY="1" gridWidth="3" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="227" insetsBottom="0" insetsRight="0" anchor="18" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="java.awt.Button" name="DownButton">
<Properties>
<Property name="actionCommand" type="java.lang.String" value="Left"/>
<Property name="label" type="java.lang.String" value="&#x2193;"/>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[30, 30]"/>
</Property>
<Property name="name" type="java.lang.String" value="LeftButton" noResource="true"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="DownButtonMouseClicked"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="4" gridY="2" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="18" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="java.awt.Button" name="RightButton">
<Properties>
<Property name="actionCommand" type="java.lang.String" value="Right"/>
<Property name="label" type="java.lang.String" value="&#x2192;"/>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[30, 30]"/>
</Property>
<Property name="name" type="java.lang.String" value="RightButton" noResource="true"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="RightButtonMouseClicked"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="5" gridY="1" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="32" anchor="18" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Form>

View File

@ -0,0 +1,247 @@
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.Random;
import javax.swing.ImageIcon;
public class MainForm extends javax.swing.JFrame {
private DrawingArmoredVehicle _ArmoredVehicle = new DrawingArmoredVehicle();;
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints;
DrawPanel = new javax.swing.JPanel(){
Graphics2D g2;};
PropertyText = new java.awt.TextField();
CreateButton = new java.awt.Button();
ImageIcon arrowUp = new ImageIcon("C:\\Users\\Alena\\Desktop\\New Folder\\JavaApplication4\\src\\Resources\\arrowUp.jpg");
UpButton = new java.awt.Button();
LeftButton = new java.awt.Button();
DownButton = new java.awt.Button();
RightButton = new java.awt.Button();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setMinimumSize(new java.awt.Dimension(444, 303));
setName("MainFrame"); // NOI18N
DrawPanel.setLayout(new java.awt.GridBagLayout());
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 4;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.ipadx = 322;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(10, 0, 10, 0);
DrawPanel.add(PropertyText, gridBagConstraints);
CreateButton.setActionCommand("Create");
CreateButton.setLabel("Создать");
CreateButton.setName("CreateButton"); // NOI18N
CreateButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
CreateButtonMouseClicked(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2;
gridBagConstraints.gridheight = 2;
gridBagConstraints.ipadx = 67;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(13, 0, 0, 0);
DrawPanel.add(CreateButton, gridBagConstraints);
UpButton.setActionCommand("Up");
UpButton.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
UpButton.setLabel("");
UpButton.setMinimumSize(new java.awt.Dimension(30, 30));
UpButton.setPreferredSize(new java.awt.Dimension(30, 30));
UpButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
UpButtonMouseClicked(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 4;
gridBagConstraints.gridy = 0;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(160, 0, 0, 0);
DrawPanel.add(UpButton, gridBagConstraints);
LeftButton.setActionCommand("Left");
LeftButton.setMinimumSize(new java.awt.Dimension(30, 30));
LeftButton.setName("LeftButton"); // NOI18N
LeftButton.setPreferredSize(new java.awt.Dimension(30, 30));
LeftButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
LeftButtonMouseClicked(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 1;
gridBagConstraints.gridwidth = 3;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(0, 227, 0, 0);
DrawPanel.add(LeftButton, gridBagConstraints);
DownButton.setActionCommand("Left");
DownButton.setLabel("");
DownButton.setMinimumSize(new java.awt.Dimension(30, 30));
DownButton.setName("LeftButton"); // NOI18N
DownButton.setPreferredSize(new java.awt.Dimension(30, 30));
DownButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
DownButtonMouseClicked(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 4;
gridBagConstraints.gridy = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
DrawPanel.add(DownButton, gridBagConstraints);
RightButton.setActionCommand("Right");
RightButton.setLabel("");
RightButton.setMinimumSize(new java.awt.Dimension(30, 30));
RightButton.setName("RightButton"); // NOI18N
RightButton.setPreferredSize(new java.awt.Dimension(30, 30));
RightButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
RightButtonMouseClicked(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 5;
gridBagConstraints.gridy = 1;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 32);
DrawPanel.add(RightButton, gridBagConstraints);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 444, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(DrawPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 438, Short.MAX_VALUE)))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 309, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(DrawPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap()))
);
pack();
}// </editor-fold>//GEN-END:initComponents
public MainForm() {
initComponents();
LeftButton.setLabel("<");
RightButton.setLabel(">");
UpButton.setLabel("/\\");
DownButton.setLabel("\\/");
}
private void CreateButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_CreateButtonMouseClicked
Random rnd = new Random();
_ArmoredVehicle.Init(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)));
_ArmoredVehicle.SetPosition(rnd.nextInt(0, 100), rnd.nextInt(25, 200),
DrawPanel.getWidth(), DrawPanel.getHeight());
PropertyText.setText("Скорость: " + _ArmoredVehicle.ArmoredVehicle.Speed +
" Вес: "+_ArmoredVehicle.ArmoredVehicle.Weight +
" Цвет: "+_ArmoredVehicle.ArmoredVehicle.BodyColor.getRGB()+
" Катков: "+_ArmoredVehicle.Count);
Draw();
}//GEN-LAST:event_CreateButtonMouseClicked
public void Move(String name)
{
switch (name)
{
case "UpButton" -> _ArmoredVehicle.MoveTransport(Direction.Up);
case "DownButton" -> _ArmoredVehicle.MoveTransport(Direction.Down);
case "LeftButton" -> _ArmoredVehicle.MoveTransport(Direction.Left);
case "RightButton" -> _ArmoredVehicle.MoveTransport(Direction.Right);
}
Draw();
}
private void UpButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_UpButtonMouseClicked
Move("UpButton");
}//GEN-LAST:event_UpButtonMouseClicked
private void LeftButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_LeftButtonMouseClicked
Move("LeftButton");
}//GEN-LAST:event_LeftButtonMouseClicked
private void RightButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_RightButtonMouseClicked
Move("RightButton");
}//GEN-LAST:event_RightButtonMouseClicked
private void DownButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_DownButtonMouseClicked
Move("DownButton");
}//GEN-LAST:event_DownButtonMouseClicked
public static void main(String args[]) {
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MainForm().setVisible(true);
}
});
}
private void Draw()
{
Graphics gr = getGraphics();
_ArmoredVehicle.paint(gr);
gr.dispose();
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private java.awt.Button CreateButton;
private java.awt.Button DownButton;
private javax.swing.JPanel DrawPanel;
private java.awt.Button LeftButton;
private java.awt.TextField PropertyText;
private java.awt.Button RightButton;
private java.awt.Button UpButton;
// End of variables declaration//GEN-END:variables
}

View File

@ -0,0 +1,74 @@
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JPanel;
public class Roller extends JPanel{
/// <summary>
/// Количество катоков
/// </summary>
public int _count;
/// <summary>
/// Цвет
/// </summary>
private Color _color;
/// <summary>
/// Левая координата отрисовки
/// </summary>
private float _startPosX;
/// <summary>
/// Верхняя кооридната отрисовки
/// </summary>
private float _startPosY;
/// <summary>
/// Ширина поля под катки
/// </summary>
private float _Width;
/// <summary>
/// Перечисление
/// </summary>
private CountRollers rolls;
public void Init(int Count, Color color, float startPosX, float startPosY, float Width)
{
_count = Count;
_color = color;
_startPosX = startPosX;
_startPosY = startPosY;
_Width = Width;
Count(_count);
}
private void Count(int c)
{
switch (c)
{
case 4 -> rolls = CountRollers.Four;
case 5 -> rolls = CountRollers.Five;
case 6 -> rolls = CountRollers.Six;
}
}
public void paint(Graphics gr)
{
Graphics2D g = (Graphics2D) gr;
Color color = _color != null ?
_color : Color.BLACK;
g.setColor(color);
//g.setColor(Color.BLUE);
int count = 0;
switch (rolls)
{
case Four -> count = 4;
case Five -> count = 5;
case Six -> count = 6;
}
int ras = (int)_Width /count;
for (int i = 0; i < count; i += 1)
{
g.drawOval((int)_startPosX+ i*ras + 15, (int)_startPosY + 35, 20, 20);
}
g.dispose();
}
}