133 lines
4.8 KiB
Java
133 lines
4.8 KiB
Java
import javax.swing.*;
|
|
import java.awt.*;
|
|
import java.awt.event.ActionEvent;
|
|
import java.awt.event.ActionListener;
|
|
import java.util.Random;
|
|
|
|
public class FormCreater extends JDialog{
|
|
private JLabel SetSpeedLabel;
|
|
private JPanel PropertiesPanel;
|
|
private JTextField SpeedTextField;
|
|
private JLabel SetWeightLabel;
|
|
private JTextField WeightTextField;
|
|
private JRadioButton BasicRadioButton;
|
|
private JRadioButton AdvancedRadioButton;
|
|
private JCheckBox MissileCheckBox;
|
|
private JCheckBox AntennaCheckBox;
|
|
private JCheckBox HelipadCheckBox;
|
|
private JPanel CargoPanel;
|
|
private JRadioButton TriangleFormRadioButton;
|
|
private JRadioButton RoundFormRadioButton;
|
|
private JRadioButton RectangleFormRadioButton;
|
|
private JPanel CountOfBlocksPanel;
|
|
private JRadioButton SixRadioButton;
|
|
private JRadioButton FourRadioButton;
|
|
private JRadioButton TwoRadioButton;
|
|
private JButton ShowWarshipButton;
|
|
private JButton ChooseButton;
|
|
private JPanel PictureBox;
|
|
BlockCount block=null;
|
|
IDrawingObjectBlock fblock=null;
|
|
private final CreaterGeneric<EntityWarship,IDrawingObjectBlock> createrGeneric=new CreaterGeneric<>(40,40);
|
|
private DrawingWarship _warship;
|
|
private DrawingWarship selectedWarship;
|
|
|
|
public FormCreater(){
|
|
setTitle("Военный корабль");
|
|
setContentPane(PictureBox);
|
|
setResizable(false);
|
|
setSize(1000,500);
|
|
ShowWindow();
|
|
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
|
|
}
|
|
|
|
@Override
|
|
public void paint(Graphics g) {
|
|
super.paint(g);
|
|
Graphics2D g2d = (Graphics2D) PictureBox.getGraphics();
|
|
if (_warship != null) {
|
|
_warship.DrawTransport(g2d);
|
|
}
|
|
}
|
|
private void ShowWindow(){
|
|
|
|
TwoRadioButton.addActionListener(e -> {
|
|
block=BlockCount.TwoBlocks;
|
|
});
|
|
FourRadioButton.addActionListener(e -> {
|
|
block=BlockCount.FourBlocks;
|
|
});
|
|
SixRadioButton.addActionListener(e -> {
|
|
block=BlockCount.SixBlocks;
|
|
});
|
|
|
|
RectangleFormRadioButton.addActionListener(e -> {
|
|
if(block==null){
|
|
return;
|
|
}
|
|
fblock=new DrawingBlock(block);
|
|
if(fblock==null)
|
|
return;
|
|
fblock.SetBlockCount(block.GetBlockCount());
|
|
createrGeneric.Add(fblock);
|
|
});
|
|
|
|
RoundFormRadioButton.addActionListener(e -> {
|
|
if(block==null){
|
|
return;
|
|
}
|
|
fblock=new DrawingRoundBlocks(block);
|
|
if(fblock==null)
|
|
return;
|
|
fblock.SetBlockCount(block.GetBlockCount());
|
|
createrGeneric.Add(fblock);
|
|
});
|
|
|
|
TriangleFormRadioButton.addActionListener(e -> {
|
|
if(block==null){
|
|
return;
|
|
}
|
|
fblock=new DrawingTriangleBlocks(block);
|
|
if(fblock==null)
|
|
return;
|
|
fblock.SetBlockCount(block.GetBlockCount());
|
|
createrGeneric.Add(fblock);
|
|
});
|
|
|
|
BasicRadioButton.addActionListener(e -> {
|
|
Color color=JColorChooser.showDialog(this,"Выберите цвет корпуса корабля",Color.WHITE);
|
|
if(Integer.parseInt(SpeedTextField.getText())==0 || Integer.parseInt(WeightTextField.getText())==0 || color==null){
|
|
return;
|
|
}
|
|
createrGeneric.Add(new EntityWarship(Integer.parseInt(SpeedTextField.getText()),Integer.parseInt(WeightTextField.getText()),color));
|
|
});
|
|
|
|
AdvancedRadioButton.addActionListener(e -> {
|
|
Color color1=JColorChooser.showDialog(this,"Выберите цвет корпуса корабля",Color.WHITE);
|
|
if(Integer.parseInt(SpeedTextField.getText())==0 || Integer.parseInt(WeightTextField.getText())==0 || color1==null){
|
|
return;
|
|
}
|
|
Color color2=JColorChooser.showDialog(this,"Выберите цвет модификаций корабля",Color.WHITE);
|
|
if(color2==null){
|
|
return;
|
|
}
|
|
createrGeneric.Add(new EntityAdvancedWarship(Integer.parseInt(SpeedTextField.getText()),Integer.parseInt(WeightTextField.getText()),
|
|
color1,color2,HelipadCheckBox.isSelected(),AntennaCheckBox.isSelected(),MissileCheckBox.isSelected()));
|
|
});
|
|
|
|
ShowWarshipButton.addActionListener(e -> {
|
|
Random rand=new Random();
|
|
_warship=createrGeneric.NewWarshipCreating();
|
|
_warship.SetPosition(rand.nextInt(100),rand.nextInt(100),getWidth(),getHeight());
|
|
repaint();
|
|
});
|
|
ChooseButton.addActionListener(e -> {
|
|
selectedWarship=_warship;
|
|
dispose();
|
|
});
|
|
}
|
|
public DrawingWarship getSelectedWarship() {
|
|
return selectedWarship;
|
|
}
|
|
}
|