Base Logic copied
This commit is contained in:
parent
fefd0e637e
commit
d30a086f9d
@ -111,7 +111,7 @@ class DrawningLocomotive {
|
|||||||
public void ChangeBorders(int width, int height)
|
public void ChangeBorders(int width, int height)
|
||||||
{
|
{
|
||||||
_pictureWidth = width;
|
_pictureWidth = width;
|
||||||
_pictureHeight = height;
|
_pictureHeight = height - 75;
|
||||||
if (_pictureWidth <= _locomotiveWidth || _pictureHeight <= _locomotiveHeight)
|
if (_pictureWidth <= _locomotiveWidth || _pictureHeight <= _locomotiveHeight)
|
||||||
{
|
{
|
||||||
_pictureWidth = null;
|
_pictureWidth = null;
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.*;
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class FormLocomotive extends JComponent{
|
public class FormLocomotive extends JComponent{
|
||||||
@ -14,27 +13,85 @@ public class FormLocomotive extends JComponent{
|
|||||||
formFrame.setVisible(true);
|
formFrame.setVisible(true);
|
||||||
formFrame.setLocationRelativeTo(null);
|
formFrame.setLocationRelativeTo(null);
|
||||||
|
|
||||||
Panel southPanel = new Panel();
|
formFrame.addComponentListener(new ComponentListener() {
|
||||||
|
@Override
|
||||||
|
public void componentResized(ComponentEvent e) {
|
||||||
|
if (_locomotive != null) _locomotive.ChangeBorders(formFrame.getWidth(), formFrame.getHeight());
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void componentMoved(ComponentEvent e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void componentShown(ComponentEvent e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void componentHidden(ComponentEvent e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Panel statusPanel = new Panel();
|
||||||
|
statusPanel.setBackground(Color.WHITE);
|
||||||
|
statusPanel.setLayout(new FlowLayout());
|
||||||
setLayout(new BorderLayout());
|
setLayout(new BorderLayout());
|
||||||
add(southPanel, BorderLayout.SOUTH);
|
add(statusPanel, BorderLayout.SOUTH);
|
||||||
|
|
||||||
|
Label speedLabel = new Label("Speed: ");
|
||||||
|
Label weightLabel = new Label("Weight: ");
|
||||||
|
Label colorLabel = new Label("Color: ");
|
||||||
|
|
||||||
JButton createButton = new JButton("Create");
|
JButton createButton = new JButton("Create");
|
||||||
createButton.addActionListener(new ActionListener() {
|
createButton.addActionListener(e -> {
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
Random rnd = new Random();
|
Random rnd = new Random();
|
||||||
_locomotive = new DrawningLocomotive();
|
_locomotive = new DrawningLocomotive();
|
||||||
_entity = new EntityLocomotive();
|
_entity = new EntityLocomotive();
|
||||||
_locomotive.Init(100 + rnd.nextInt(200), 1000 + rnd.nextInt(1000), Color.getHSBColor(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)), _entity);
|
_locomotive.Init(100 + rnd.nextInt(200), 1000 + rnd.nextInt(1000), Color.getHSBColor(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)), _entity);
|
||||||
_locomotive.SetPosition(10 + rnd.nextInt(90), 10 + rnd.nextInt(90), formFrame.getWidth(), formFrame.getHeight());
|
_locomotive.SetPosition(10 + rnd.nextInt(90), 10 + rnd.nextInt(90), formFrame.getWidth(), formFrame.getHeight() - 75);
|
||||||
// toolStripStatusLabelSpeed.Text = $"Speed: {_locomotive.Locomotive.Speed}";
|
speedLabel.setText("Speed: " + _locomotive.Locomotive.getSpeed());
|
||||||
// toolStripStatusLabelWeight.Text = $"Weight: {_locomotive.Locomotive.Weight}";
|
weightLabel.setText("Weight: " + (int)_locomotive.Locomotive.getWeight());
|
||||||
// toolStripStatusLabelColor.Text = $"Color: {_locomotive.Locomotive.BodyColor.Name}";
|
colorLabel.setText("Color: " + _locomotive.Locomotive.getBodyColor().getRed() + " " + _locomotive.Locomotive.getBodyColor().getGreen() + " " + _locomotive.Locomotive.getBodyColor().getBlue() );
|
||||||
repaint();
|
repaint();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
southPanel.add(createButton);
|
statusPanel.add(createButton);
|
||||||
|
statusPanel.add(speedLabel);
|
||||||
|
statusPanel.add(weightLabel);
|
||||||
|
statusPanel.add(colorLabel);
|
||||||
|
|
||||||
|
JButton moveDownButton = new JButton("Down");
|
||||||
|
moveDownButton.addActionListener(e -> {
|
||||||
|
if (_locomotive != null) _locomotive.MoveTransport(Direction.Down);
|
||||||
|
repaint();
|
||||||
|
});
|
||||||
|
|
||||||
|
JButton moveUpButton = new JButton("Up");
|
||||||
|
moveUpButton.addActionListener(e -> {
|
||||||
|
if (_locomotive != null) _locomotive.MoveTransport(Direction.Up);
|
||||||
|
repaint();
|
||||||
|
});
|
||||||
|
|
||||||
|
JButton moveLeftButton = new JButton("Left");
|
||||||
|
moveLeftButton.addActionListener(e -> {
|
||||||
|
if (_locomotive != null) _locomotive.MoveTransport(Direction.Left);
|
||||||
|
repaint();
|
||||||
|
});
|
||||||
|
|
||||||
|
JButton moveRightButton = new JButton("Right");
|
||||||
|
moveRightButton.addActionListener(e -> {
|
||||||
|
if (_locomotive != null) _locomotive.MoveTransport(Direction.Right);
|
||||||
|
repaint();
|
||||||
|
});
|
||||||
|
|
||||||
|
statusPanel.add(moveUpButton);
|
||||||
|
statusPanel.add(moveDownButton);
|
||||||
|
statusPanel.add(moveLeftButton);
|
||||||
|
statusPanel.add(moveRightButton);
|
||||||
|
|
||||||
formFrame.getContentPane().add(this);
|
formFrame.getContentPane().add(this);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user