arrays form

This commit is contained in:
ShabOl 2023-12-12 18:47:15 +04:00
parent f518b62cdf
commit 6dadff7aea
3 changed files with 108 additions and 7 deletions

View File

@ -3,11 +3,112 @@ package AirBomber;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import AirBomber.Generics.EntitiesGenericCollection;
import AirBomber.MovementStrategy.ObjectEntityRenderer;
import AirBomber.Rendering.BomberRendererBase;
import java.awt.image.BufferedImage;
import java.util.Random;
import AirBomber.Entities.*;
import AirBomber.Generics.*;
import AirBomber.Rendering.*;
public class FormArrays extends JFrame
{
private ArraysGeneric<BomberEntityBase, IEngineRenderer> Arrays;
public FormArrays()
{
InitializeComponent();
Random Random = new Random();
int MaxCount = Random.nextInt(2, 4);
Arrays = new ArraysGeneric<>(MaxCount, MaxCount, PictureBox.getWidth(), PictureBox.getHeight());
for (int i = 0; i < MaxCount; i++)
{
/** Добавление сущности */
Arrays.Add(new BomberEntityBase(
Random.nextInt(100, 300),
Random.nextInt(1000, 3000),
new Color(Random.nextInt(0, 256), Random.nextInt(0, 256), Random.nextInt(0, 256))
));
/** Добавление IEngineRenderer */
IEngineRenderer EngineRenderer = null;
int EngineRendererVariant = Random.nextInt(1, 4);
switch (EngineRendererVariant) {
case 1:
EngineRenderer = new EngineRenderer();
break;
case 2:
EngineRenderer = new RectangleEngineRenderer();
break;
case 3:
EngineRenderer = new TriangleEngineRenderer();
break;
default:
break;
}
EngineRenderer.SetAmount(Random.nextInt(1, 7));
Arrays.Add(EngineRenderer);
}
}
private void Draw(BomberRendererBase Renderer)
{
BufferedImage bmp = new BufferedImage(
PictureBox.getWidth(),
PictureBox.getHeight(),
BufferedImage.TYPE_INT_ARGB
);
Graphics2D g = bmp.createGraphics();
Renderer.DrawEntity(g);
PictureBox.setIcon(new ImageIcon(bmp));
}
private void ButtonCreate_Click(ActionEvent e)
{
BomberRendererBase Renderer = Arrays.CreateObject();
Renderer.SetPosition(100, 100);
Draw(Renderer);
}
private void InitializeComponent()
{
PictureBox = new JLabel();
ButtonCreate = new JButton();
//
// ButtonCreate
//
ButtonCreate.setName("ButtonCreate");
ButtonCreate.setBounds(12, 419, 80, 30);
ButtonCreate.setText("Создать");
ButtonCreate.setBackground(new Color(225, 225, 225));
ButtonCreate.setFont(new Font("Segoe UI", Font.PLAIN, 11));
ButtonCreate.setFocusable(false);
ButtonCreate.addActionListener(e -> ButtonCreate_Click(e));
//
// PictureBox
//
PictureBox.setBounds(0, 0, 884, 461);
//
// BomberForm
//
setTitle("Усложнение");
setSize(900, 500);
setLayout(null);
setLocationRelativeTo(null);
setVisible(true);
add(PictureBox);
add(ButtonCreate);
}
private JButton ButtonCreate;
private JLabel PictureBox;
}

View File

@ -58,11 +58,11 @@ public class ArraysGeneric <T extends BomberEntityBase, U extends IEngineRendere
Random Random = new Random();
int EntityIndex = Random.nextInt(_entitiesCount);
int RendererIndex = Random.nextInt(_renderersCount);
int EngineRendererIndex = Random.nextInt(_renderersCount);
T Entity = _entities.get(EntityIndex);
U Renderer = _renderers.get(RendererIndex);
U EngineRenderer = _renderers.get(EngineRendererIndex);
return new BomberRendererBase(Entity, Renderer, _pictureWidth, _pictureHeight);
return new BomberRendererBase(Entity, EngineRenderer, _pictureWidth, _pictureHeight);
}
}

View File

@ -3,6 +3,6 @@ package AirBomber;
public class Program {
public static void main(String[] args) throws Exception
{
new FormEntityCollection();
new FormArrays();
}
}