Abazov A. A. LabWork#1 #1
31
AirBomber/src/AirBomberPackage/CanvasMy.java
Normal file
31
AirBomber/src/AirBomberPackage/CanvasMy.java
Normal 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);
|
||||
}
|
||||
}
|
16
AirBomber/src/AirBomberPackage/Direction.java
Normal file
16
AirBomber/src/AirBomberPackage/Direction.java
Normal 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
|
||||
}
|
224
AirBomber/src/AirBomberPackage/DrawingAirBomber.java
Normal file
224
AirBomber/src/AirBomberPackage/DrawingAirBomber.java
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
61
AirBomber/src/AirBomberPackage/DrawingEngines.java
Normal file
61
AirBomber/src/AirBomberPackage/DrawingEngines.java
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
15
AirBomber/src/AirBomberPackage/Engines.java
Normal file
15
AirBomber/src/AirBomberPackage/Engines.java
Normal 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
|
||||
}
|
43
AirBomber/src/AirBomberPackage/EntityAirBomber.java
Normal file
43
AirBomber/src/AirBomberPackage/EntityAirBomber.java
Normal 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;
|
||||
}
|
||||
}
|
@ -3,6 +3,16 @@
|
||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
|
||||
<Properties>
|
||||
<Property name="defaultCloseOperation" type="int" value="3"/>
|
||||
<Property name="title" type="java.lang.String" value="Бомбардировщик"/>
|
||||
<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>
|
||||
<SyntheticProperties>
|
||||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
|
||||
@ -23,13 +33,191 @@
|
||||
<Layout>
|
||||
<DimensionLayout dim="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>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<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>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JButton" name="createAirBomberButton">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Создать"/>
|
||||
<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="Скорость: Вес: Цвет: Двигатели:"/>
|
||||
<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="Количество двигателей: "/>
|
||||
</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="Два"/>
|
||||
<StringItem index="1" value="Четыре"/>
|
||||
<StringItem index="2" value="Шесть"/>
|
||||
</StringArray>
|
||||
</Property>
|
||||
</Properties>
|
||||
<AuxValues>
|
||||
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="<String>"/>
|
||||
</AuxValues>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Form>
|
||||
|
@ -3,6 +3,9 @@
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
|
||||
*/
|
||||
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() {
|
||||
initComponents();
|
||||
}
|
||||
|
||||
private DrawingAirBomber _airBomber;
|
||||
|
||||
/**
|
||||
* 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
|
||||
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);
|
||||
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());
|
||||
getContentPane().setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
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.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();
|
||||
}// </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
|
||||
*/
|
||||
@ -78,5 +241,14 @@ public class JFrameAirBomber extends javax.swing.JFrame {
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
BIN
AirBomber/src/AirBomberPackage/arrowDown.png
Normal file
BIN
AirBomber/src/AirBomberPackage/arrowDown.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 565 B |
BIN
AirBomber/src/AirBomberPackage/arrowLeft.png
Normal file
BIN
AirBomber/src/AirBomberPackage/arrowLeft.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 612 B |
BIN
AirBomber/src/AirBomberPackage/arrowRight.png
Normal file
BIN
AirBomber/src/AirBomberPackage/arrowRight.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 619 B |
BIN
AirBomber/src/AirBomberPackage/arrowUp.png
Normal file
BIN
AirBomber/src/AirBomberPackage/arrowUp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 546 B |
Loading…
Reference in New Issue
Block a user