PIbd-21_Kouvshinoff_T._A._W.../laba1Loco/Form4GenericDopClass.java
2023-10-23 21:52:50 +04:00

63 lines
2.1 KiB
Java

package laba1Loco;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
public class Form4GenericDopClass extends JFrame {
static int pictureBoxWidth = 980;
static int pictureBoxHeight = 560;
public DrawingTrain _drawingTrain;
private class Canvas extends JComponent{
public Canvas(){
}
public void paintComponent (Graphics g){
if (_drawingTrain == null){
return;
}
super.paintComponents (g) ;
Graphics2D g2d = (Graphics2D)g;
_drawingTrain.SetPosition(50, 50);
_drawingTrain.DrawTransport(g2d);
super.repaint();
}
}
GenericDopClass<EntityTrain, IWheelDrawing> genericDopClass;
public Form4GenericDopClass(){
_drawingTrain = null;
Canvas canv = new Canvas();
setSize (1000, 600);
setLayout(null);
canv.setBounds(0,0,pictureBoxWidth, pictureBoxHeight);
genericDopClass = new GenericDopClass<>(100, 100, pictureBoxWidth, pictureBoxHeight);
genericDopClass.addTrain(new EntityTrain(100, 100, Color.BLUE, 2));
genericDopClass.addTrain(new EntityTrain(100, 100, Color.RED, 3));
genericDopClass.addTrain(new EntityTrain(100, 100, Color.GRAY, 4));
genericDopClass.addTrain(new EntityLoco(100, 100, Color.BLUE, 2, Color.ORANGE, true, true, true));
genericDopClass.addWheel(new WheelDrawingDavidStar());
genericDopClass.addWheel(new WheelDrawingBalls());
JButton creatButton = new JButton("createButton");
creatButton.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e){
_drawingTrain = genericDopClass.getRDrawingObject();
canv.repaint();
}
}
);
creatButton.setBounds(pictureBoxWidth/2, pictureBoxHeight-20, 120, 20);
add(canv);
add(creatButton);
setVisible(true);
}
}