файлы лабораторной

This commit is contained in:
Ivan_Starostin 2023-12-22 20:13:55 +04:00
parent d7792f53c3
commit 59c5a52675

View File

@ -13,7 +13,7 @@ import java.io.IOException;
import java.util.Random;
public class FrameLainer extends JFrame {
private DrawingLainer drawingBattleship;
private DrawingLainer drawingLainer;
private JComponent pictureBox;
public FrameLainer() throws IOException {
super("лайнер");
@ -24,7 +24,7 @@ public class FrameLainer extends JFrame {
public void paintComponent(Graphics graphics){
super.paintComponent(graphics);
Graphics2D graphics2D = (Graphics2D) graphics;
if (drawingBattleship != null) drawingBattleship.drawTransport(graphics2D);
if (drawingLainer != null) drawingLainer.drawTransport(graphics2D);
super.repaint();
}
};
@ -49,7 +49,7 @@ public class FrameLainer extends JFrame {
downButton.setActionCommand("down");
downButton.addActionListener(this::buttonMoveClick);
JPanel panelBattleship = new JPanel(new BorderLayout());
JPanel panelLainer = new JPanel(new BorderLayout());
JPanel createPanel = new JPanel(new BorderLayout());
createPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
JPanel movementPanel = new JPanel(new GridBagLayout());
@ -75,41 +75,41 @@ public class FrameLainer extends JFrame {
setLayout(new BorderLayout());
add(pictureBox);
rightPanel.add(movementPanel, BorderLayout.SOUTH);
panelBattleship.add(rightPanel, BorderLayout.EAST);
panelBattleship.add(createPanel, BorderLayout.WEST);
add(panelBattleship,BorderLayout.CENTER);
panelLainer.add(rightPanel, BorderLayout.EAST);
panelLainer.add(createPanel, BorderLayout.WEST);
add(panelLainer,BorderLayout.CENTER);
setVisible(true);
}
private void buttonCreateClick() {
Random random = new Random();
drawingBattleship = new DrawingLainer();
drawingLainer = new DrawingLainer();
pictureBox.setBounds(0,0,getContentPane().getWidth(),getContentPane().getHeight());
drawingBattleship.init(random.nextInt(200) + 100, random.nextInt(2000) + 1000, new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
drawingLainer.init(random.nextInt(200) + 100, random.nextInt(2000) + 1000, new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)), random.nextBoolean(), random.nextBoolean(), pictureBox.getWidth(), pictureBox.getHeight(), random.nextInt(4));
drawingBattleship.setPosition(random.nextInt(90) + 10, random.nextInt(90) + 10);
drawingLainer.setPosition(random.nextInt(90) + 10, random.nextInt(90) + 10);
draw();
}
private void buttonMoveClick(ActionEvent event) {
if(drawingBattleship == null || drawingBattleship.getEntityLainer() == null)
if(drawingLainer == null || drawingLainer.getEntityLainer() == null)
return;
switch (event.getActionCommand()) {
case "left" :
drawingBattleship.moveTransport(DirectionType.LEFT);
drawingLainer.moveTransport(DirectionType.LEFT);
break;
case "right" :
drawingBattleship.moveTransport(DirectionType.RIGHT);
drawingLainer.moveTransport(DirectionType.RIGHT);
break;
case "up" :
drawingBattleship.moveTransport(DirectionType.UP);
drawingLainer.moveTransport(DirectionType.UP);
break;
case "down" :
drawingBattleship.moveTransport(DirectionType.DOWN);
drawingLainer.moveTransport(DirectionType.DOWN);
break;
}
draw();
}
private void draw() {
if (drawingBattleship == null)
if (drawingLainer == null)
{
return;
}