138 lines
4.3 KiB
Java
138 lines
4.3 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;
|
|
|
|
JPanel BottomPanel = new JPanel();
|
|
JPanel CreatePanel = new JPanel();
|
|
JPanel BottomAndCreatePanel = new JPanel();
|
|
JPanel DimentionPanel = new JPanel();
|
|
JPanel UPanel = new JPanel();
|
|
JPanel DPanel = new JPanel();
|
|
JPanel LRPanel = new JPanel();
|
|
|
|
JLabel SpeedLabel = new JLabel("Speed: ");
|
|
JLabel WeightLabel = new JLabel("Weight: ");
|
|
JLabel BodyColorLabel = new JLabel("Color: ");
|
|
|
|
DrawingField field = new DrawingField(this);
|
|
|
|
JButton ButtonCreate=new JButton("Create");
|
|
|
|
Icon iconUp = new ImageIcon("C:\\Users\\kashi\\OneDrive\\Материал\\KeyUp.png");
|
|
JButton ButtonUp=new JButton(iconUp);
|
|
|
|
Icon iconDown = new ImageIcon("C:\\Users\\kashi\\OneDrive\\Материал\\KeyDown.png");
|
|
JButton ButtonDown=new JButton(iconDown);
|
|
|
|
Icon iconRight = new ImageIcon("C:\\Users\\kashi\\OneDrive\\Материал\\KeyRight.png");
|
|
JButton ButtonRight=new JButton(iconRight);
|
|
|
|
Icon iconLeft = new ImageIcon("C:\\Users\\kashi\\OneDrive\\Материал\\KeyLeft.png");
|
|
JButton ButtonLeft=new JButton(iconLeft);
|
|
|
|
|
|
public FormGasolineTanker(){
|
|
super("Gasoline Tanker");
|
|
setSize(800,600);
|
|
Width=getWidth();
|
|
Height=getHeight();
|
|
ShowWindow();
|
|
RefreshWindow();
|
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
setVisible(true);
|
|
}
|
|
|
|
public void ShowWindow(){
|
|
|
|
Dimension dimen=new Dimension(30,30);
|
|
|
|
ButtonUp.setPreferredSize(dimen);
|
|
ButtonUp.addActionListener(e->{
|
|
field.UpButtonAction();
|
|
repaint();
|
|
});
|
|
|
|
ButtonDown.setPreferredSize(dimen);
|
|
ButtonDown.addActionListener(e->{
|
|
field.DownButtonAction();
|
|
repaint();
|
|
});
|
|
|
|
ButtonRight.setPreferredSize(dimen);
|
|
ButtonRight.addActionListener(e->{
|
|
field.RightButtonAction();
|
|
repaint();
|
|
});
|
|
|
|
ButtonLeft.setPreferredSize(dimen);
|
|
ButtonLeft.addActionListener(e->{
|
|
field.LeftButtonAction();
|
|
repaint();
|
|
});
|
|
|
|
LRPanel.setLayout(new FlowLayout(FlowLayout.CENTER,50,0));
|
|
LRPanel.setBackground(new Color(0,0,0,0));
|
|
LRPanel.add(ButtonLeft);
|
|
LRPanel.add(ButtonRight);
|
|
|
|
UPanel.setLayout(new FlowLayout());
|
|
UPanel.setBackground(new Color(0,0,0,0));
|
|
UPanel.add(ButtonUp);
|
|
|
|
DPanel.setLayout(new FlowLayout());
|
|
DPanel.setBackground(new Color(0,0,0,0));
|
|
DPanel.add(ButtonDown);
|
|
|
|
DimentionPanel.setLayout(new BoxLayout(DimentionPanel,BoxLayout.Y_AXIS));
|
|
DimentionPanel.setBackground(new Color(0,0,0,0));
|
|
DimentionPanel.add(UPanel);
|
|
DimentionPanel.add(LRPanel);
|
|
DimentionPanel.add(DPanel);
|
|
add(DimentionPanel);
|
|
|
|
CreatePanel.setLayout(new FlowLayout());
|
|
CreatePanel.setBackground(new Color(0,0,0,0));
|
|
CreatePanel.add(ButtonCreate);
|
|
ButtonCreate.addActionListener(e->{
|
|
field.CreateButtonAction();
|
|
repaint();
|
|
});
|
|
|
|
BottomPanel.setLayout(new FlowLayout());
|
|
BottomPanel.setBackground(new Color(0,0,0,0));
|
|
BottomPanel.add(SpeedLabel);
|
|
BottomPanel.add(WeightLabel);
|
|
BottomPanel.add(BodyColorLabel);
|
|
|
|
BottomAndCreatePanel.setLayout(new BoxLayout(BottomAndCreatePanel,BoxLayout.Y_AXIS));
|
|
BottomAndCreatePanel.setBackground(new Color(0,0,0,0));
|
|
BottomAndCreatePanel.add(CreatePanel);
|
|
BottomAndCreatePanel.add(BottomPanel);
|
|
|
|
add(BottomAndCreatePanel);
|
|
add(field);
|
|
|
|
addComponentListener(new ComponentAdapter() {
|
|
@Override
|
|
public void componentResized(ComponentEvent e) {
|
|
super.componentResized(e);
|
|
Width=getWidth();
|
|
Height=getHeight();
|
|
|
|
field.ResizeField();
|
|
repaint();
|
|
RefreshWindow();
|
|
}
|
|
});
|
|
}
|
|
public void RefreshWindow(){
|
|
field.setBounds(0,0,Width,Height);
|
|
BottomAndCreatePanel.setBounds(-220,Height-110,Width,80);
|
|
DimentionPanel.setBounds(Width-170,Height-170,190,140);
|
|
}
|
|
}
|