diff --git a/DrawningLocomotive.java b/DrawningLocomotive.java index 19497c3..a12110e 100644 --- a/DrawningLocomotive.java +++ b/DrawningLocomotive.java @@ -80,7 +80,7 @@ class DrawningLocomotive { } } - public void DrawTransport(Graphics g) { + public void DrawTransport(Graphics2D g) { if (_startPosX < 0 || _startPosY < 0 || _pictureHeight == null || _pictureWidth == null) { diff --git a/FormLocomotive.java b/FormLocomotive.java new file mode 100644 index 0000000..ea3c141 --- /dev/null +++ b/FormLocomotive.java @@ -0,0 +1,55 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Random; + +public class FormLocomotive extends JComponent{ + private DrawningLocomotive _locomotive; + private EntityLocomotive _entity; + public FormLocomotive() { + JFrame formFrame = new JFrame("Locomotive"); + formFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + formFrame.setSize(800, 500); + formFrame.setVisible(true); + formFrame.setLocationRelativeTo(null); + + Panel southPanel = new Panel(); + setLayout(new BorderLayout()); + add(southPanel, BorderLayout.SOUTH); + + JButton createButton = new JButton("Create"); + createButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + Random rnd = new Random(); + _locomotive = new DrawningLocomotive(); + _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.SetPosition(10 + rnd.nextInt(90), 10 + rnd.nextInt(90), formFrame.getWidth(), formFrame.getHeight()); +// toolStripStatusLabelSpeed.Text = $"Speed: {_locomotive.Locomotive.Speed}"; +// toolStripStatusLabelWeight.Text = $"Weight: {_locomotive.Locomotive.Weight}"; +// toolStripStatusLabelColor.Text = $"Color: {_locomotive.Locomotive.BodyColor.Name}"; + repaint(); + } + }); + + southPanel.add(createButton); + + formFrame.getContentPane().add(this); + } + + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); + Graphics2D g2 = (Graphics2D)g; + if (_locomotive != null) _locomotive.DrawTransport(g2); + super.repaint(); + } + + public static void main(String[] args) { + FormLocomotive formLocomotive = new FormLocomotive(); + + + } +}