54 lines
2.0 KiB
Java
54 lines
2.0 KiB
Java
import java.awt.*;
|
|
import javax.swing.*;
|
|
import java.awt.event.*;
|
|
public class NewFormRand extends JFrame {
|
|
static int pictureBoxWidth = 960;
|
|
static int pictureBoxHeight = 560;
|
|
public DrawingShip _drawingShip;
|
|
private class Canvas extends JComponent{
|
|
public Canvas(){
|
|
}
|
|
public void paintComponent (Graphics g){
|
|
if (_drawingShip == null){
|
|
return;
|
|
}
|
|
super.paintComponents (g) ;
|
|
Graphics2D g2d = (Graphics2D)g;
|
|
_drawingShip.SetPosition(100, 100);
|
|
_drawingShip.DrawShip(g2d);
|
|
super.repaint();
|
|
}
|
|
}
|
|
ShipGenericDop<EntityShip, IDecksDrawing> _ShipGenericDop;
|
|
public NewFormRand(){
|
|
_drawingShip = null;
|
|
Canvas canv = new Canvas();
|
|
setSize(1000, 600);
|
|
setLayout(null);
|
|
_ShipGenericDop = new ShipGenericDop<>(50,50,pictureBoxWidth,pictureBoxHeight);
|
|
canv.setBounds(0, 0, pictureBoxWidth, pictureBoxHeight);
|
|
_ShipGenericDop.Add(new EntityShip(200,200,Color.PINK));
|
|
_ShipGenericDop.Add(new EntityShip(200,200,Color.GRAY));
|
|
_ShipGenericDop.Add(new EntityContainerShip(200, 200, Color.GREEN, Color.BLUE, true, false, 2, 1));
|
|
_ShipGenericDop.Add(new EntityContainerShip(200, 200, Color.LIGHT_GRAY, Color.MAGENTA, false, true, 3, 3));
|
|
_ShipGenericDop.Add(new DrawingDecks());
|
|
_ShipGenericDop.Add(new DrawingDecksRect());
|
|
_ShipGenericDop.Add(new DrawingDecksTrapez());
|
|
JButton creatButton = new JButton("создать");
|
|
creatButton.addActionListener(
|
|
new ActionListener() {
|
|
public void actionPerformed(ActionEvent e){
|
|
_drawingShip = _ShipGenericDop.getObjectRandomShip();
|
|
canv.repaint();
|
|
}
|
|
}
|
|
);
|
|
creatButton.setBounds(820, 490, 120, 20);
|
|
|
|
add(canv);
|
|
add(creatButton);
|
|
setVisible(true);
|
|
}
|
|
}
|
|
|