PIbd-21_Zhirnova_A_E_Double.../FormDoubleDeckerBus.java

95 lines
4.7 KiB
Java
Raw Permalink Normal View History

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Random;
import javax.imageio.ImageIO;
import javax.swing.*;
public class FormDoubleDeckerBus {
public static void main(String[] args) throws IOException {
JFrame DoubleDeckerBusFrame = new JFrame();
JPanel DoubleDeckerBusPanel = new JPanel();
DoubleDeckerBusFrame.setLayout(new BorderLayout());
DoubleDeckerBusFrame.setSize(900, 500);
DoubleDeckerBusFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
DoubleDeckerBusFrame.setLayout(new BorderLayout(1,1));
DrawningDoubleDeckerBus DrawningDoubleDeckerBus = new DrawningDoubleDeckerBus();
DoubleDeckerBusPanel.setLayout(null);
BufferedImage RightIcon = ImageIO.read(new File("C:/Users/User/IdeaProjects/PIbd-21_Zhirnova_A_E_DoubleDeckerBus._Hard/Resources/right.png"));
BufferedImage LeftIcon = ImageIO.read(new File("C:/Users/User/IdeaProjects/PIbd-21_Zhirnova_A_E_DoubleDeckerBus._Hard/Resources/left.png"));
BufferedImage UpIcon = ImageIO.read(new File("C:/Users/User/IdeaProjects/PIbd-21_Zhirnova_A_E_DoubleDeckerBus._Hard/Resources/up.png"));
BufferedImage DownIcon = ImageIO.read(new File("C:/Users/User/IdeaProjects/PIbd-21_Zhirnova_A_E_DoubleDeckerBus._Hard/Resources/down.png"));
JButton RightButton = new JButton(new ImageIcon(RightIcon));
JButton LeftButton = new JButton(new ImageIcon(LeftIcon));
JButton UpButton = new JButton(new ImageIcon(UpIcon));
JButton DownButton = new JButton(new ImageIcon(DownIcon));
JButton CreateButton = new JButton();
CreateButton.setText("Create");
CreateButton.setBounds(12, 401, 90, 40);
RightButton.setBounds(840,411,30,30);
LeftButton.setBounds(768,411,30,30);
UpButton.setBounds(804,375,30,30);
DownButton.setBounds(804,411,30,30);
DoubleDeckerBusPanel.add(CreateButton);
DoubleDeckerBusPanel.add(RightButton);
DoubleDeckerBusPanel.add(LeftButton);
DoubleDeckerBusPanel.add(UpButton);
DoubleDeckerBusPanel.add(DownButton);
DoubleDeckerBusFrame.add(DoubleDeckerBusPanel, BorderLayout.CENTER);
Random random = new Random();
CreateButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
DrawningDoubleDeckerBus.Init(random.nextInt(201) + 100, random.nextDouble() * 2000 + 1000,
Color.getHSBColor(random.nextInt(301), random.nextInt(301), random.nextInt(301)),
Color.getHSBColor(random.nextInt(301), random.nextInt(301), random.nextInt(301)),
random.nextInt(4) + 2, DoubleDeckerBusPanel.getWidth(), DoubleDeckerBusPanel.getHeight(),
random.nextBoolean(), random.nextBoolean(), DoubleDeckerBusPanel);
DrawningDoubleDeckerBus.DrawTransport();
}
});
RightButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(DrawningDoubleDeckerBus.EntityDoubleDeckerBus() == null)
return;
DrawningDoubleDeckerBus.MoveTransport(DirectionType.Right);
DrawningDoubleDeckerBus.DrawTransport();
}
});
LeftButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(DrawningDoubleDeckerBus.EntityDoubleDeckerBus() == null)
return;
DrawningDoubleDeckerBus.MoveTransport(DirectionType.Left);
DrawningDoubleDeckerBus.DrawTransport();
}
});
UpButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(DrawningDoubleDeckerBus.EntityDoubleDeckerBus() == null)
return;
DrawningDoubleDeckerBus.MoveTransport(DirectionType.Up);
DrawningDoubleDeckerBus.DrawTransport();
}
});
DownButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(DrawningDoubleDeckerBus.EntityDoubleDeckerBus() == null)
return;
DrawningDoubleDeckerBus.MoveTransport(DirectionType.Down);
DrawningDoubleDeckerBus.DrawTransport();
}
});
DoubleDeckerBusFrame.setVisible(true);
}
}