diff --git a/src/main/java/FormMap.form b/src/main/java/FormMap.form new file mode 100644 index 0000000..5dcacd8 --- /dev/null +++ b/src/main/java/FormMap.form @@ -0,0 +1,129 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/main/java/FormMap.java b/src/main/java/FormMap.java new file mode 100644 index 0000000..868daa7 --- /dev/null +++ b/src/main/java/FormMap.java @@ -0,0 +1,151 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; +import java.awt.image.BufferedImage; +import java.util.Objects; +import java.util.Random; + +public class FormMap extends JFrame { + private JPanel drawPanel; + private JButton buttonCreate; + private JButton buttonRight; + private JButton buttonUp; + private JButton buttonDown; + private JButton buttonLeft; + private JButton buttonCreate_Modif; + private JLabel labelSpeed; + private JLabel labelWeight; + private JLabel labelColor; + private JComboBox mapSelectorComboBox; + private JPanel mainPanel; + + private AbstractMap abstractMap; + private Image img; + public FormMap() { + super("Карта"); + abstractMap = new SimpleMap(); + + setBounds(100, 100, 700, 700); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + labelSpeed.setText("Скорость: "); + labelWeight.setText("Вес: "); + labelColor.setText("Цвет: "); + + buttonCreate.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + Random rnd = new Random(); + DrawingArmoredCar armoredCar = new DrawingArmoredCar(rnd.nextInt(100,300), rnd.nextInt(1000, 2000), + new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256))); + setData(armoredCar); + } + }); + + buttonUp.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + if (abstractMap != null) { + img = abstractMap.MoveObject(Direction.Up); + drawPanel.repaint(); + } + } + }); + + buttonDown.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + if (abstractMap != null) { + img = abstractMap.MoveObject(Direction.Down); + drawPanel.repaint(); + } + } + }); + + buttonLeft.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + if (abstractMap != null) { + img = abstractMap.MoveObject(Direction.Left); + drawPanel.repaint(); + } + } + }); + + buttonRight.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + if (abstractMap != null) { + img = abstractMap.MoveObject(Direction.Right); + drawPanel.repaint(); + } + } + }); + + setContentPane(mainPanel); + setVisible(true); + buttonCreate_Modif.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + Random rnd = new Random(); + DrawingTank tank = new DrawingTank(rnd.nextInt(100, 300), rnd.nextInt(1000, + 2000), + new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, + 256)), + new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, + 256)), + 1==rnd.nextInt(0, 2), 1==rnd.nextInt(0, 2)); + setData(tank); + } + }); + mapSelectorComboBox.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String name = (String) mapSelectorComboBox.getSelectedItem(); + switch (name) + { + case "Простая карта": + abstractMap = new SimpleMap(); + break; + + case "Карта 1": + abstractMap = new MyMapWooden(); + break; + case "Карта 2": + //abstractMap = new MyMapWooden(); + break; + } + //setData(); + } + }); + } + + private void createUIComponents() { + drawPanel = new JPanel() { + @Override + public void paintComponent(Graphics g) { + super.paintComponent(g); + g.drawImage(img, 0, 0, this); + super.repaint(); + } + }; + } + + private void setData(DrawingArmoredCar drawingArmoredCar) + { + if (abstractMap != null) + img = abstractMap.CreateMap(drawPanel.getWidth(), drawPanel.getHeight(), new DrawingObjectArmoredCar(drawingArmoredCar)); + + labelSpeed.setText("Скорость: " + drawingArmoredCar.getArmoredCar().getSpeed()); + labelWeight.setText("Вес: " + drawingArmoredCar.getArmoredCar().getWeight()); + labelColor.setText("Цвет: " + drawingArmoredCar.getArmoredCar().getBodyColor().getRGB()); + } +} + + + + + diff --git a/src/main/java/Program.java b/src/main/java/Program.java index 2d1f91a..1683846 100644 --- a/src/main/java/Program.java +++ b/src/main/java/Program.java @@ -1,5 +1,6 @@ public class Program { public static void main(String[] args) { - new FormArmoredCar(); + //new FormArmoredCar(); + new FormMap(); } }