PIbd-21_Putintsev_D.M._Road.../src/RoadTrain/FormGenericDopClass.java

65 lines
2.2 KiB
Java
Raw Permalink Normal View History

package RoadTrain;
import RoadTrain.DrawingObjects.*;
import RoadTrain.Entities.*;
import RoadTrain.Extra.*;
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 FormGenericDopClass extends JFrame {
static int pictureBoxWidth = 980;
static int pictureBoxHeight = 560;
public DrawingTruck _drawingTruck;
private class Canvas extends JComponent{
public Canvas(){
}
public void paintComponent (Graphics g){
if (_drawingTruck == null){
return;
}
super.paintComponents (g) ;
Graphics2D g2d = (Graphics2D)g;
_drawingTruck.SetPosition(50, 50);
_drawingTruck.DrawTransport(g2d);
super.repaint();
}
}
GenericDopClass<EntityTruck, IDrawingWheels> genericDopClass;
public FormGenericDopClass(){
_drawingTruck = null;
Canvas canv = new Canvas();
setSize (1000, 600);
setLayout(null);
canv.setBounds(0,0,pictureBoxWidth, pictureBoxHeight);
genericDopClass = new GenericDopClass<>(100, 100, pictureBoxWidth, pictureBoxHeight);
2023-11-25 00:19:05 +04:00
genericDopClass.add(new EntityTruck(100, 100, Color.BLUE, 1));
genericDopClass.add(new EntityTruck(100, 100, Color.RED, 2));
genericDopClass.add(new EntityTruck(100, 100, Color.GRAY, 1));
genericDopClass.add(new EntityRoadTrain(100, 100, Color.BLUE, 3, Color.ORANGE, true, true));
genericDopClass.add(new DrawingOneLineWheels());
genericDopClass.add(new DrawingTwoLineWheels());
JButton createButton = new JButton("Создать");
createButton.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e){
_drawingTruck = genericDopClass.getDrawingObject();
canv.repaint();
}
}
);
createButton.setBounds(pictureBoxWidth/2, pictureBoxHeight-20, 120, 20);
add(canv);
add(createButton);
setVisible(true);
}
}