135 lines
5.2 KiB
Java
135 lines
5.2 KiB
Java
import javax.swing.*;
|
|
import java.awt.*;
|
|
import java.awt.event.ActionEvent;
|
|
import java.awt.event.ActionListener;
|
|
import java.util.Random;
|
|
|
|
public class RandomFrame extends JFrame {
|
|
RandomPanel panel = new RandomPanel();
|
|
RandomFrame() {
|
|
this.setSize(710, 535);
|
|
this.setTitle("CruiserRandom");
|
|
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
this.setResizable(false);
|
|
this.setLocationRelativeTo(null);
|
|
this.add(panel);
|
|
this.setVisible(true);
|
|
}
|
|
public class RandomPanel extends JPanel {
|
|
static final int SCREEN_W = 700;
|
|
static final int SCREEN_H = 500;
|
|
GenericCreate<EntityCruiser, IDop> _genericCreate = new GenericCreate<>(10, 10);
|
|
ComponentsPanel entitiesPanel = new ComponentsPanel();
|
|
ComponentsPanel wheelsPanel = new ComponentsPanel();
|
|
DrawingCruiser generatedCruiser;
|
|
RandomPanel() {
|
|
this.setLayout(null);
|
|
this.setPreferredSize(new Dimension(SCREEN_W, SCREEN_H));
|
|
JButton buttonCruiser = new JButton("Создать простой объект");
|
|
buttonCruiser.setBounds(20, 20, 130, 30);
|
|
buttonCruiser.addActionListener(new ActionListener() {
|
|
@Override
|
|
public void actionPerformed(ActionEvent e) {
|
|
GameFrame dialogWindow = new GameFrame();
|
|
if (dialogWindow.getSelectedCruiser() != null){
|
|
if (dialogWindow.getSelectedCruiser() instanceof DrawingAdvancedCruiser) {
|
|
_genericCreate.Add(((DrawingAdvancedCruiser) dialogWindow.getSelectedCruiser()).getEntityCruiser());
|
|
}
|
|
else {
|
|
_genericCreate.Add(dialogWindow.getSelectedCruiser().EntityCruiser);
|
|
}
|
|
repaint();}
|
|
|
|
else{
|
|
System.out.println("Selected cruiser is null!");
|
|
}
|
|
}
|
|
});
|
|
this.add(buttonCruiser);
|
|
JButton buttonIDop = new JButton("Создать палубы");
|
|
buttonIDop.addActionListener(new ActionListener() {
|
|
@Override
|
|
public void actionPerformed(ActionEvent e) {
|
|
Random random = new Random();
|
|
IDop interWheels;
|
|
switch(random.nextInt(1, 4)){
|
|
case 1:
|
|
interWheels = new NumberOfWheels(random.nextInt(2, 5));
|
|
break;
|
|
case 2:
|
|
interWheels = new DopClassRect(random.nextInt(2, 5));
|
|
break;
|
|
default:
|
|
interWheels = new DopClassMixed(random.nextInt(2, 5));
|
|
break;
|
|
}
|
|
|
|
_genericCreate.Add(interWheels);
|
|
repaint();
|
|
|
|
}
|
|
});
|
|
buttonIDop.setBounds(20 + 130 + 20, 20, 130, 30);
|
|
this.add(buttonIDop);
|
|
JButton buttonCreateRandomCruiser = new JButton("Сгенерировать объект");
|
|
buttonCreateRandomCruiser.addActionListener(new ActionListener() {
|
|
@Override
|
|
public void actionPerformed(ActionEvent e) {
|
|
generatedCruiser = _genericCreate.DrawingGeneratedCruiser();
|
|
if (generatedCruiser != null) {
|
|
generatedCruiser.SetPosition(430, 160);
|
|
}
|
|
repaint();
|
|
}
|
|
});
|
|
buttonCreateRandomCruiser.setBounds(20 + 130 + 20 + 235, 20 + 80, 190, 30);
|
|
this.add(buttonCreateRandomCruiser);
|
|
}
|
|
@Override
|
|
public void paintComponent(Graphics g) {
|
|
super.paintComponent(g);
|
|
draw(g);
|
|
}
|
|
public void draw(Graphics g) {
|
|
int startX = 20 ;
|
|
int startY = 70;
|
|
int startXForWheels = 170;
|
|
int startYForWheels = 30;
|
|
int height = 70;
|
|
int width = 110;
|
|
_genericCreate.DrawEntitiesCruiser(g, startX, startY);
|
|
for (int i=0; i < _genericCreate.getWheels().size(); i++) {
|
|
_genericCreate.getWheels().get(i).drawWheels(g, startXForWheels, startYForWheels + i * 30, Color.black);
|
|
}
|
|
if (generatedCruiser != null){
|
|
generatedCruiser.DrawTransport(g);
|
|
}
|
|
}
|
|
}
|
|
|
|
public class ComponentsPanel extends JPanel {
|
|
static final int SCREEN_W = 130;
|
|
static final int SCREEN_H = 400;
|
|
|
|
ComponentsPanel() {
|
|
this.setSize(SCREEN_W, SCREEN_H);
|
|
}
|
|
@Override
|
|
public void paintComponent(Graphics g) {
|
|
super.paintComponent(g);
|
|
}
|
|
public void draw(Graphics g) {
|
|
}
|
|
}
|
|
public class CarRandomPanel extends JPanel {
|
|
static final int SCREEN_W = 200;
|
|
static final int SCREEN_H = 200;
|
|
@Override
|
|
public void paintComponent(Graphics g) {
|
|
super.paintComponent(g);
|
|
draw(g);
|
|
}
|
|
public void draw(Graphics g) {
|
|
}
|
|
}
|
|
} |