Compare commits
No commits in common. "1_laba" and "main" have entirely different histories.
Binary file not shown.
Before Width: | Height: | Size: 810 B |
Binary file not shown.
Before Width: | Height: | Size: 802 B |
Binary file not shown.
Before Width: | Height: | Size: 817 B |
BIN
src/Crane/Up.png
BIN
src/Crane/Up.png
Binary file not shown.
Before Width: | Height: | Size: 821 B |
@ -1,16 +0,0 @@
|
|||||||
public enum DirectionType
|
|
||||||
{
|
|
||||||
Up("U"),
|
|
||||||
Down("D"),
|
|
||||||
Left("L"),
|
|
||||||
Right("R");
|
|
||||||
private String direct;
|
|
||||||
DirectionType(String d)
|
|
||||||
{
|
|
||||||
direct = d;
|
|
||||||
}
|
|
||||||
public String getDirect()
|
|
||||||
{
|
|
||||||
return direct;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,115 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
|
|
||||||
public class DrawingCrane
|
|
||||||
{
|
|
||||||
private EntityCrane entityCrane;
|
|
||||||
private DrawingWheel drawingWheel;
|
|
||||||
private int _pictureWidth;
|
|
||||||
private int _pictureHeight;
|
|
||||||
|
|
||||||
private int _startPositionX;
|
|
||||||
private int _startPositionY;
|
|
||||||
|
|
||||||
private final int _craneWidth = 200;
|
|
||||||
|
|
||||||
private final int _craneHeight = 150;
|
|
||||||
public void Init(int speed, double weight, boolean counterWeight, boolean crane, Color bodyColor, Color additionalColor, int width, int height,int wheelCount)
|
|
||||||
{
|
|
||||||
if ((_craneWidth > width) || (_craneHeight > height)) return;
|
|
||||||
_pictureHeight = height;
|
|
||||||
_pictureWidth = width;
|
|
||||||
entityCrane = new EntityCrane();
|
|
||||||
entityCrane.Init(speed, weight, counterWeight,crane, bodyColor, additionalColor);
|
|
||||||
drawingWheel = new DrawingWheel();
|
|
||||||
drawingWheel.SetWheelCounter(wheelCount);
|
|
||||||
}
|
|
||||||
public void SetPosition(int x, int y)
|
|
||||||
{
|
|
||||||
|
|
||||||
if(x+_craneWidth>_pictureWidth)
|
|
||||||
{
|
|
||||||
while(x + _craneWidth > _pictureWidth)
|
|
||||||
{
|
|
||||||
x -= _pictureWidth;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_startPositionX = x;
|
|
||||||
|
|
||||||
if(y+_craneHeight>_pictureHeight)
|
|
||||||
{
|
|
||||||
while(y+_craneHeight>_pictureHeight)
|
|
||||||
{
|
|
||||||
y -= _pictureHeight;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_startPositionY = y;
|
|
||||||
}
|
|
||||||
public void MoveCrane(DirectionType direction)
|
|
||||||
{
|
|
||||||
if (entityCrane == null) return;
|
|
||||||
switch (direction) {
|
|
||||||
case Left -> {
|
|
||||||
|
|
||||||
if (_startPositionX - entityCrane.Step > 0) {
|
|
||||||
_startPositionX -= (int) entityCrane.Step;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case Right->{
|
|
||||||
|
|
||||||
if (_startPositionX + entityCrane.Step + _craneWidth < _pictureWidth) {
|
|
||||||
_startPositionX += (int) entityCrane.Step;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case Up-> {
|
|
||||||
|
|
||||||
if (_startPositionY - entityCrane.Step > 0) {
|
|
||||||
_startPositionY -= (int) entityCrane.Step;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
case Down ->{
|
|
||||||
if (_startPositionY + entityCrane.Step + _craneHeight < _pictureHeight) {
|
|
||||||
|
|
||||||
_startPositionY += (int) entityCrane.Step;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
public void DrawTransport(Graphics g) {
|
|
||||||
var g2d = (Graphics2D)g;
|
|
||||||
if (entityCrane == null) return;
|
|
||||||
// Гусеницы
|
|
||||||
|
|
||||||
g2d.drawLine( _startPositionX + 5, _startPositionY + 110, _startPositionX + 195, _startPositionY + 110);
|
|
||||||
g2d.drawLine( _startPositionX, _startPositionY + 115, _startPositionX, _startPositionY + 145);
|
|
||||||
g2d.drawLine( _startPositionX + 5, _startPositionY + 150, _startPositionX + 195, _startPositionY + 150);
|
|
||||||
g2d.drawLine( _startPositionX + 200, _startPositionY + 115, _startPositionX + 200, _startPositionY + 145);
|
|
||||||
g2d.drawArc( _startPositionX, _startPositionY + 110, _craneWidth / 20, _craneHeight / 15, 45, 135);
|
|
||||||
g2d.drawArc( _startPositionX, _startPositionY + 140, _craneWidth / 20, _craneHeight / 15, 135, 180);
|
|
||||||
g2d.drawArc( _startPositionX + 190, _startPositionY + 110, _craneWidth / 20, _craneHeight / 20, 305, 170);
|
|
||||||
g2d.drawArc( _startPositionX + 190, _startPositionY + 143, _craneWidth / 20, _craneHeight / 20, 230, 180);
|
|
||||||
// основное тело
|
|
||||||
g2d.setColor(entityCrane.getBodyColor());
|
|
||||||
g2d.drawRect( _startPositionX + 10, _startPositionY + 65, 180, 40);
|
|
||||||
g2d.fillRect( _startPositionX + 10, _startPositionY + 65, 180, 40);
|
|
||||||
g2d.setColor(Color.BLACK);
|
|
||||||
|
|
||||||
drawingWheel.DrawWheels(_startPositionX, _startPositionY, g2d);
|
|
||||||
//кабинка и выхлоп
|
|
||||||
g2d.drawRect( _startPositionX + 60, _startPositionY + 10, 20, 55);
|
|
||||||
g2d.drawRect( _startPositionX + 110, _startPositionY, 75, 65);
|
|
||||||
if (entityCrane.getCounterWeight()) {
|
|
||||||
g2d.setColor(entityCrane.getAdditionalColor());
|
|
||||||
g2d.drawRect( _startPositionX + 185, _startPositionY + 20, 15, 45);
|
|
||||||
|
|
||||||
}
|
|
||||||
if (entityCrane.getCrane()) {
|
|
||||||
g2d.drawRect( _startPositionX + 20, _startPositionY, 30, 65);
|
|
||||||
g2d.drawRect( _startPositionX, _startPositionY, 20, 30);
|
|
||||||
g2d.fillRect( _startPositionX + 20, _startPositionY, 30, 65);
|
|
||||||
g2d.fillRect( _startPositionX, _startPositionY, 20, 30);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
|
|
||||||
public class DrawingWheel {
|
|
||||||
private WheelCounter wheelCounter;
|
|
||||||
public void SetWheelCounter(int count)
|
|
||||||
{
|
|
||||||
if (count % 3 == 0)
|
|
||||||
wheelCounter = WheelCounter.SIX;
|
|
||||||
else if (count % 3 == 1)
|
|
||||||
wheelCounter = WheelCounter.FOUR;
|
|
||||||
else if (count % 3 == 2)
|
|
||||||
wheelCounter = WheelCounter.FIVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DrawWheels(int _startPositionX, int _startPositionY, Graphics2D g2d)
|
|
||||||
{
|
|
||||||
g2d.drawOval( _startPositionX + 2, _startPositionY + 112, 36, 36);
|
|
||||||
g2d.drawOval( _startPositionX + 160, _startPositionY + 112, 36, 36);
|
|
||||||
g2d.drawOval( _startPositionX + 74, _startPositionY + 112, 10, 10);
|
|
||||||
g2d.drawOval( _startPositionX + 111, _startPositionY + 112, 10, 10);
|
|
||||||
switch (wheelCounter)
|
|
||||||
{
|
|
||||||
case FIVE -> {g2d.drawOval( _startPositionX + 133, _startPositionY + 128, 20, 20);}
|
|
||||||
case SIX -> {g2d.drawOval( _startPositionX + 45, _startPositionY + 128, 20, 20); g2d.drawOval( _startPositionX + 133, _startPositionY + 128, 20, 20);}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
|
|
||||||
public class EntityCrane
|
|
||||||
{
|
|
||||||
//скорость
|
|
||||||
private int Speed ;
|
|
||||||
public int getSpeed() {return Speed;}
|
|
||||||
private void setSpeed(int value) {Speed = value;}
|
|
||||||
|
|
||||||
|
|
||||||
//вес
|
|
||||||
private double Weight ;
|
|
||||||
public double getWeight() {return Weight;}
|
|
||||||
private void setWeight(double value) {Weight = value;}
|
|
||||||
//основной цвет
|
|
||||||
private Color BodyColor ;
|
|
||||||
public Color getBodyColor() {return BodyColor;}
|
|
||||||
private void setBodyColor(Color value) {BodyColor = value;}
|
|
||||||
//дополнительный
|
|
||||||
private Color AdditionalColor ;
|
|
||||||
public Color getAdditionalColor() {return AdditionalColor;}
|
|
||||||
private void setAdditionalColor(Color value) {AdditionalColor = value;}
|
|
||||||
|
|
||||||
private boolean CounterWeight ;
|
|
||||||
public boolean getCounterWeight() {return CounterWeight;}
|
|
||||||
private void setCounterWeight(boolean value) {CounterWeight = value;}
|
|
||||||
|
|
||||||
private boolean Crane;
|
|
||||||
public boolean getCrane() {return Crane;}
|
|
||||||
private void setCrane(boolean value) {Crane = value;}
|
|
||||||
//шаг перемещения
|
|
||||||
public double Step;
|
|
||||||
|
|
||||||
public void Init(int speed, double weight, boolean counterWeight,boolean crane, Color bodyColor, Color additionalColor)
|
|
||||||
{
|
|
||||||
Speed = speed;
|
|
||||||
Weight = weight;
|
|
||||||
CounterWeight = counterWeight;
|
|
||||||
Crane = crane;
|
|
||||||
BodyColor = bodyColor;
|
|
||||||
AdditionalColor = additionalColor;
|
|
||||||
Step = (double)Speed * 100 / Weight;
|
|
||||||
}
|
|
||||||
}
|
|
142
src/Frame.java
142
src/Frame.java
@ -1,142 +0,0 @@
|
|||||||
import javax.imageio.ImageIO;
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.awt.image.*;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
class DrawCrane extends JComponent {
|
|
||||||
private DrawingCrane _drawingCrane;
|
|
||||||
public void paintComponent(Graphics g)
|
|
||||||
{
|
|
||||||
super.paintComponent(g);
|
|
||||||
if (_drawingCrane == null)
|
|
||||||
return;
|
|
||||||
_drawingCrane.DrawTransport(g);
|
|
||||||
super.repaint();
|
|
||||||
}
|
|
||||||
protected void CreateCraneButton_Click()
|
|
||||||
{
|
|
||||||
Random rnd = new Random();
|
|
||||||
_drawingCrane = new DrawingCrane();
|
|
||||||
Color addColor = new Color(rnd.nextInt( 256), rnd.nextInt( 256), rnd.nextInt( 256));
|
|
||||||
Color bodyColor = new Color(rnd.nextInt( 256), rnd.nextInt( 256), rnd.nextInt(256));
|
|
||||||
_drawingCrane.Init(rnd.nextInt(100)+100, rnd.nextInt(2000)+1000,
|
|
||||||
ConvertToBoolean(rnd.nextInt( 2)), ConvertToBoolean(rnd.nextInt( 2)), bodyColor, addColor,
|
|
||||||
Frame.Width-10, Frame.Height-38, rnd.nextInt( 3)+4);
|
|
||||||
_drawingCrane.SetPosition(rnd.nextInt( 100), rnd.nextInt(90)+10);
|
|
||||||
super.repaint();
|
|
||||||
}
|
|
||||||
protected void ButtonMove_Click(String tag)
|
|
||||||
{
|
|
||||||
if (_drawingCrane == null)
|
|
||||||
return;
|
|
||||||
switch (tag) {
|
|
||||||
case "U" -> _drawingCrane.MoveCrane(DirectionType.Up);
|
|
||||||
case "D" -> _drawingCrane.MoveCrane(DirectionType.Down);
|
|
||||||
case "L" -> _drawingCrane.MoveCrane(DirectionType.Left);
|
|
||||||
case "R" -> _drawingCrane.MoveCrane(DirectionType.Right);
|
|
||||||
}
|
|
||||||
super.repaint();
|
|
||||||
}
|
|
||||||
static boolean ConvertToBoolean(int value)
|
|
||||||
{
|
|
||||||
if(value ==0)
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public class Frame extends JFrame {
|
|
||||||
public Frame()
|
|
||||||
{
|
|
||||||
InitUI();
|
|
||||||
}
|
|
||||||
protected static final int Width = 900;
|
|
||||||
protected static final int Height = 500;
|
|
||||||
|
|
||||||
DrawCrane Crane;
|
|
||||||
private void InitUI() {
|
|
||||||
setSize(Width, Height);
|
|
||||||
setTitle("HoistingCrane");
|
|
||||||
setLocationRelativeTo(null);
|
|
||||||
setLayout(null);
|
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
setResizable(false);
|
|
||||||
Crane = new DrawCrane();
|
|
||||||
Crane.setBounds(0, 0, Width, Height);
|
|
||||||
add(Crane);
|
|
||||||
|
|
||||||
MoveAL moving = new MoveAL();
|
|
||||||
|
|
||||||
JButton left = new JButton();
|
|
||||||
left.setActionCommand("L");
|
|
||||||
left.addActionListener(moving);
|
|
||||||
left.setLayout(null);
|
|
||||||
|
|
||||||
JButton right = new JButton();
|
|
||||||
right.setActionCommand("R");
|
|
||||||
right.setLayout(null);
|
|
||||||
right.addActionListener(moving);
|
|
||||||
|
|
||||||
JButton up = new JButton();
|
|
||||||
up.setActionCommand("U");
|
|
||||||
up.addActionListener(moving);
|
|
||||||
up.setLayout(null);
|
|
||||||
|
|
||||||
JButton down = new JButton();
|
|
||||||
down.setActionCommand("D");
|
|
||||||
down.addActionListener(moving);
|
|
||||||
down.setLayout(null);
|
|
||||||
|
|
||||||
JButton CreateButton = new JButton("Создать");
|
|
||||||
right.setIcon(new ImageIcon("src/crane/right.png"));
|
|
||||||
left.setIcon(new ImageIcon("src/crane/left.png"));
|
|
||||||
down.setIcon(new ImageIcon("src/crane/down.png"));
|
|
||||||
up.setIcon(new ImageIcon("src/crane/up.png"));
|
|
||||||
JPanel panelMoveButtons = new JPanel();
|
|
||||||
|
|
||||||
panelMoveButtons.setLayout(new GridBagLayout());
|
|
||||||
panelMoveButtons.setBounds(774, 395, 98, 66);
|
|
||||||
|
|
||||||
GridBagConstraints constraints = new GridBagConstraints();
|
|
||||||
constraints.fill = GridBagConstraints.BOTH;
|
|
||||||
constraints.gridx = 1;
|
|
||||||
constraints.gridy = 0;
|
|
||||||
constraints.weightx = 4;
|
|
||||||
constraints.weighty = 6;
|
|
||||||
panelMoveButtons.add(up, constraints);
|
|
||||||
constraints.gridy = 1;
|
|
||||||
constraints.gridx = 0;
|
|
||||||
panelMoveButtons.add(left, constraints);
|
|
||||||
constraints.gridx = 1;
|
|
||||||
panelMoveButtons.add(down, constraints);
|
|
||||||
constraints.gridx = 2;
|
|
||||||
panelMoveButtons.add(right, constraints);
|
|
||||||
|
|
||||||
|
|
||||||
JPanel panelCreateButton = new JPanel();
|
|
||||||
panelCreateButton.setLayout(new BorderLayout());
|
|
||||||
panelCreateButton.setBounds(0, 420, 112, 34);
|
|
||||||
panelCreateButton.add(CreateButton);
|
|
||||||
|
|
||||||
add(panelMoveButtons);
|
|
||||||
add(panelCreateButton);
|
|
||||||
|
|
||||||
|
|
||||||
setVisible(true);
|
|
||||||
CreateButton.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
Crane.CreateCraneButton_Click();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
public class MoveAL implements ActionListener {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
Crane.ButtonMove_Click(e.getActionCommand());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
public class Main {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
Frame a = new Frame();
|
|
||||||
a.setVisible(true);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
public enum WheelCounter {
|
|
||||||
FOUR (4),
|
|
||||||
FIVE (5),
|
|
||||||
SIX (6);
|
|
||||||
private int count;
|
|
||||||
WheelCounter(int c)
|
|
||||||
{
|
|
||||||
count = c;
|
|
||||||
}
|
|
||||||
public int getCount()
|
|
||||||
{
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user