92 lines
3.1 KiB
Java
92 lines
3.1 KiB
Java
import javax.swing.*;
|
|
import java.awt.*;
|
|
import java.awt.event.ComponentAdapter;
|
|
import java.awt.event.ComponentEvent;
|
|
|
|
public class FormGasolineTanker extends JFrame{
|
|
private int Width;
|
|
private int Height;
|
|
DrawingField field = new DrawingField(this);
|
|
private JButton ButtonDown;
|
|
private JButton ButtonRight;
|
|
private JButton ButtonLeft;
|
|
private JButton ButtonUp;
|
|
private JButton ButtonCreate;
|
|
private JButton ButtonCreateModif;
|
|
public JLabel SpeedLabel;
|
|
public JLabel WeightLabel;
|
|
public JLabel BodyColorLabel;
|
|
private JPanel PictureBox;
|
|
|
|
public FormGasolineTanker(){
|
|
super("Военный корабль");
|
|
setContentPane(PictureBox);
|
|
setSize(1000,700);
|
|
Width = getWidth();
|
|
Height = getHeight();
|
|
ShowWindow();
|
|
field.setBounds(0,0,Width,Height);
|
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
setVisible(true);
|
|
}
|
|
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));
|
|
private void ShowWindow(){
|
|
|
|
ButtonCreate.addActionListener(e -> {
|
|
field.CreateButtonAction();
|
|
ReDraw();
|
|
});
|
|
ButtonCreateModif.addActionListener(e -> {
|
|
field.CreateModifButtonAction();
|
|
ReDraw();
|
|
});
|
|
ButtonUp.setIcon(spriteUp);
|
|
ButtonUp.addActionListener(e -> {
|
|
field.DirectionButtonAction(Direction.Up);
|
|
ReDraw();
|
|
});
|
|
ButtonLeft.setIcon(spriteLeft);
|
|
ButtonLeft.addActionListener(e -> {
|
|
field.DirectionButtonAction(Direction.Left);
|
|
ReDraw();
|
|
});
|
|
ButtonRight.setIcon(spriteRight);
|
|
ButtonRight.addActionListener(e -> {
|
|
field.DirectionButtonAction(Direction.Right);
|
|
ReDraw();
|
|
});
|
|
ButtonDown.setIcon(spriteDown);
|
|
ButtonDown.addActionListener(e -> {
|
|
field.DirectionButtonAction(Direction.Down);
|
|
ReDraw();
|
|
});
|
|
|
|
addComponentListener(new ComponentAdapter() {
|
|
@Override
|
|
public void componentResized(ComponentEvent e){
|
|
super.componentResized(e);
|
|
Width=getWidth();
|
|
Height=getHeight();
|
|
|
|
field.ResizeField();
|
|
ReDraw();
|
|
field.setBounds(0,0,Width,Height);
|
|
}
|
|
});
|
|
}
|
|
private void ReDraw()
|
|
{
|
|
Graphics2D graphics = (Graphics2D) PictureBox.getGraphics();
|
|
graphics.clearRect(0, 0, PictureBox.getWidth(), PictureBox.getHeight());
|
|
PictureBox.paintComponents(graphics);
|
|
field.Draw(graphics);
|
|
}
|
|
}
|