PIBD-13_Fomichev_V.S._LabWork01_Hard #1

Closed
slavaxom9k wants to merge 5 commits from labwork01 into main
24 changed files with 605 additions and 0 deletions

3
.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

9
.idea/PIBD-13_Fomichev_V.S._Hard.iml generated Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/misc.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_18" default="true" project-jdk-name="corretto-18" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/PIBD-13_Fomichev_V.S._Hard.iml" filepath="$PROJECT_DIR$/.idea/PIBD-13_Fomichev_V.S._Hard.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

29
ProjectAntiAircraftGun/.gitignore vendored Normal file
View File

@ -0,0 +1,29 @@
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

3
ProjectAntiAircraftGun/.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

6
ProjectAntiAircraftGun/.idea/misc.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_18" default="true" project-jdk-name="corretto-18" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/ProjectAntiAircraftGun.iml" filepath="$PROJECT_DIR$/ProjectAntiAircraftGun.iml" />
</modules>
</component>
</project>

View File

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

6
ProjectAntiAircraftGun/.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,15 @@
import javax.swing.*;
import java.awt.*;
public class CanvasAntiAircraftGun extends JComponent {
public DrawningAntiAircraftGun _drawingAntiAircraftGun;
public CanvasAntiAircraftGun(){}
public void paintComponent(Graphics g) {
if (_drawingAntiAircraftGun == null) {
return;
}
super.paintComponents(g);
Graphics2D g2d = (Graphics2D) g;
_drawingAntiAircraftGun.DrawTransport(g2d);
super.repaint();
}
}

View File

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

View File

@ -0,0 +1,6 @@
public enum DirectionType {
Up,
Down,
Left,
Right
}

View File

@ -0,0 +1,153 @@
import javax.swing.*;
import java.awt.*;
import java.util.Random;
public class DrawningAntiAircraftGun extends JPanel{
public EntityAntiAircraftGun EntityAntiAircraftGun;
public DrawningRollers _rollers = null;
private Integer picture_width;
private Integer picture_height;
private Integer _StartPosX;
private Integer _StartPosY;
private int drawningCarWidth = 120;
private int drawningCarHeight = 90;
public void Init(int speed, double weight, Color bodycolor, Color additionalcolor, boolean tower, boolean radar) {
EntityAntiAircraftGun = new EntityAntiAircraftGun();
EntityAntiAircraftGun.Init(speed, weight, bodycolor, additionalcolor, tower, radar);
picture_width = null;
picture_height = null;
_StartPosX = null;
_StartPosY = null;
_rollers = new DrawningRollers();
Random rand = new Random();
int randomNum = rand.nextInt(4);
_rollers.SetCount(randomNum);
}
public boolean SetPictureSize(int width, int height) {
if (width < drawningCarWidth || height < drawningCarHeight) return false;
picture_width = width;
picture_height = height;
if (_StartPosX != null || _StartPosY != null) {
if (_StartPosX + drawningCarWidth > picture_width)
{
_StartPosX = _StartPosX - (_StartPosX + drawningCarWidth - picture_width);
}
else if (_StartPosX < 0) _StartPosX = 0;
if (_StartPosY + drawningCarHeight > picture_height)
{
_StartPosY = _StartPosY - (_StartPosY + drawningCarHeight - picture_height);
}
else if (_StartPosY < 0) _StartPosY = 0;
}
return true;
}
public void SetPosition(int x, int y) {
if (!(picture_width != null && picture_height != null)) return;
if (x + drawningCarWidth > picture_width)
{
_StartPosX = x - (x + drawningCarWidth - picture_width);
}
else if (x < 0) _StartPosX = 0;
else _StartPosX = x;
if (y + drawningCarHeight > picture_height)
{
_StartPosY = y - (y + drawningCarHeight - picture_height);
}
else if (y < 0) _StartPosY = 0;
else _StartPosY = y;
}
public boolean MoveTransport(DirectionType direction) {
if (EntityAntiAircraftGun == null || _StartPosX == null || _StartPosY == null) return false;
switch (direction) {
case Left:
if (_StartPosX - EntityAntiAircraftGun.Step > 0) {
_StartPosX -= (int)EntityAntiAircraftGun.Step;
}
return true;
case Up:
if (_StartPosY - EntityAntiAircraftGun.Step > 0)
{
_StartPosY -= (int)EntityAntiAircraftGun.Step;
}
return true;
case Right:
if (_StartPosX + drawningCarWidth + (int)EntityAntiAircraftGun.Step < picture_width - EntityAntiAircraftGun.Step)
{
_StartPosX += (int)EntityAntiAircraftGun.Step;
}
return true;
case Down:
if (_StartPosY + drawningCarHeight + (int)EntityAntiAircraftGun.Step < picture_height - EntityAntiAircraftGun.Step)
{
_StartPosY += (int)EntityAntiAircraftGun.Step;
}
return true;
default:
return false;
}
}
public void DrawTransport(Graphics2D g) {
if (EntityAntiAircraftGun == null ) {
return;
}
;
g.drawOval(_StartPosX + 10, _StartPosY + 75, 30, 30);
g.drawOval(_StartPosX + 100, _StartPosY + 75, 30, 30);
g.drawRect(_StartPosX + 25, _StartPosY + 75, 90, 30);
//границы цвет
g.setColor(EntityAntiAircraftGun.getBodyColor());
g.fillRect(_StartPosX + 35, _StartPosY + 40, 35, 30);
g.fillOval(_StartPosX + 10, _StartPosY + 75, 30, 30);
g.fillOval(_StartPosX + 100, _StartPosY+ 75, 30, 30);
g.fillRect(_StartPosX+ 25, _StartPosY + 75, 90, 30);
// границы арт. установки
g.setColor(Color.BLACK);
g.drawRect(_StartPosX+ 35, _StartPosY + 40, 35, 30);
g.drawRect(_StartPosX+ 10, _StartPosY + 65, 120, 13);
//Большие катки ЦВЕТ
g.setColor(Color.GRAY);
g.fillOval(_StartPosX + 13, _StartPosY + 78, 24, 24);
g.fillOval( _StartPosX + 103, _StartPosY + 78, 24, 24);
//Большие катки ОТРИСОВКА
g.setColor(Color.BLACK);
g.drawOval( _StartPosX + 13, _StartPosY + 78, 24, 24);
g.drawOval( _StartPosX + 103, _StartPosY + 78, 24, 24);
g.setColor(EntityAntiAircraftGun.getBodyColor());
g.fillRect(_StartPosX + 10, _StartPosY+ 65, 120, 13);
_rollers.Draw(g,_StartPosX, _StartPosY);
//отрисовки башни
if (EntityAntiAircraftGun.getIsTower())
{
g.setColor(EntityAntiAircraftGun.getAdditionalColor());
g.fillRect(_StartPosX + 35, _StartPosY+ 50, 35, 15);
g.setColor(Color.BLACK);
g.drawRect(_StartPosX + 35, _StartPosY + 50, 35, 15);
g.drawLine(_StartPosX + 45, _StartPosY + 50, _StartPosX + 90, _StartPosY + 20);
g.drawLine( _StartPosX + 60, _StartPosY + 50, _StartPosX + 95, _StartPosY + 27);
g.drawLine( _StartPosX + 45, _StartPosY + 50, _StartPosX + 60, _StartPosY + 50);
g.drawLine( _StartPosX + 90, _StartPosY + 20, _StartPosX + 95, _StartPosY + 27);
g.drawLine( _StartPosX + 90, _StartPosY + 20, _StartPosX + 100, _StartPosY + 20);
g.drawLine( _StartPosX + 100, _StartPosY + 20, _StartPosX + 95, _StartPosY + 27);
}
//отрисовка радара
if (EntityAntiAircraftGun.getIsRadar())
{;
g.drawLine(_StartPosX + 20, _StartPosY + 65, _StartPosX + 20, _StartPosY + 40);
g.drawRect( _StartPosX + 10, _StartPosY + 20, 20, 20);
g.setColor(EntityAntiAircraftGun.getAdditionalColor());
g.fillRect(_StartPosX + 10, _StartPosY + 20, 20, 20);
}
}
}

View File

@ -0,0 +1,52 @@
import java.awt.*;
public class DrawningRollers {
private CountRollers _rollers;
public CountRollers getCount() {
return _rollers;
}
public void SetCount(int count) {
switch (count) {
case 1: // 4
_rollers = CountRollers.Four;
break;
case 2: // 5
_rollers = CountRollers.Five;
break;
case 3: // 6
_rollers = CountRollers.Six;
break;
default:
_rollers = CountRollers.Four;
break;
}
}
public void Draw(Graphics2D g, int _StartPosX, int _StartPosY) {
g.setColor(Color.BLACK);
if (_rollers == null) {
return;
}
//нижние катки ЦВЕТ
g.setColor(Color.GRAY);
g.fillOval(_StartPosX + 40, _StartPosY + 90, 15, 15);
g.fillOval(_StartPosX + 55, _StartPosY + 90, 15, 15);
if (_rollers != CountRollers.Four) {
g.fillOval(_StartPosX + 70, _StartPosY + 90, 15, 15);
}
if (_rollers == CountRollers.Six) {
g.fillOval(_StartPosX + 85, _StartPosY + 90, 15, 15);
}
//нижние катки ОТРИСОВКА
g.setColor(Color.BLACK);
g.drawOval(_StartPosX + 40, _StartPosY + 90, 15, 15);
g.drawOval( _StartPosX + 55, _StartPosY + 90, 15, 15);
if (_rollers != CountRollers.Four) {
g.drawOval( _StartPosX+ 70, _StartPosY + 90, 15, 15);
}
if (_rollers == CountRollers.Six) {
g.drawOval(_StartPosX + 85, _StartPosY + 90, 15, 15);
}
}
}

View File

@ -0,0 +1,24 @@
import java.awt.*;
public class EntityAntiAircraftGun {
private int Speed;
private double Weight;
private Color BodyColor;
public Color getBodyColor() {return BodyColor;}
private Color AdditionalColor;
public Color getAdditionalColor() {return AdditionalColor;}
private boolean IsTower;
public boolean getIsTower() {return IsTower;}
private boolean IsRadar;
public boolean getIsRadar() {return IsRadar;}
public double Step;
public void Init(int speed, double weight, Color bodycolor, Color additionalcolor, boolean isTower, boolean isRadar)
{
Speed = speed;
Weight = weight;
BodyColor = bodycolor;
AdditionalColor = additionalcolor;
IsTower = isTower;
IsRadar = isRadar;
Step = Speed * 100 / Weight;
}
}

View File

@ -0,0 +1,123 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.util.Random;
public class FormAntiAircraftGun extends JFrame {
private String title;
private Dimension dimension;
private int Width, Height;
private CanvasAntiAircraftGun canvasAntiAircraftGun = new CanvasAntiAircraftGun();
private JButton CreateButton = new JButton("Создать");;
private JButton UpButton = new JButton();
private JButton DownButton = new JButton();;
private JButton LeftButton = new JButton();;
private JButton RightButton = new JButton();
public FormAntiAircraftGun(String title, Dimension dimension) {
this.title = title;
this.dimension = dimension;
}
public void Init() {
setTitle(title);
setMinimumSize(dimension);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Width = getWidth() - 15;
Height = getHeight() - 35;
CreateButton.setName("CREATE");
Icon iconUp = new ImageIcon("src/images/up.jpg");
UpButton.setIcon(iconUp);
UpButton.setName("UP");
DownButton.setName("DOWN");
Icon iconDown = new ImageIcon("src/images/down.jpg");
DownButton.setIcon(iconDown);
LeftButton.setName("LEFT");
Icon iconLeft = new ImageIcon("src/images/left.jpg");
LeftButton.setIcon(iconLeft);
RightButton.setName("RIGHT");
Icon iconRight = new ImageIcon("src/images/right.jpg");
RightButton.setIcon(iconRight);
CreateButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int StartPositionX = (int)(Math.random() * 90 + 10);
int StartPositionY = (int)(Math.random() * 90 + 10);
int speed = (int)(Math.random() * 300 + 100);
double weight = (double)(Math.random() * 3000 + 1000);
Color bodyColor = new Color((int)(Math.random() * 255 + 0),(int)(Math.random() * 255 + 0),(int)(Math.random() * 255 + 0));
Color additionalColor = new Color((int)(Math.random() * 255 + 0),(int)(Math.random() * 255 + 0),(int)(Math.random() * 255 + 0));;
boolean tower = new Random().nextBoolean();
boolean radar = new Random().nextBoolean();;
canvasAntiAircraftGun._drawingAntiAircraftGun = new DrawningAntiAircraftGun();
canvasAntiAircraftGun._drawingAntiAircraftGun.Init(speed, weight, bodyColor, additionalColor, tower, radar);
canvasAntiAircraftGun._drawingAntiAircraftGun.SetPictureSize(Width, Height);
canvasAntiAircraftGun._drawingAntiAircraftGun.SetPosition( StartPositionX, StartPositionY);
canvasAntiAircraftGun.repaint();
}
});
ActionListener actionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
if (canvasAntiAircraftGun._drawingAntiAircraftGun == null) return;
boolean result = false;
switch ((((JButton)(event.getSource())).getName())) {
case "UP":
result = canvasAntiAircraftGun._drawingAntiAircraftGun.MoveTransport(DirectionType.Up);
break;
case "DOWN":
result = canvasAntiAircraftGun._drawingAntiAircraftGun.MoveTransport(DirectionType.Down);
break;
case "LEFT":
result = canvasAntiAircraftGun._drawingAntiAircraftGun.MoveTransport(DirectionType.Left);
break;
case "RIGHT":
result = canvasAntiAircraftGun._drawingAntiAircraftGun.MoveTransport(DirectionType.Right);
break;
}
if (result) {
canvasAntiAircraftGun.repaint();
}
}
};
UpButton.addActionListener(actionListener);
DownButton.addActionListener(actionListener);
LeftButton.addActionListener(actionListener);
RightButton.addActionListener(actionListener);
setSize(dimension.width,dimension.height);
setLayout(null);
canvasAntiAircraftGun.setBounds(0,0, getWidth(), getHeight());
CreateButton.setBounds(10, getHeight() - 90, 100, 40);
UpButton.setBounds(getWidth() - 140, getHeight() - 160, 50, 50);
DownButton.setBounds(getWidth() - 140, getHeight() - 100, 50, 50);
RightButton.setBounds(getWidth() - 80, getHeight() - 100, 50, 50);
LeftButton.setBounds(getWidth() - 200, getHeight() - 100, 50, 50);
add(CreateButton);
add(UpButton);
add(DownButton);
add(RightButton);
add(LeftButton);
add(canvasAntiAircraftGun);
setVisible(true);
//обработка события изменения размеров окна
addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent e) {
Width = getWidth() - 15;
Height = getHeight() - 35;
if (canvasAntiAircraftGun._drawingAntiAircraftGun != null)
canvasAntiAircraftGun._drawingAntiAircraftGun.SetPictureSize(Width, Height);
canvasAntiAircraftGun.setBounds(0,0, getWidth(), getHeight());
CreateButton.setBounds(10, getHeight() - 90, 100, 40);
UpButton.setBounds(getWidth() - 140, getHeight() - 160, 50, 50);
DownButton.setBounds(getWidth() - 140, getHeight() - 100, 50, 50);
RightButton.setBounds(getWidth() - 80, getHeight() - 100, 50, 50);
LeftButton.setBounds(getWidth() - 200, getHeight() - 100, 50, 50);
}
});
}
}

View File

@ -0,0 +1,8 @@
import java.awt.*;
public class Main {
public static void main(String[] args) {
FormAntiAircraftGun form = new FormAntiAircraftGun("Зенитная установка", new Dimension(600, 600));
form.Init();
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 141 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 141 KiB