115 lines
4.2 KiB
Java
115 lines
4.2 KiB
Java
|
import javax.imageio.*;
|
|||
|
import javax.swing.*;
|
|||
|
import java.awt.*;
|
|||
|
import java.awt.event.*;
|
|||
|
import java.awt.image.*;
|
|||
|
import java.util.*;
|
|||
|
|
|||
|
public class FormShip {
|
|||
|
private JToolBar statusStrip;
|
|||
|
public JPanel Mainpanel;
|
|||
|
private DrawingShip pictureShip;
|
|||
|
private JButton buttonRight;
|
|||
|
private JButton buttonCreate;
|
|||
|
private JButton buttonLeft;
|
|||
|
private JButton buttonUp;
|
|||
|
private JButton buttonDown;
|
|||
|
private JLabel JLabelSpeed = new JLabel();
|
|||
|
private JLabel JLabelWeight = new JLabel();
|
|||
|
private JLabel JLabelColor = new JLabel();
|
|||
|
|
|||
|
private void Draw()
|
|||
|
{
|
|||
|
if (pictureShip.GetWarmlyShip() == null) return;
|
|||
|
pictureShip.DrawTransport();
|
|||
|
}
|
|||
|
|
|||
|
private void ButtonMove_Click(String name)
|
|||
|
{
|
|||
|
if (pictureShip == null) return;
|
|||
|
switch (name)
|
|||
|
{
|
|||
|
case "buttonLeft":
|
|||
|
pictureShip.MoveTransport(Direction.Left);
|
|||
|
break;
|
|||
|
case "buttonUp":
|
|||
|
pictureShip.MoveTransport(Direction.Up);
|
|||
|
break;
|
|||
|
case "buttonRight":
|
|||
|
pictureShip.MoveTransport(Direction.Right);
|
|||
|
break;
|
|||
|
case "buttonDown":
|
|||
|
pictureShip.MoveTransport(Direction.Down);
|
|||
|
break;
|
|||
|
}
|
|||
|
Draw();
|
|||
|
}
|
|||
|
|
|||
|
public FormShip() {
|
|||
|
Box LabelBox = Box.createHorizontalBox();
|
|||
|
LabelBox.setMinimumSize(new Dimension(1, 20));
|
|||
|
LabelBox.add(JLabelSpeed);
|
|||
|
LabelBox.add(JLabelWeight);
|
|||
|
LabelBox.add(JLabelColor);
|
|||
|
statusStrip.add(LabelBox);
|
|||
|
|
|||
|
try {
|
|||
|
Image img = ImageIO.read(FormShip.class.getResource("/Images/totop.png"));
|
|||
|
buttonUp.setIcon(new ImageIcon(img));
|
|||
|
img = ImageIO.read(FormShip.class.getResource("/Images/toleft.png"));
|
|||
|
buttonLeft.setIcon(new ImageIcon(img));
|
|||
|
img = ImageIO.read(FormShip.class.getResource("/Images/todown.png"));
|
|||
|
buttonDown.setIcon(new ImageIcon(img));
|
|||
|
img = ImageIO.read(FormShip.class.getResource("/Images/toright.png"));
|
|||
|
buttonRight.setIcon(new ImageIcon(img));
|
|||
|
} catch (Exception ex) {
|
|||
|
System.out.println(ex);
|
|||
|
}
|
|||
|
|
|||
|
buttonCreate.addActionListener(new ActionListener() {
|
|||
|
@Override
|
|||
|
public void actionPerformed(ActionEvent e) {
|
|||
|
Random random = new Random();
|
|||
|
pictureShip.Init(random.nextInt(100, 300), random.nextInt(1000, 2000), new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)));
|
|||
|
pictureShip.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100), pictureShip.getWidth(), pictureShip.getHeight());
|
|||
|
JLabelSpeed.setText("Cкорость: " + pictureShip.GetWarmlyShip().GetSpeed() + " ");
|
|||
|
JLabelWeight.setText("Вес: " + pictureShip.GetWarmlyShip().GetWeight() + " ");
|
|||
|
JLabelColor.setText(("Цвет: " + pictureShip.GetWarmlyShip().GetBodyColor() + " "));
|
|||
|
Draw();
|
|||
|
}
|
|||
|
});
|
|||
|
buttonUp.addActionListener(new ActionListener() {
|
|||
|
@Override
|
|||
|
public void actionPerformed(ActionEvent e) {
|
|||
|
ButtonMove_Click("buttonUp");
|
|||
|
}
|
|||
|
});
|
|||
|
buttonLeft.addActionListener(new ActionListener() {
|
|||
|
@Override
|
|||
|
public void actionPerformed(ActionEvent e) {
|
|||
|
ButtonMove_Click("buttonLeft");
|
|||
|
}
|
|||
|
});
|
|||
|
buttonDown.addActionListener(new ActionListener() {
|
|||
|
@Override
|
|||
|
public void actionPerformed(ActionEvent e) {
|
|||
|
ButtonMove_Click("buttonDown");
|
|||
|
}
|
|||
|
});
|
|||
|
buttonRight.addActionListener(new ActionListener() {
|
|||
|
@Override
|
|||
|
public void actionPerformed(ActionEvent e) {
|
|||
|
ButtonMove_Click("buttonRight");
|
|||
|
}
|
|||
|
});
|
|||
|
pictureShip.addComponentListener(new ComponentAdapter() {
|
|||
|
@Override
|
|||
|
public void componentResized(ComponentEvent e) {
|
|||
|
super.componentResized(e);
|
|||
|
pictureShip.ChangeBorders(pictureShip.getWidth(), pictureShip.getHeight());
|
|||
|
Draw();
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
}
|