some fixes

This commit is contained in:
pyzhov.egor 2024-02-13 00:48:29 +04:00
parent 6b543de74e
commit 80f133e150
41 changed files with 45 additions and 38 deletions

1
.idea/.name generated Normal file
View File

@ -0,0 +1 @@
DrawningCatamaran.java

Binary file not shown.

After

Width:  |  Height:  |  Size: 244 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 249 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 254 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

View File

@ -5,8 +5,8 @@ public class DrawningCatamaran {
public EntityCatamaran entityCatamaran;
private Integer _pictureWidth = null;
private Integer _pictureHeight = null;
private int _startPosX;
private int _startPosY;
private Integer _startPosX;
private Integer _startPosY;
private final int _drawingCatamaranWidth = 120;
private final int _drawingCatamaranHeight = 70;
private DrawningCatamaranPaddle _drawingCatamaranPaddle;
@ -28,12 +28,42 @@ public class DrawningCatamaran {
public void setPosition(int x, int y, int width, int height) {
if (x > 0 && x + _drawingCatamaranWidth < width && y> 0 && y + _drawingCatamaranHeight < height) {
_startPosX = x;
_startPosY = y;
_pictureWidth = width;
_pictureHeight = height;
if (_pictureHeight == null || _pictureWidth == null)
return;
if (x + _drawingCatamaranWidth > _pictureWidth) _startPosX = _pictureWidth - _drawingCatamaranWidth;
else if (x < 0) _startPosX = 0;
else _startPosX = x;
if (y + _drawingCatamaranHeight > _pictureHeight) _startPosY = _pictureHeight - _drawingCatamaranHeight;
else if (y < 0) _startPosY = 0;
else _startPosY = y;
}
public boolean setPictureSize(int width, int height) {
_pictureHeight = height;
_pictureWidth = width;
if (_drawingCatamaranHeight > height || _drawingCatamaranWidth > width)
return false;
if (_startPosX != null || _startPosY != null)
{
if (_startPosX + _drawingCatamaranWidth > _pictureWidth)
_startPosX = _pictureWidth - _drawingCatamaranWidth;
else if (_startPosX < 0)
_startPosX = 0;
if (_startPosY + _drawingCatamaranHeight > _pictureHeight)
_startPosY = _pictureHeight - _drawingCatamaranHeight;
else if (_startPosY < 0)
_startPosY = 0;
}
return true;
}
public boolean moveTransport(DirectionType direction) {
@ -152,25 +182,10 @@ public class DrawningCatamaran {
g2d.setColor(entityCatamaran.getAdditionalColor());
g2d.fillPolygon(sailPolygon);
// вёсла катамарана
}
}
public void changeBorders(int width, int height) {
_pictureWidth = width;
_pictureHeight = height;
if (_pictureWidth <= _drawingCatamaranWidth || _pictureHeight <= _drawingCatamaranHeight) {
_pictureWidth = null;
_pictureHeight = null;
return;
}
if (_startPosX + _drawingCatamaranWidth > _pictureWidth)
_startPosX = _pictureWidth - _drawingCatamaranWidth;
if (_startPosY + _drawingCatamaranHeight > _pictureHeight)
_startPosY = _pictureHeight - _drawingCatamaranHeight;
}
}

View File

@ -8,9 +8,9 @@ public class DrawningCatamaranPaddle {
}
public void setEnumNumber(int paddlesCount) {
for (PaddlesCount val : PaddlesCount.values()) {
if (val.enumNumber == paddlesCount) {
_paddlesCount = val;
for (PaddlesCount value : PaddlesCount.values()) {
if (value.enumNumber == paddlesCount) {
_paddlesCount = value;
return;
}
}

View File

@ -2,8 +2,6 @@ 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.LinkedList;
import java.util.Random;
import java.util.List;
@ -38,6 +36,7 @@ public class FormCatamaran extends JFrame {
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
random.nextBoolean(), random.nextBoolean() );
_drawningCatamaran.setPictureSize(PictureBox.getWidth(), PictureBox.getHeight());
_drawningCatamaran.setPosition(random.nextInt(35, 100),
random.nextInt(35, 100), PictureBox.getWidth(), PictureBox.getHeight());
@ -45,15 +44,6 @@ public class FormCatamaran extends JFrame {
}
});
PanelWrapper.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
super.componentResized(e);
_drawningCatamaran.changeBorders(PictureBox.getWidth(), PictureBox.getHeight());
Draw();
}
});
ActionListener buttonMoveClickedListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@ -101,12 +91,13 @@ public class FormCatamaran extends JFrame {
RepaintControls();
}
private void RepaintControls() {
for (JComponent control : controls) {
control.repaint();
}
}
private void InitializeControlsRepaintList() {
controls = new LinkedList<>();
controls.add(buttonCreate);

Binary file not shown.

After

Width:  |  Height:  |  Size: 244 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 249 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 254 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 B

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB