Хард лаб 5 готова, почищен код
This commit is contained in:
parent
7e8bac26f3
commit
64a31c1a76
@ -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);
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import java.util.function.Consumer;
|
||||
public class FormLocomotiveConfig extends JFrame{
|
||||
// Рабочие поля
|
||||
private DrawningLocomotive locomotive;
|
||||
private EventListener<DrawningLocomotive> eventListener = new EventListener<>();
|
||||
private final EventListener<DrawningLocomotive> eventListener = new EventListener<>();
|
||||
|
||||
//Элементы формы
|
||||
private JPanel FormPanel;
|
||||
|
130
FormMap.java
130
FormMap.java
@ -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();
|
||||
}
|
||||
|
||||
}
|
@ -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 -> {
|
||||
|
Loading…
Reference in New Issue
Block a user