Added & fixed FormMap
This commit is contained in:
parent
febb4eaa6b
commit
8e0a97dd2b
@ -2,7 +2,7 @@ import java.awt.*;
|
||||
public class DrawningWarmlyLocomotive extends DrawningLocomotive{
|
||||
public DrawningWarmlyLocomotive(int speed, float weight, Color bodyColor, Color extraColor, boolean pipe, boolean storage)
|
||||
{
|
||||
super(speed, weight, bodyColor, 130, 70);
|
||||
super(speed, weight, bodyColor, 140, 70);
|
||||
Locomotive = new EntityWarmlyLocomotive(speed, weight, bodyColor, extraColor, pipe, storage);
|
||||
}
|
||||
@Override
|
||||
|
@ -99,9 +99,6 @@ public class FormLocomotive extends JComponent{
|
||||
|
||||
formFrame.getContentPane().add(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
@ -111,6 +108,6 @@ public class FormLocomotive extends JComponent{
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new FormLocomotive();
|
||||
new FormMap();
|
||||
}
|
||||
}
|
||||
|
126
FormMap.java
Normal file
126
FormMap.java
Normal file
@ -0,0 +1,126 @@
|
||||
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"):
|
||||
break;
|
||||
case ("Rail Map"):
|
||||
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)));
|
||||
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, 500, 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)),
|
||||
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, 500, 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("D");
|
||||
moveDownButton.addActionListener(e -> {
|
||||
if(bufferImg != null) bufferImg = _abstractMap.MoveObject(Direction.Down);
|
||||
repaint();
|
||||
});
|
||||
|
||||
JButton moveUpButton = new JButton("U");
|
||||
moveUpButton.addActionListener(e -> {
|
||||
if(bufferImg != null) bufferImg = _abstractMap.MoveObject(Direction.Up);
|
||||
repaint();
|
||||
});
|
||||
|
||||
JButton moveLeftButton = new JButton("L");
|
||||
moveLeftButton.addActionListener(e -> {
|
||||
if(bufferImg != null) bufferImg = _abstractMap.MoveObject(Direction.Left);
|
||||
repaint();
|
||||
});
|
||||
|
||||
JButton moveRightButton = new JButton("R");
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2 = (Graphics2D)g;
|
||||
if (bufferImg != null) g2.drawImage(bufferImg, 0,0,1000,500,null);
|
||||
super.repaint();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user