97 lines
4.2 KiB
Java
97 lines
4.2 KiB
Java
|
package MonorailHard;
|
||
|
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 Main {
|
||
|
public static void main(String[] args) throws IOException {
|
||
|
JFrame MonorailFrame = new JFrame();
|
||
|
JPanel MonorailPanel = new JPanel();
|
||
|
MonorailFrame.setLayout(new BorderLayout());
|
||
|
MonorailFrame.setSize(900, 500);
|
||
|
MonorailFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||
|
MonorailFrame.setLayout(new BorderLayout(1,1));
|
||
|
DrawningMonorail DrawningMonorail = new DrawningMonorail();
|
||
|
MonorailPanel.setLayout(null);
|
||
|
BufferedImage RightIcon = ImageIO.read(new File("RightButton.png"));
|
||
|
BufferedImage LeftIcon = ImageIO.read(new File("LeftButton.png"));
|
||
|
BufferedImage UpIcon = ImageIO.read(new File("UpButton.png"));
|
||
|
BufferedImage DownIcon = ImageIO.read(new File("DownButton.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("Создать");
|
||
|
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);
|
||
|
MonorailPanel.add(CreateButton);
|
||
|
MonorailPanel.add(RightButton);
|
||
|
MonorailPanel.add(LeftButton);
|
||
|
MonorailPanel.add(UpButton);
|
||
|
MonorailPanel.add(DownButton);
|
||
|
MonorailFrame.add(MonorailPanel, BorderLayout.CENTER);
|
||
|
Random random = new Random();
|
||
|
CreateButton.addActionListener(new ActionListener() {
|
||
|
@Override
|
||
|
public void actionPerformed(ActionEvent e) {
|
||
|
DrawningMonorail.Init(random.nextInt(100, 300), random.nextDouble(1000, 3000),
|
||
|
Color.getHSBColor(random.nextInt(0, 301), random.nextInt(0, 301), random.nextInt(0, 301)),
|
||
|
Color.getHSBColor(random.nextInt(0, 301), random.nextInt(0, 301), random.nextInt(0, 301)),
|
||
|
Color.getHSBColor(random.nextInt(0, 301), random.nextInt(0, 301), random.nextInt(0, 301)),
|
||
|
random.nextInt(2, 5),
|
||
|
MonorailPanel.getWidth(), MonorailPanel.getHeight(), random.nextBoolean(), random.nextBoolean(), MonorailPanel);
|
||
|
DrawningMonorail.DrawMonorail();
|
||
|
}
|
||
|
});
|
||
|
RightButton.addActionListener(new ActionListener() {
|
||
|
@Override
|
||
|
public void actionPerformed(ActionEvent e) {
|
||
|
if(DrawningMonorail.EntityMonorail() == null)
|
||
|
return;
|
||
|
DrawningMonorail.MoveTransport(DirectionType.Right);
|
||
|
DrawningMonorail.DrawMonorail();
|
||
|
}
|
||
|
});
|
||
|
LeftButton.addActionListener(new ActionListener() {
|
||
|
@Override
|
||
|
public void actionPerformed(ActionEvent e) {
|
||
|
if(DrawningMonorail.EntityMonorail() == null)
|
||
|
return;
|
||
|
DrawningMonorail.MoveTransport(DirectionType.Left);
|
||
|
DrawningMonorail.DrawMonorail();
|
||
|
}
|
||
|
});
|
||
|
UpButton.addActionListener(new ActionListener() {
|
||
|
@Override
|
||
|
public void actionPerformed(ActionEvent e) {
|
||
|
if(DrawningMonorail.EntityMonorail() == null)
|
||
|
return;
|
||
|
DrawningMonorail.MoveTransport(DirectionType.Up);
|
||
|
DrawningMonorail.DrawMonorail();
|
||
|
}
|
||
|
});
|
||
|
DownButton.addActionListener(new ActionListener() {
|
||
|
@Override
|
||
|
public void actionPerformed(ActionEvent e) {
|
||
|
if(DrawningMonorail.EntityMonorail() == null)
|
||
|
return;
|
||
|
DrawningMonorail.MoveTransport(DirectionType.Down);
|
||
|
DrawningMonorail.DrawMonorail();
|
||
|
}
|
||
|
});
|
||
|
|
||
|
MonorailFrame.setVisible(true);
|
||
|
}
|
||
|
}
|