Borschevskaya A.A. Lab Work 1 Hard #1
@ -12,12 +12,12 @@
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="cfb06" binding="drawPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<grid id="cfb06" binding="drawPanel" custom-create="true" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="2" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-4473925"/>
|
||||
<background color="-1"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
|
@ -38,12 +38,6 @@ public class FormCar extends JFrame{
|
||||
labelWeight.setText("Вес: ");
|
||||
labelColor.setText("Цвет: ");
|
||||
|
||||
|
||||
|
||||
|
||||
Canvas canvas = new Canvas();
|
||||
drawPanel.add(canvas);
|
||||
|
||||
buttonCreate.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
@ -55,7 +49,6 @@ public class FormCar extends JFrame{
|
||||
armoredCar.SetPosition(rnd.nextInt(90) + 10, rnd.nextInt(90) + 10,
|
||||
drawPanel.getWidth(), drawPanel.getHeight());
|
||||
|
||||
canvas.setArmoredCar(armoredCar);
|
||||
labelSpeed.setText("Скорость: " + armoredCar.armoredCar.getSpeed());
|
||||
labelWeight.setText("Вес: " + armoredCar.armoredCar.getWeight());
|
||||
labelColor.setText("Цвет: " + armoredCar.armoredCar.getWeight());
|
||||
@ -67,7 +60,7 @@ public class FormCar extends JFrame{
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
if (armoredCar != null)
|
||||
armoredCar.MoveTransport(Direction.Up);
|
||||
canvas.repaint();
|
||||
drawPanel.repaint();
|
||||
}
|
||||
});
|
||||
|
||||
@ -76,7 +69,8 @@ public class FormCar extends JFrame{
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
if (armoredCar != null)
|
||||
armoredCar.MoveTransport(Direction.Down);
|
||||
canvas.repaint();
|
||||
drawPanel.repaint();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
@ -85,7 +79,7 @@ public class FormCar extends JFrame{
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
if (armoredCar != null)
|
||||
armoredCar.MoveTransport(Direction.Left);
|
||||
canvas.repaint();
|
||||
drawPanel.repaint();
|
||||
}
|
||||
});
|
||||
|
||||
@ -94,31 +88,25 @@ public class FormCar extends JFrame{
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
if (armoredCar != null)
|
||||
armoredCar.MoveTransport(Direction.Right);
|
||||
canvas.repaint();
|
||||
drawPanel.repaint();
|
||||
}
|
||||
});
|
||||
|
||||
setContentPane(mainPanel);
|
||||
setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
class Canvas extends JPanel {
|
||||
private DrawingArmoredCar armoredCar;
|
||||
public Canvas () {
|
||||
super();
|
||||
private void createUIComponents() {
|
||||
drawPanel = new JPanel() {
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
if (armoredCar != null) {
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
armoredCar.DrawTransport(g2d);
|
||||
}
|
||||
super.repaint();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void setArmoredCar(DrawingArmoredCar armoredCar) {
|
||||
this.armoredCar = armoredCar;
|
||||
}
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
if (armoredCar != null) {
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
armoredCar.DrawTransport(g2d);
|
||||
}
|
||||
super.repaint();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user