From 64a31c1a76f082779e71996928541df3a9d6c138 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Fri, 18 Nov 2022 21:18:41 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A5=D0=B0=D1=80=D0=B4=20=D0=BB=D0=B0=D0=B1?= =?UTF-8?q?=205=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=B0,=20=D0=BF=D0=BE?= =?UTF-8?q?=D1=87=D0=B8=D1=89=D0=B5=D0=BD=20=D0=BA=D0=BE=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrawningLocomotive.java | 12 --- FormLocomotiveConfig.java | 2 +- FormMap.java | 130 --------------------------------- FormMapWithSetLocomotives.java | 21 ------ 4 files changed, 1 insertion(+), 164 deletions(-) delete mode 100644 FormMap.java diff --git a/DrawningLocomotive.java b/DrawningLocomotive.java index e0271cc..015f2ef 100644 --- a/DrawningLocomotive.java +++ b/DrawningLocomotive.java @@ -20,18 +20,6 @@ public class DrawningLocomotive { private final Random random = new Random(); public DrawningLocomotive(int speed, float weight, Color bodyColor, int wheelsCount) { - /*int randExtra = random.nextInt(2); - switch (random.nextInt(3)){ - case 0: - drawningExtra = new ExtraStarWheelDraw(randExtra, bodyColor); - break; - case 1: - drawningExtra = new ExtraRoundWheelDraw(randExtra, bodyColor); - break; - case 2: - drawningExtra = new ExtraWheelsDraw(randExtra, bodyColor); - break; - }*/ drawningExtra = new ExtraWheelsDraw(wheelsCount, bodyColor); Locomotive = new EntityLocomotive(speed, weight, bodyColor); } diff --git a/FormLocomotiveConfig.java b/FormLocomotiveConfig.java index c2cdead..de89c28 100644 --- a/FormLocomotiveConfig.java +++ b/FormLocomotiveConfig.java @@ -7,7 +7,7 @@ import java.util.function.Consumer; public class FormLocomotiveConfig extends JFrame{ // Рабочие поля private DrawningLocomotive locomotive; - private EventListener eventListener = new EventListener<>(); + private final EventListener eventListener = new EventListener<>(); //Элементы формы private JPanel FormPanel; diff --git a/FormMap.java b/FormMap.java deleted file mode 100644 index 3087aa3..0000000 --- a/FormMap.java +++ /dev/null @@ -1,130 +0,0 @@ -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.image.BufferedImage; -import java.util.Random; - -public class FormMap extends JComponent { - - private AbstractMap _abstractMap; - private BufferedImage bufferImg = null; - - public FormMap() { - JFrame formFrame = new JFrame("Form Map"); - formFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - formFrame.setSize(1000, 500); - formFrame.setVisible(true); - formFrame.setLocationRelativeTo(null); - - Panel statusPanel = new Panel(); - statusPanel.setBackground(Color.WHITE); - statusPanel.setLayout(new FlowLayout()); - setLayout(new BorderLayout()); - add(statusPanel, BorderLayout.SOUTH); - - Label speedLabel = new Label("Speed: "); - Label weightLabel = new Label("Weight: "); - Label colorLabel = new Label("Color: "); - - String[] maps = { - "Simple Map", - "Spike Map", - "Rail Map" - }; - JComboBox mapSelectComboBox = new JComboBox(maps); - mapSelectComboBox.setEditable(true); - mapSelectComboBox.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - String item = (String)mapSelectComboBox.getSelectedItem(); - if (item == null) return; - switch (item) { - case ("Simple Map"): - _abstractMap = new SimpleMap(); - break; - case ("Spike Map"): - _abstractMap = new SpikeMap(); - break; - case ("Rail Map"): - _abstractMap = new RailMap(); - break; - } - } - }); - - JButton createButton = new JButton("Create"); - createButton.addActionListener(e -> { - Random rnd = new Random(); - var locomotive = new DrawningLocomotive(rnd.nextInt(200) + 100, rnd.nextInt(1000) + 1000, new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)), rnd.nextInt(2) + 2); - speedLabel.setText("Speed: " + locomotive.Locomotive.getSpeed()); - weightLabel.setText("Weight: " + (int)locomotive.Locomotive.getWeight()); - colorLabel.setText("Color: " + locomotive.Locomotive.getBodyColor().getRed() + " " + locomotive.Locomotive.getBodyColor().getGreen() + " " + locomotive.Locomotive.getBodyColor().getBlue()); - if (_abstractMap != null) bufferImg = _abstractMap.CreateMap(1000, 490, new DrawningObjectLocomotive(locomotive)); - repaint(); - }); - - JButton modifiedButton = new JButton("Modified"); - modifiedButton.addActionListener(e -> { - Random rnd = new Random(); - var locomotive = new DrawningWarmlyLocomotive(rnd.nextInt(200) + 100, rnd.nextInt(1000) + 1000, - new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)), - rnd.nextInt(2) + 2, - new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)), - rnd.nextBoolean(), - rnd.nextBoolean()); - speedLabel.setText("Speed: " + locomotive.Locomotive.getSpeed()); - weightLabel.setText("Weight: " + (int)locomotive.Locomotive.getWeight()); - colorLabel.setText("Color: " + locomotive.Locomotive.getBodyColor().getRed() + " " + locomotive.Locomotive.getBodyColor().getGreen() + " " + locomotive.Locomotive.getBodyColor().getBlue() ); - if (_abstractMap != null) bufferImg = _abstractMap.CreateMap(1000, 490, new DrawningObjectLocomotive(locomotive)); - repaint(); - }); - statusPanel.add(mapSelectComboBox); - statusPanel.add(createButton); - statusPanel.add(modifiedButton); - statusPanel.add(speedLabel); - statusPanel.add(weightLabel); - statusPanel.add(colorLabel); - - JButton moveDownButton = new JButton("Down"); - moveDownButton.addActionListener(e -> { - if(bufferImg != null) bufferImg = _abstractMap.MoveObject(Direction.Down); - repaint(); - }); - - JButton moveUpButton = new JButton("Up"); - moveUpButton.addActionListener(e -> { - if(bufferImg != null) bufferImg = _abstractMap.MoveObject(Direction.Up); - repaint(); - }); - - JButton moveLeftButton = new JButton("Left"); - moveLeftButton.addActionListener(e -> { - if(bufferImg != null) bufferImg = _abstractMap.MoveObject(Direction.Left); - repaint(); - }); - - JButton moveRightButton = new JButton("Right"); - moveRightButton.addActionListener(e -> { - if(bufferImg != null) bufferImg = _abstractMap.MoveObject(Direction.Right); - repaint(); - }); - - statusPanel.add(moveUpButton); - statusPanel.add(moveDownButton); - statusPanel.add(moveLeftButton); - statusPanel.add(moveRightButton); - - formFrame.getContentPane().add(this); - super.repaint(); - } - - @Override - protected void paintComponent(Graphics g) { - super.paintComponent(g); - Graphics2D g2 = (Graphics2D)g; - if (bufferImg != null) g2.drawImage(bufferImg, 0,0,1000,490,null); - super.repaint(); - } - -} diff --git a/FormMapWithSetLocomotives.java b/FormMapWithSetLocomotives.java index fed8467..ce8dfab 100644 --- a/FormMapWithSetLocomotives.java +++ b/FormMapWithSetLocomotives.java @@ -113,27 +113,6 @@ public class FormMapWithSetLocomotives extends JComponent { // Кнопка добавления локомотива JButton addLocomotiveButton = new JButton("Add Locomotive"); addLocomotiveButton.addActionListener(e -> { - /*// логика добавления - if (listBoxMaps.getSelectedIndex() == -1) - { - return; - } - JDialog dialog = new JDialog(formFrame, "Dialog", true); - FormLocomotive formLocomotive = new FormLocomotive(dialog); - dialog.setSize(800, 500); - dialog.setContentPane(formLocomotive); - dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); - dialog.setVisible(true); - DrawningObjectLocomotive locomotive = new DrawningObjectLocomotive(formLocomotive.getSelectedLocomotive()); - if (_mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).Plus(locomotive)!= -1) { - JOptionPane.showMessageDialog(formFrame, "Object added", "Success", JOptionPane.OK_CANCEL_OPTION); - bufferImg = _mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).ShowSet(); - repaint(); - } - else { - JOptionPane.showMessageDialog(formFrame, "Object cannot be added", "Error", JOptionPane.OK_CANCEL_OPTION); - }*/ - FormLocomotiveConfig formLocomotiveConfig = new FormLocomotiveConfig(); formLocomotiveConfig.setVisible(true); formLocomotiveConfig.AddListener(locomotive -> {