135 lines
5.2 KiB
Java
135 lines
5.2 KiB
Java
import javax.swing.*;
|
|
import java.awt.*;
|
|
import java.util.Random;
|
|
|
|
public class FormCreater extends JDialog{
|
|
private JButton ChooseButton;
|
|
private JButton ShowGasolineTankerButton;
|
|
private JTextField SpeedTextField;
|
|
private JTextField WeightTextField;
|
|
private JCheckBox BodyKitCheckBox;
|
|
private JCheckBox AntennaCheckBox;
|
|
private JRadioButton BasicRadioButton;
|
|
private JRadioButton AdvancedRadioButton;
|
|
private JRadioButton TwoRadioButton;
|
|
private JRadioButton ThreeRadioButton;
|
|
private JRadioButton FourRadioButton;
|
|
private JRadioButton NotOrnament;
|
|
private JRadioButton RedOrnament;
|
|
private JRadioButton GrayOrnament;
|
|
private JLabel SetSpeedLabel;
|
|
private JLabel SetWeightLabel;
|
|
private JPanel PictureBox;
|
|
CountWheels wheels=null;
|
|
IDrawningObjectWheels fwheels=null;
|
|
private final CreaterGeneric<EntityGasolineTanker,IDrawningObjectWheels> createrGeneric=new CreaterGeneric<>(40,40);
|
|
private DrawingGasolineTanker _gasolineTanker;
|
|
private DrawingGasolineTanker selectedGasolineTanker;
|
|
|
|
ImageIcon spriteUp =new ImageIcon((new ImageIcon("Material\\KeyUp.png")).
|
|
getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH));
|
|
ImageIcon spriteDown =new ImageIcon((new ImageIcon("Material\\KeyDown.png")).
|
|
getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH));
|
|
ImageIcon spriteLeft =new ImageIcon((new ImageIcon("Material\\KeyLeft.png")).
|
|
getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH));
|
|
ImageIcon spriteRight =new ImageIcon((new ImageIcon("Material\\KeyRight.png")).
|
|
getImage().getScaledInstance(10,10,Image.SCALE_SMOOTH));
|
|
public FormCreater(){
|
|
setTitle("Gasoline tanker");
|
|
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 (_gasolineTanker != null) {
|
|
_gasolineTanker.DrawTransport(g2d);
|
|
}
|
|
}
|
|
private void ShowWindow(){
|
|
|
|
TwoRadioButton.addActionListener(e -> {
|
|
wheels=CountWheels.Two;
|
|
});
|
|
ThreeRadioButton.addActionListener(e -> {
|
|
wheels=CountWheels.Three;
|
|
});
|
|
FourRadioButton.addActionListener(e -> {
|
|
wheels=CountWheels.Four;
|
|
});
|
|
|
|
NotOrnament.addActionListener(e -> {
|
|
if(wheels==null){
|
|
return;
|
|
}
|
|
fwheels=new DrawingWheels(wheels);
|
|
if(fwheels==null)
|
|
return;
|
|
fwheels.SetCountWheels(wheels.getCountWheels());
|
|
createrGeneric.AddWheels(fwheels);
|
|
});
|
|
|
|
RedOrnament.addActionListener(e -> {
|
|
if(wheels==null){
|
|
return;
|
|
}
|
|
fwheels=new DrawingOrnamentWheelsSecond(wheels);
|
|
if(fwheels==null)
|
|
return;
|
|
fwheels.SetCountWheels(wheels.getCountWheels());
|
|
createrGeneric.AddWheels(fwheels);
|
|
});
|
|
|
|
GrayOrnament.addActionListener(e -> {
|
|
if(wheels==null){
|
|
return;
|
|
}
|
|
fwheels=new DrawingOrnamentWheelsFirst(wheels);
|
|
if(fwheels==null)
|
|
return;
|
|
fwheels.SetCountWheels(wheels.getCountWheels());
|
|
createrGeneric.AddWheels(fwheels);
|
|
});
|
|
|
|
BasicRadioButton.addActionListener(e -> {
|
|
Color color=JColorChooser.showDialog(this,"Select body color",Color.WHITE);
|
|
if(Integer.parseInt(SpeedTextField.getText())==0 || Integer.parseInt(WeightTextField.getText())==0 || color==null){
|
|
return;
|
|
}
|
|
createrGeneric.AddGasolineTanker(new EntityGasolineTanker(Integer.parseInt(SpeedTextField.getText()),Integer.parseInt(WeightTextField.getText()),color));
|
|
});
|
|
|
|
AdvancedRadioButton.addActionListener(e -> {
|
|
Color color1=JColorChooser.showDialog(this,"Select body color",Color.WHITE);
|
|
if(Integer.parseInt(SpeedTextField.getText())==0 || Integer.parseInt(WeightTextField.getText())==0 || color1==null){
|
|
return;
|
|
}
|
|
Color color2=JColorChooser.showDialog(this,"Select modification color",Color.WHITE);
|
|
if(color2==null){
|
|
return;
|
|
}
|
|
createrGeneric.AddGasolineTanker(new EntityImprovedGasolineTanker(Integer.parseInt(SpeedTextField.getText()),Integer.parseInt(WeightTextField.getText()),
|
|
color1,color2, BodyKitCheckBox.isSelected(),AntennaCheckBox.isSelected()));
|
|
});
|
|
|
|
ShowGasolineTankerButton.addActionListener(e -> {
|
|
Random rand=new Random();
|
|
_gasolineTanker=createrGeneric.NewGasolineTankerCreating();
|
|
_gasolineTanker.SetPosition(rand.nextInt(100),rand.nextInt(100),getWidth(),getHeight());
|
|
repaint();
|
|
});
|
|
ChooseButton.addActionListener(e -> {
|
|
selectedGasolineTanker=_gasolineTanker;
|
|
dispose();
|
|
});
|
|
}
|
|
public DrawingGasolineTanker getSelectedGasolineTanker() {
|
|
return selectedGasolineTanker;
|
|
}
|
|
}
|