Compare commits

..

1 Commits

Author SHA1 Message Date
a879f47bfe Первая лабораторная работа. 2022-10-16 16:42:31 +04:00
12 changed files with 754 additions and 4 deletions

View File

@ -0,0 +1,31 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package AirBomberPackage;
import javax.swing.*;
import java.awt.*;
/**
*
* @author Андрей
*/
public class CanvasMy extends JComponent {
public CanvasMy(){
super();
}
private DrawingAirBomber _airBomber = null;
public void setAirBomber(DrawingAirBomber _airBomber) {
this._airBomber = _airBomber;
}
@Override
public void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
if (_airBomber != null) _airBomber.DrawTransport(g2d);
}
}

View File

@ -0,0 +1,16 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package AirBomberPackage;
/**
*
* @author Андрей
*/
public enum Direction {
UP,
DOWN,
LEFT,
RIGHT
}

View File

@ -0,0 +1,224 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package AirBomberPackage;
import java.awt.*;
import java.util.Random;
/**
*
* @author Андрей
*/
public class DrawingAirBomber {
private EntityAirBomber AirBomber;
public DrawingEngines drawingEngines;
public float _startPosX;
public float _startPosY;
private Integer _pictureWidth = null;
private Integer _pictureHeight = null;
private static final int _airBomberWidth = 110;
private static final int _airBomberHeight = 100;
public void Init(int speed, float weight, Color bodyColor, int numberOfEngines){
AirBomber = new EntityAirBomber();
drawingEngines = new DrawingEngines();
AirBomber.Init(speed, weight, bodyColor);
System.out.println(numberOfEngines + "");
drawingEngines.setNumberOfEngines(numberOfEngines);
}
public EntityAirBomber getAirBomber() {
return AirBomber;
}
public void SetPosition(int x, int y, int width, int height){
_pictureWidth = width;
_pictureHeight = height;
if (_pictureWidth == null || _pictureHeight == null)
{
return;
}
Random rd = new Random();
_startPosX = x + _airBomberWidth >= _pictureWidth ? rd.nextInt(0, _pictureWidth - 1 - _airBomberWidth) : x;
_startPosY = y + _airBomberHeight >= _pictureHeight ? rd.nextInt(0, _pictureHeight - 1 - _airBomberHeight) : y;
}
public void MoveTransport(Direction direction)
{
if (_pictureWidth == null || _pictureHeight == null)
{
return;
}
switch (direction)
{
// вправо
case RIGHT:
if (_startPosX + _airBomberWidth + AirBomber.Step < _pictureWidth)
{
_startPosX += AirBomber.Step;
}
break;
//влево
case LEFT:
if (_startPosX - AirBomber.Step > 0)
{
_startPosX -= AirBomber.Step;
}
break;
//вверх
case UP:
if (_startPosY - AirBomber.Step > 0)
{
_startPosY -= AirBomber.Step;
}
break;
//вниз
case DOWN:
if (_startPosY + _airBomberHeight + AirBomber.Step < _pictureHeight)
{
_startPosY += AirBomber.Step;
}
break;
}
}
public void DrawTransport(Graphics2D g)
{
if (_startPosX < 0 || _startPosY < 0
|| _pictureHeight == null || _pictureWidth == null)
{
return;
}
int _startPosXInt = (int)_startPosX;
int _startPosYInt = (int)_startPosY;
//отрисовка двигателей
drawingEngines.drawEngines(g, _startPosXInt, _startPosYInt, AirBomber.getBodyColor());
//отрисовка кабины
int[] cabinX =
{
_startPosXInt + 5,
_startPosXInt + 20,
_startPosXInt + 20
};
int[] cabinY =
{
_startPosYInt + 50,
_startPosYInt + 40,
_startPosYInt + 60
};
g.fillPolygon(cabinX, cabinY, cabinX.length);
g.setColor(AirBomber.getBodyColor());
//отрисовка корпуса
g.fillRect(_startPosXInt + 20, _startPosYInt + 40, 90, 20);
//отрисовка правого крыла
int[] rightWingX =
{
_startPosXInt + 50,
_startPosXInt + 50,
_startPosXInt + 60,
_startPosXInt + 70
};
int[] rightWingY =
{
_startPosYInt + 40,
_startPosYInt,
_startPosYInt,
_startPosYInt + 40
};
g.fillPolygon(rightWingX, rightWingY, rightWingX.length);
//отрисовка левого крыла
int[] leftWingX =
{
_startPosXInt + 50,
_startPosXInt + 50,
_startPosXInt + 60,
_startPosXInt + 70
};
int[] leftWingY =
{
_startPosYInt + 60,
_startPosYInt + 100,
_startPosYInt + 100,
_startPosYInt + 60
};
g.fillPolygon(leftWingX, leftWingY, leftWingX.length);
//отрисовка хвоста (справа)
int[] rightTailX =
{
_startPosXInt + 95,
_startPosXInt + 95,
_startPosXInt + 110,
_startPosXInt + 110
};
int[] rightTailY =
{
_startPosYInt + 40,
_startPosYInt + 30,
_startPosYInt + 15,
_startPosYInt + 40
};
g.fillPolygon(rightTailX, rightTailY, rightTailX.length);
//отрисовка хвоста (слева)
int[] leftTailX =
{
_startPosXInt + 95,
_startPosXInt + 95,
_startPosXInt + 110,
_startPosXInt + 110
};
int[] leftTailY =
{
_startPosYInt + 60,
_startPosYInt + 70,
_startPosYInt + 85,
_startPosYInt + 60
};
g.fillPolygon(leftTailX, leftTailY, leftTailX.length);
g.setColor(Color.BLACK);
g.drawRect(_startPosXInt + 20, _startPosYInt + 40, 90, 20);
g.drawPolygon(rightWingX, rightWingY, rightWingX.length);
g.drawPolygon(leftWingX, leftWingY, leftWingX.length);
g.drawPolygon(rightTailX, rightTailY, rightTailX.length);
g.drawPolygon(leftTailX, leftTailY, leftTailX.length);
g.drawLine(_startPosXInt, _startPosYInt + 50, _startPosXInt + 5, _startPosYInt + 50);
}
public void ChangeBorders(int width, int height)
{
_pictureWidth = width;
_pictureHeight = height;
if (_pictureWidth <= _airBomberWidth || _pictureHeight <= _airBomberHeight)
{
_pictureWidth = null;
_pictureHeight = null;
return;
}
if (_startPosX + _airBomberWidth > _pictureWidth)
{
_startPosX = _pictureWidth - _airBomberWidth;
}
if (_startPosY + _airBomberHeight > _pictureHeight)
{
_startPosY = _pictureHeight - _airBomberHeight;
}
}
}

View File

@ -0,0 +1,61 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package AirBomberPackage;
import java.awt.Graphics2D;
import java.awt.Color;
/**
*
* @author Андрей
*/
public class DrawingEngines {
private Engines engines = null;
private int numberOfEngines;
public int getNumberOfEngines() {
return numberOfEngines;
}
public void setNumberOfEngines(int numberOfEngines) {
if (numberOfEngines != 2 && numberOfEngines != 4 && numberOfEngines != 6) return;
this.numberOfEngines = numberOfEngines;
switch (this.numberOfEngines) {
case 2:
engines = Engines.TWO;
break;
case 4:
engines = Engines.FOUR;
break;
case 6:
engines = Engines.SIX;
break;
}
}
private void drawEngine(Graphics2D g, int startPosX, int startPosY, int yOffset, Color bodyColor){
g.setColor(bodyColor);
g.fillRect(startPosX + 45, startPosY + 40 + yOffset, 5, 5);
g.setColor(Color.BLACK);
g.drawRect(startPosX + 45, startPosY + 40 + yOffset, 5, 5);
}
public void drawEngines(Graphics2D g, int startPosX, int startPosY, Color bodyColor){
if (engines == null) return;
switch (engines) {
case SIX:
drawEngine(g, startPosX, startPosY, -5 - 5 - 20, bodyColor);
drawEngine(g, startPosX, startPosY, 20 + 5 + 20, bodyColor);
case FOUR:
drawEngine(g, startPosX, startPosY, -5 - 5 - 10, bodyColor);
drawEngine(g, startPosX, startPosY, 20 + 5 + 10, bodyColor);
case TWO:
drawEngine(g, startPosX, startPosY, -5 - 5, bodyColor);
drawEngine(g, startPosX, startPosY, 20 + 5, bodyColor);
break;
}
}
}

View File

@ -0,0 +1,15 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package AirBomberPackage;
/**
*
* @author Андрей
*/
public enum Engines {
TWO,
FOUR,
SIX
}

View File

@ -0,0 +1,43 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package AirBomberPackage;
import java.awt.Color;
import java.util.Random;
/**
*
* @author Андрей
*/
public class EntityAirBomber {
private int Speed;
private float Weight;
private Color BodyColor;
public float Step;
public int getSpeed() {
return Speed;
}
public float getWeight() {
return Weight;
}
public Color getBodyColor() {
return BodyColor;
}
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

@ -3,6 +3,16 @@
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo"> <Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<Properties> <Properties>
<Property name="defaultCloseOperation" type="int" value="3"/> <Property name="defaultCloseOperation" type="int" value="3"/>
<Property name="title" type="java.lang.String" value="&#x411;&#x43e;&#x43c;&#x431;&#x430;&#x440;&#x434;&#x438;&#x440;&#x43e;&#x432;&#x449;&#x438;&#x43a;"/>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Arial" size="10" style="0"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[700, 400]"/>
</Property>
<Property name="size" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[700, 400]"/>
</Property>
</Properties> </Properties>
<SyntheticProperties> <SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/> <SyntheticProperty name="formSizePolicy" type="int" value="1"/>
@ -23,13 +33,191 @@
<Layout> <Layout>
<DimensionLayout dim="0"> <DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="400" max="32767" attributes="0"/> <Component id="statusLabel" alignment="0" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabelEngines" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jComboBoxEngines" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="createAirBomberButton" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="369" max="32767" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Component id="upButton" alignment="1" min="-2" pref="30" max="-2" attributes="0"/>
<Group type="102" alignment="1" attributes="0">
<Component id="leftButton" min="-2" pref="30" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="downButton" min="-2" pref="30" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="rightButton" min="-2" pref="30" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="17" max="-2" attributes="0"/>
</Group>
<Component id="airBomberCanvas" alignment="0" max="32767" attributes="0"/>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
<DimensionLayout dim="1"> <DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="300" max="32767" attributes="0"/> <Group type="102" alignment="1" attributes="0">
<Component id="airBomberCanvas" pref="298" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabelEngines" alignment="3" min="-2" pref="31" max="-2" attributes="0"/>
<Component id="jComboBoxEngines" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="createAirBomberButton" min="-2" pref="31" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="1" attributes="0">
<Component id="upButton" min="-2" pref="31" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="leftButton" alignment="3" min="-2" pref="31" max="-2" attributes="0"/>
<Component id="downButton" alignment="3" min="-2" pref="31" max="-2" attributes="0"/>
<Component id="rightButton" alignment="3" min="-2" pref="31" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="statusLabel" min="-2" pref="22" max="-2" attributes="0"/>
</Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
</Layout> </Layout>
<SubComponents>
<Component class="javax.swing.JButton" name="createAirBomberButton">
<Properties>
<Property name="text" type="java.lang.String" value="&#x421;&#x43e;&#x437;&#x434;&#x430;&#x442;&#x44c;"/>
<Property name="name" type="java.lang.String" value="createAirBomberButton" noResource="true"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="createAirBomberButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="leftButton">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/AirBomberPackage/arrowLeft.png"/>
</Property>
<Property name="margin" type="java.awt.Insets" editor="org.netbeans.beaninfo.editors.InsetsEditor">
<Insets value="[0, 0, 0, 0]"/>
</Property>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[30, 30]"/>
</Property>
<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="buttonLeft" noResource="true"/>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[30, 30]"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="moveButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="downButton">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/AirBomberPackage/arrowDown.png"/>
</Property>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[30, 30]"/>
</Property>
<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="buttonDown" noResource="true"/>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[30, 30]"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="moveButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="rightButton">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/AirBomberPackage/arrowRight.png"/>
</Property>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[30, 30]"/>
</Property>
<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="buttonRight" noResource="true"/>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[30, 30]"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="moveButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="upButton">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/AirBomberPackage/arrowUp.png"/>
</Property>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[30, 30]"/>
</Property>
<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="buttonUp" noResource="true"/>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[30, 30]"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="moveButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="statusLabel">
<Properties>
<Property name="text" type="java.lang.String" value="&#x421;&#x43a;&#x43e;&#x440;&#x43e;&#x441;&#x442;&#x44c;: &#x412;&#x435;&#x441;: &#x426;&#x432;&#x435;&#x442;: &#x414;&#x432;&#x438;&#x433;&#x430;&#x442;&#x435;&#x43b;&#x438;:"/>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[0, 0]"/>
</Property>
</Properties>
</Component>
<Container class="AirBomberPackage.CanvasMy" name="airBomberCanvas">
<Events>
<EventHandler event="componentResized" listener="java.awt.event.ComponentListener" parameters="java.awt.event.ComponentEvent" handler="airBomberCanvasComponentResized"/>
</Events>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
<Property name="useNullLayout" type="boolean" value="true"/>
</Layout>
</Container>
<Component class="javax.swing.JLabel" name="jLabelEngines">
<Properties>
<Property name="text" type="java.lang.String" value="&#x41a;&#x43e;&#x43b;&#x438;&#x447;&#x435;&#x441;&#x442;&#x432;&#x43e; &#x434;&#x432;&#x438;&#x433;&#x430;&#x442;&#x435;&#x43b;&#x435;&#x439;: "/>
</Properties>
</Component>
<Component class="javax.swing.JComboBox" name="jComboBoxEngines">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="3">
<StringItem index="0" value="&#x414;&#x432;&#x430;"/>
<StringItem index="1" value="&#x427;&#x435;&#x442;&#x44b;&#x440;&#x435;"/>
<StringItem index="2" value="&#x428;&#x435;&#x441;&#x442;&#x44c;"/>
</StringArray>
</Property>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
</AuxValues>
</Component>
</SubComponents>
</Form> </Form>

View File

@ -3,6 +3,9 @@
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template * Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
*/ */
package AirBomberPackage; package AirBomberPackage;
import java.awt.*;
import javax.swing.*;
import java.util.Random;
/** /**
* *
@ -16,6 +19,8 @@ public class JFrameAirBomber extends javax.swing.JFrame {
public JFrameAirBomber() { public JFrameAirBomber() {
initComponents(); initComponents();
} }
private DrawingAirBomber _airBomber;
/** /**
* This method is called from within the constructor to initialize the form. * This method is called from within the constructor to initialize the form.
@ -26,22 +31,180 @@ public class JFrameAirBomber extends javax.swing.JFrame {
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() { private void initComponents() {
createAirBomberButton = new javax.swing.JButton();
leftButton = new javax.swing.JButton();
downButton = new javax.swing.JButton();
rightButton = new javax.swing.JButton();
upButton = new javax.swing.JButton();
statusLabel = new javax.swing.JLabel();
airBomberCanvas = new AirBomberPackage.CanvasMy();
jLabelEngines = new javax.swing.JLabel();
jComboBoxEngines = new javax.swing.JComboBox<>();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Бомбардировщик");
setFont(new java.awt.Font("Arial", 0, 10)); // NOI18N
setPreferredSize(new java.awt.Dimension(700, 400));
setSize(new java.awt.Dimension(700, 400));
createAirBomberButton.setText("Создать");
createAirBomberButton.setName("createAirBomberButton"); // NOI18N
createAirBomberButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
createAirBomberButtonActionPerformed(evt);
}
});
leftButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowLeft.png"))); // NOI18N
leftButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
leftButton.setMaximumSize(new java.awt.Dimension(30, 30));
leftButton.setMinimumSize(new java.awt.Dimension(30, 30));
leftButton.setName("buttonLeft"); // NOI18N
leftButton.setPreferredSize(new java.awt.Dimension(30, 30));
leftButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
moveButtonActionPerformed(evt);
}
});
downButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowDown.png"))); // NOI18N
downButton.setMaximumSize(new java.awt.Dimension(30, 30));
downButton.setMinimumSize(new java.awt.Dimension(30, 30));
downButton.setName("buttonDown"); // NOI18N
downButton.setPreferredSize(new java.awt.Dimension(30, 30));
downButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
moveButtonActionPerformed(evt);
}
});
rightButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowRight.png"))); // NOI18N
rightButton.setMaximumSize(new java.awt.Dimension(30, 30));
rightButton.setMinimumSize(new java.awt.Dimension(30, 30));
rightButton.setName("buttonRight"); // NOI18N
rightButton.setPreferredSize(new java.awt.Dimension(30, 30));
rightButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
moveButtonActionPerformed(evt);
}
});
upButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowUp.png"))); // NOI18N
upButton.setMaximumSize(new java.awt.Dimension(30, 30));
upButton.setMinimumSize(new java.awt.Dimension(30, 30));
upButton.setName("buttonUp"); // NOI18N
upButton.setPreferredSize(new java.awt.Dimension(30, 30));
upButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
moveButtonActionPerformed(evt);
}
});
statusLabel.setText("Скорость: Вес: Цвет: Двигатели:");
statusLabel.setMinimumSize(new java.awt.Dimension(0, 0));
airBomberCanvas.addComponentListener(new java.awt.event.ComponentAdapter() {
public void componentResized(java.awt.event.ComponentEvent evt) {
airBomberCanvasComponentResized(evt);
}
});
jLabelEngines.setText("Количество двигателей: ");
jComboBoxEngines.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Два", "Четыре", "Шесть" }));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout); getContentPane().setLayout(layout);
layout.setHorizontalGroup( layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE) .addComponent(statusLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabelEngines)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jComboBoxEngines, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(createAirBomberButton))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 369, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(upButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(leftButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(downButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(rightButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(17, 17, 17))
.addComponent(airBomberCanvas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
); );
layout.setVerticalGroup( layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(airBomberCanvas, javax.swing.GroupLayout.DEFAULT_SIZE, 298, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabelEngines, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jComboBoxEngines, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(createAirBomberButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(upButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(leftButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(downButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(rightButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(statusLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
); );
pack(); pack();
}// </editor-fold>//GEN-END:initComponents }// </editor-fold>//GEN-END:initComponents
private void createAirBomberButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createAirBomberButtonActionPerformed
Random rnd = new Random();
_airBomber = new DrawingAirBomber();
_airBomber.Init(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)), (jComboBoxEngines.getSelectedIndex() + 1) * 2);
System.out.println(((jComboBoxEngines.getSelectedIndex() + 1) * 2) + "");
_airBomber.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100), airBomberCanvas.getWidth(), airBomberCanvas.getHeight());
statusLabel.setText("Скорость: " + _airBomber.getAirBomber().getSpeed() + " Вес: " + (int) _airBomber.getAirBomber().getWeight() + " Цвет: " + _airBomber.getAirBomber().getBodyColor() + " Двигатели: " + _airBomber.drawingEngines.getNumberOfEngines());
airBomberCanvas.setAirBomber(_airBomber);
Draw();
}//GEN-LAST:event_createAirBomberButtonActionPerformed
private void moveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveButtonActionPerformed
if (_airBomber == null) return;
String name = ((JButton) evt.getSource()).getName();
switch (name)
{
case "buttonUp":
_airBomber.MoveTransport(Direction.UP);
break;
case "buttonDown":
_airBomber.MoveTransport(Direction.DOWN);
break;
case "buttonLeft":
_airBomber.MoveTransport(Direction.LEFT);
break;
case "buttonRight":
_airBomber.MoveTransport(Direction.RIGHT);
break;
}
Draw();
}//GEN-LAST:event_moveButtonActionPerformed
private void airBomberCanvasComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_airBomberCanvasComponentResized
if (_airBomber == null) return;
_airBomber.ChangeBorders(airBomberCanvas.getWidth(), airBomberCanvas.getHeight());
}//GEN-LAST:event_airBomberCanvasComponentResized
private void Draw(){
airBomberCanvas.repaint();
}
/** /**
* @param args the command line arguments * @param args the command line arguments
*/ */
@ -78,5 +241,14 @@ public class JFrameAirBomber extends javax.swing.JFrame {
} }
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private AirBomberPackage.CanvasMy airBomberCanvas;
private javax.swing.JButton createAirBomberButton;
private javax.swing.JButton downButton;
private javax.swing.JComboBox<String> jComboBoxEngines;
private javax.swing.JLabel jLabelEngines;
private javax.swing.JButton leftButton;
private javax.swing.JButton rightButton;
private javax.swing.JLabel statusLabel;
private javax.swing.JButton upButton;
// End of variables declaration//GEN-END:variables // End of variables declaration//GEN-END:variables
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 565 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 612 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 619 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 546 B