72 lines
2.8 KiB
Java

import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.Random;
public class DrawingMap extends JPanel {
private final FormMap Map;
private AbstractMap _abstractMap;
BufferedImage bufferedImage;
public DrawingMap(FormMap map){
Map=map;
_abstractMap = new SimpleMap();
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(bufferedImage,0,0,null);
}
private void SetData(DrawingGasolineTanker gasolineTanker) {
Random rand=new Random();
gasolineTanker.SetPosition(rand.nextInt(100)+10,rand.nextInt(100)+10,getWidth(),getHeight());
Map.SpeedLabel.setText("Speed: "+gasolineTanker.getGasolineTanker().getSpeed());
Map.WeightLabel.setText("Weight: "+gasolineTanker.getGasolineTanker().getWeight());
Map.BodyColorLabel.setText("Color: "+Integer.toHexString(gasolineTanker.getGasolineTanker().getBodyColor().getRGB()).substring(2));
bufferedImage = _abstractMap.CreateMap(700,550,new DrawingObjectGasolineTanker(gasolineTanker));
}
public void CreateButtonAction(){
Random rand=new Random();
Color color1=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
if(color1==null)
color1=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
DrawingGasolineTanker warship=new DrawingGasolineTanker(rand.nextInt(50)+10,rand.nextInt(3000)+20000,color1,rand.nextInt(3));
SetData(warship);
}
public void CreateModifButtonAction(){
Random rand=new Random();
Color color1=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
Color color2=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
if(color1==null)
color1=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
if (color2==null)
color2=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
DrawingGasolineTanker gasolineTanker = new DrawingImprovedGasolineTanker(rand.nextInt(50) + 10, rand.nextInt(3000) + 20000, color1,
color2, rand.nextBoolean(), rand.nextBoolean(),rand.nextInt(3));
SetData(gasolineTanker);
}
public void DirectionButtonAction(Direction side){
if(_abstractMap != null){
bufferedImage = _abstractMap.MoveObject(side);
}
}
public void ComboBoxSelectorMapAction(String name){
switch (name){
case "Simple map":
_abstractMap = new SimpleMap();
break;
case "Long map":
_abstractMap = new LongMap();
break;
}
}
public void DrawMap(Graphics g){
g.drawImage(bufferedImage,0,0,null);
}
}