From a2cf154aa44f04f11fa8062c9371cb93bbc2d6f7 Mon Sep 17 00:00:00 2001 From: Safgerd Date: Mon, 21 Nov 2022 21:35:51 +0400 Subject: [PATCH] =?UTF-8?q?LabWork03:=20=D0=9F=D0=BE=D1=81=D0=BB=D0=B5=20?= =?UTF-8?q?=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20FormMap,=20?= =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FormMap.form | 137 --------------------------------------------------- FormMap.java | 116 ------------------------------------------- 2 files changed, 253 deletions(-) delete mode 100644 FormMap.form delete mode 100644 FormMap.java diff --git a/FormMap.form b/FormMap.form deleted file mode 100644 index 29f645b..0000000 --- a/FormMap.form +++ /dev/null @@ -1,137 +0,0 @@ - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/FormMap.java b/FormMap.java deleted file mode 100644 index dee9e61..0000000 --- a/FormMap.java +++ /dev/null @@ -1,116 +0,0 @@ -import javax.swing.*; -import java.awt.*; -import java.awt.event.ItemEvent; -import java.util.Random; - -public class FormMap extends JFrame { - private JPanel ContentPanel; - private JButton buttonCreate; - private JLabel speedLabel; - private JLabel weightLabel; - private JLabel colorLabel; - private JButton buttonLeft; - private JButton buttonDown; - private JButton buttonRight; - private JButton buttonUp; - private JPanel pictureBox; - private JButton buttonCreateModif; - private JComboBox comboBoxMapSelector; - - private AbstractMap _abstractMap; - private Image imageBuffer; - - public FormMap(){ - setTitle("Трактор"); - setContentPane(ContentPanel); - setSize(800, 500); - _abstractMap = new SimpleMap(); - - // Обработка нажатия кнопки "Создать" - buttonCreate.addActionListener(e->{ - Random rnd = new Random(); - var _tracktor = new DrawningTracktor( - rnd.nextInt(100, 300), - rnd.nextInt(1000, 2000), - new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)), - rnd.nextInt(3,8) - ); - setData(_tracktor); - }); - - // Обработка нажатия кнопки "Модификация" - buttonCreateModif.addActionListener(e->{ - Random rnd = new Random(); - var _tracktor = new DrawningTrackedVehicle( - rnd.nextInt(100, 300), - rnd.nextInt(1000, 2000), - new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)), - rnd.nextInt(3,8), - new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)), - rnd.nextBoolean(), - rnd.nextBoolean() - ); - setData(_tracktor); - }); - - buttonUp.addActionListener(e->{ - if (_abstractMap != null){ - imageBuffer = _abstractMap.MoveObject(Direction.Up); - repaint(); - } - }); - - buttonLeft.addActionListener(e->{ - if (_abstractMap != null){ - imageBuffer = _abstractMap.MoveObject(Direction.Left); - repaint(); - } - }); - - buttonDown.addActionListener(e->{ - if (_abstractMap != null){ - imageBuffer = _abstractMap.MoveObject(Direction.Down); - repaint(); - } - }); - - buttonRight.addActionListener(e->{ - if (_abstractMap != null){ - imageBuffer = _abstractMap.MoveObject(Direction.Right); - repaint(); - } - }); - - comboBoxMapSelector.addItemListener(e->{ - if (e.getStateChange()== ItemEvent.SELECTED){ - switch (e.getItem().toString()) { - case "Простая карта" -> _abstractMap = new SimpleMap(); - case "Свалка карта" -> _abstractMap = new DumpMap(); - } - - repaint(); - } - }); - } - - private void setData(DrawningTracktor _tracktor) { - Random rnd = new Random(); - _tracktor.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100), pictureBox.getWidth(), pictureBox.getHeight()); - speedLabel.setText("Скорость: " + _tracktor.getTracktor().getSpeed()); - weightLabel.setText("Вес: " + _tracktor.getTracktor().getWeight()); - colorLabel.setText("Цвет: " + String.format("%h",_tracktor.getTracktor().getBodyColor())); - imageBuffer = _abstractMap.CreateMap(pictureBox.getWidth(), pictureBox.getHeight(), new DrawningObjectExcavator(_tracktor)); - - repaint(); - } - - @Override - public void paint(Graphics g){ - super.paint(g); - Graphics2D g2d = (Graphics2D)pictureBox.getGraphics(); - if (imageBuffer != null){ - pictureBox.paintComponents(imageBuffer.getGraphics()); - g2d.drawImage(imageBuffer,0,0,null); - } - } -}