55 lines
2.0 KiB
Java
55 lines
2.0 KiB
Java
import javax.swing.*;
|
||
import java.awt.*;
|
||
import java.util.Random;
|
||
|
||
public class DrawingField extends JPanel{
|
||
private final FormWarship Field;
|
||
DrawingWarship _warship=null;
|
||
public DrawingField(FormWarship field) {
|
||
Field = field;
|
||
}
|
||
|
||
@Override
|
||
protected void paintComponent(Graphics g) {
|
||
super.paintComponent(g);
|
||
Graphics2D g2 =(Graphics2D)g;
|
||
if (_warship!=null)
|
||
_warship.DrawTransport(g2);
|
||
else return;
|
||
}
|
||
public void DirectionButtonAction(Direction side){
|
||
if(_warship == null)
|
||
return;
|
||
_warship.MoveTransport(side);
|
||
}
|
||
private void SetData() {
|
||
Random rand=new Random();
|
||
_warship.SetPosition(rand.nextInt(100)+10,rand.nextInt(100)+10,getWidth(),getHeight());
|
||
Field.SpeedLabel.setText("Скорость: "+_warship.GetWarship().GetSpeed());
|
||
Field.WeightLabel.setText("Вес: "+_warship.GetWarship().GetWeight());
|
||
Field.BodyColorLabel.setText("Цвет: "+Integer.toHexString(_warship.GetWarship().GetBodyColor().getRGB()).substring(2));
|
||
}
|
||
public void CreateButtonAction(){
|
||
Random rand=new Random();
|
||
_warship=new DrawingWarship(rand.nextInt(50)+10,rand.nextInt(3000)+20000,new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)),rand.nextInt(3));
|
||
SetData();
|
||
}
|
||
public void CreateModifButtonAction(){
|
||
Random rand=new Random();
|
||
_warship = new DrawingAdvancedWarship(rand.nextInt(50) + 10, rand.nextInt(3000) + 20000, new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)),
|
||
new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)), rand.nextBoolean(), rand.nextBoolean(), rand.nextBoolean(),rand.nextInt(3));
|
||
SetData();
|
||
}
|
||
public void ResizeField(){
|
||
if (_warship!=null)
|
||
_warship.ChangeBorders(getWidth(),getHeight());
|
||
else return;
|
||
}
|
||
|
||
public void Draw(Graphics2D graphics) {
|
||
if (_warship!=null)
|
||
_warship.DrawTransport(graphics);
|
||
else return;
|
||
}
|
||
}
|