Лабораторная работа №1 (1 часть)
This commit is contained in:
parent
087d5d5dfd
commit
bbffa9f730
124
ProjectCleaningCar/.idea/uiDesigner.xml
Normal file
124
ProjectCleaningCar/.idea/uiDesigner.xml
Normal file
@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
</project>
|
@ -3,6 +3,7 @@
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/Resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
|
BIN
ProjectCleaningCar/Resources/Arrow_Down.png
Normal file
BIN
ProjectCleaningCar/Resources/Arrow_Down.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.4 KiB |
BIN
ProjectCleaningCar/Resources/Arrow_Left.png
Normal file
BIN
ProjectCleaningCar/Resources/Arrow_Left.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.4 KiB |
BIN
ProjectCleaningCar/Resources/Arrow_Right.png
Normal file
BIN
ProjectCleaningCar/Resources/Arrow_Right.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.4 KiB |
BIN
ProjectCleaningCar/Resources/Arrow_Up.png
Normal file
BIN
ProjectCleaningCar/Resources/Arrow_Up.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.0 KiB |
6
ProjectCleaningCar/src/DirectionType.java
Normal file
6
ProjectCleaningCar/src/DirectionType.java
Normal file
@ -0,0 +1,6 @@
|
||||
public enum DirectionType {
|
||||
Up,
|
||||
Down,
|
||||
Left,
|
||||
Right
|
||||
}
|
115
ProjectCleaningCar/src/DrawningCleaningCar.java
Normal file
115
ProjectCleaningCar/src/DrawningCleaningCar.java
Normal file
@ -0,0 +1,115 @@
|
||||
import java.awt.*;
|
||||
public class DrawningCleaningCar {
|
||||
private EntityCleaningCar EntityCleaningCar;
|
||||
public EntityCleaningCar getEntityCleaningCar() {
|
||||
return EntityCleaningCar;
|
||||
}
|
||||
private Integer _pictureWidth;
|
||||
private Integer _pictureHeight;
|
||||
private Integer _startPosX;
|
||||
private Integer _startPosY;
|
||||
private final Integer _drawningCarWidth = 135;
|
||||
private final Integer _drawningCarHeight = 60;
|
||||
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, boolean tank, boolean sweepingBrush, boolean flashlight) {
|
||||
EntityCleaningCar = new EntityCleaningCar();
|
||||
EntityCleaningCar.Init(speed, weight, bodyColor, additionalColor, tank, sweepingBrush, flashlight);
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
public boolean SetPictureSize(int width, int height) {
|
||||
if (width < _drawningCarWidth || height < _drawningCarHeight) {return false;}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if (_startPosX != null && _startPosY != null)
|
||||
{
|
||||
if (_startPosX + _drawningCarWidth > _pictureWidth)
|
||||
{
|
||||
_startPosX = -_drawningCarWidth + _pictureWidth;
|
||||
}
|
||||
else if (_startPosX < 0)
|
||||
{
|
||||
_startPosX = 0;
|
||||
}
|
||||
if (_startPosY + _drawningCarHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = -_drawningCarHeight + _pictureHeight;
|
||||
}
|
||||
else if (_startPosY < 0)
|
||||
{
|
||||
_startPosY = 0;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public void SetPosition(int x, int y) {
|
||||
if (_pictureHeight == null || _pictureWidth == null) return;
|
||||
if (x + _drawningCarWidth > _pictureWidth) {
|
||||
_startPosX = _pictureWidth - _drawningCarWidth;
|
||||
} else if (x < 0) {
|
||||
_startPosX = 0;
|
||||
}
|
||||
else {
|
||||
_startPosX = x;
|
||||
}
|
||||
if (y + _drawningCarHeight > _pictureHeight) {
|
||||
_startPosY = _pictureHeight - _drawningCarHeight;
|
||||
} else if (y < 0) {
|
||||
_startPosY = 0;
|
||||
} else {
|
||||
_startPosY = y;
|
||||
}
|
||||
}
|
||||
public boolean MoveTransport(DirectionType directionType) {
|
||||
if (EntityCleaningCar == null || _startPosX == null || _startPosY == null) {
|
||||
return false;
|
||||
}
|
||||
switch (directionType) {
|
||||
case Left:
|
||||
if (_startPosX - EntityCleaningCar.Step() > 0) {
|
||||
_startPosX -= (int) EntityCleaningCar.Step();
|
||||
}
|
||||
return true;
|
||||
case Right:
|
||||
if (_startPosX + _drawningCarWidth + EntityCleaningCar.Step() < _pictureWidth) {
|
||||
_startPosX += (int) EntityCleaningCar.Step();
|
||||
}
|
||||
return true;
|
||||
case Up:
|
||||
if (_startPosY - EntityCleaningCar.Step() > 0) {
|
||||
_startPosY -= (int) EntityCleaningCar.Step();
|
||||
}
|
||||
return true;
|
||||
case Down:
|
||||
if (_startPosY + _drawningCarHeight + EntityCleaningCar.Step() < _pictureHeight) {
|
||||
_startPosY += (int) EntityCleaningCar.Step();
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public void DrawTransport(Graphics g) {
|
||||
if (EntityCleaningCar == null || _startPosX == null || _startPosY == null) {
|
||||
return;
|
||||
}
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
if (EntityCleaningCar.getTank()) {
|
||||
g2d.setColor(EntityCleaningCar.getAdditionalColor());
|
||||
g2d.drawRect(_startPosX, _startPosY, 100, 38);
|
||||
g2d.fillRect(_startPosX, _startPosY, 100, 38);
|
||||
}
|
||||
if (EntityCleaningCar.getSweepingBrush()) {
|
||||
g2d.setColor(EntityCleaningCar.getAdditionalColor());
|
||||
}
|
||||
if (EntityCleaningCar.getFlashLight()) {
|
||||
g2d.setColor(EntityCleaningCar.getAdditionalColor());
|
||||
}
|
||||
g2d.setColor(EntityCleaningCar.getBodyColor());
|
||||
g2d.fillRect(_startPosX, _startPosY + 40, 125, 10);
|
||||
g2d.fillRect(_startPosX + 100, _startPosY + 10, 20, 30);
|
||||
|
||||
}
|
||||
}
|
45
ProjectCleaningCar/src/EntityCleaningCar.java
Normal file
45
ProjectCleaningCar/src/EntityCleaningCar.java
Normal file
@ -0,0 +1,45 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityCleaningCar {
|
||||
private int Speed;
|
||||
public int getSpeed() {
|
||||
return Speed;
|
||||
}
|
||||
private double Weight;
|
||||
public double getWeight() {
|
||||
return Weight;
|
||||
}
|
||||
private Color BodyColor;
|
||||
public Color getBodyColor() {
|
||||
return BodyColor;
|
||||
}
|
||||
private Color AdditionalColor;
|
||||
public Color getAdditionalColor() {
|
||||
return AdditionalColor;
|
||||
}
|
||||
private boolean Tank;
|
||||
public boolean getTank() {
|
||||
return Tank;
|
||||
}
|
||||
private boolean SweepingBrush;
|
||||
public boolean getSweepingBrush() {
|
||||
return SweepingBrush;
|
||||
}
|
||||
private boolean FlashLight;
|
||||
public boolean getFlashLight() {
|
||||
return FlashLight;
|
||||
}
|
||||
public double Step() {
|
||||
return Speed * 200 / Weight;
|
||||
}
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, boolean tank, boolean sweepingBrush, boolean flashLight) {
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
Tank = tank;
|
||||
SweepingBrush = sweepingBrush;
|
||||
FlashLight = flashLight;
|
||||
}
|
||||
|
||||
}
|
84
ProjectCleaningCar/src/FormCleaningCar.form
Normal file
84
ProjectCleaningCar/src/FormCleaningCar.form
Normal file
@ -0,0 +1,84 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormCleaningCar">
|
||||
<grid id="27dc6" binding="pictureBox" layout-manager="GridLayoutManager" row-count="2" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="601" height="395"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="fb60" class="javax.swing.JButton" binding="buttonRight">
|
||||
<constraints>
|
||||
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="6" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="62" height="62"/>
|
||||
<preferred-size width="62" height="62"/>
|
||||
<maximum-size width="62" height="62"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<enabled value="true"/>
|
||||
<horizontalAlignment value="0"/>
|
||||
<horizontalTextPosition value="0"/>
|
||||
<icon value="Arrow_Right.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<vspacer id="cd599">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="3587c" class="javax.swing.JButton" binding="buttonCreate">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="10" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="100" height="60"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<horizontalAlignment value="0"/>
|
||||
<text value="Создать"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="2822e" class="javax.swing.JButton" binding="buttonUp">
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="6" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="62" height="62"/>
|
||||
<preferred-size width="62" height="62"/>
|
||||
<maximum-size width="62" height="62"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<icon value="Arrow_Up.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="62bbe" class="javax.swing.JButton" binding="buttonDown">
|
||||
<constraints>
|
||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="10" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="62" height="62"/>
|
||||
<preferred-size width="62" height="62"/>
|
||||
<maximum-size width="62" height="62"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<icon value="Arrow_Down.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="b50ef" class="javax.swing.JButton" binding="buttonLeft">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="6" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="62" height="62"/>
|
||||
<preferred-size width="62" height="62"/>
|
||||
<maximum-size width="62" height="62"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<icon value="Arrow_Left.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
101
ProjectCleaningCar/src/FormCleaningCar.java
Normal file
101
ProjectCleaningCar/src/FormCleaningCar.java
Normal file
@ -0,0 +1,101 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.Random;
|
||||
import java.util.List;
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class FormCleaningCar extends JFrame {
|
||||
protected DrawningCleaningCar _drawningCleaningCar = new DrawningCleaningCar();
|
||||
JPanel pictureBox;
|
||||
private JButton buttonCreate;
|
||||
private JButton buttonRight;
|
||||
private JButton buttonLeft;
|
||||
private JButton buttonDown;
|
||||
private JButton buttonUp;
|
||||
private List<JComponent> controls;
|
||||
|
||||
public FormCleaningCar() {
|
||||
buttonUp.setName("buttonUp");
|
||||
buttonDown.setName("buttonDown");
|
||||
buttonLeft.setName("buttonLeft");
|
||||
buttonRight.setName("buttonRight");
|
||||
InitializeControlsRepaintList();
|
||||
|
||||
buttonCreate.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Random random = new Random();
|
||||
_drawningCleaningCar.Init(random.nextInt(100, 300), random.nextInt(1000, 3000),
|
||||
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(),
|
||||
random.nextBoolean());
|
||||
_drawningCleaningCar.SetPictureSize(pictureBox.getWidth(), pictureBox.getHeight());
|
||||
_drawningCleaningCar.SetPosition(random.nextInt(0, 200), random.nextInt(0, 200));
|
||||
Draw();
|
||||
}
|
||||
});
|
||||
ActionListener buttonMoveClickedListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String buttonName = ((JButton) e.getSource()).getName();
|
||||
boolean result = false;
|
||||
|
||||
switch (buttonName) {
|
||||
case "buttonUp": {
|
||||
result = _drawningCleaningCar.MoveTransport(DirectionType.Up);
|
||||
}
|
||||
break;
|
||||
case "buttonDown": {
|
||||
result = _drawningCleaningCar.MoveTransport(DirectionType.Down);
|
||||
}
|
||||
break;
|
||||
case "buttonLeft": {
|
||||
result = _drawningCleaningCar.MoveTransport(DirectionType.Left);
|
||||
}
|
||||
break;
|
||||
case "buttonRight": {
|
||||
result = _drawningCleaningCar.MoveTransport(DirectionType.Right);
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
if (result)
|
||||
Draw();
|
||||
|
||||
}
|
||||
};
|
||||
buttonRight.addActionListener(buttonMoveClickedListener);
|
||||
buttonDown.addActionListener(buttonMoveClickedListener);
|
||||
buttonLeft.addActionListener(buttonMoveClickedListener);
|
||||
buttonUp.addActionListener(buttonMoveClickedListener);
|
||||
}
|
||||
private void Draw() {
|
||||
if (_drawningCleaningCar.getEntityCleaningCar() == null ||
|
||||
pictureBox.getWidth() == 0 || pictureBox.getHeight() == 0)
|
||||
return;
|
||||
Graphics g = pictureBox.getGraphics();
|
||||
g.setColor(pictureBox.getBackground());
|
||||
g.fillRect(0,0, pictureBox.getWidth(), pictureBox.getHeight());
|
||||
_drawningCleaningCar.DrawTransport(g);
|
||||
|
||||
RepaintControls();
|
||||
|
||||
}
|
||||
private void RepaintControls() {
|
||||
for (JComponent control : controls) {
|
||||
control.repaint();
|
||||
}
|
||||
}
|
||||
private void InitializeControlsRepaintList() {
|
||||
controls = new LinkedList<>();
|
||||
controls.add(buttonCreate);
|
||||
controls.add(buttonUp);
|
||||
controls.add(buttonDown);
|
||||
controls.add(buttonLeft);
|
||||
controls.add(buttonRight);
|
||||
}
|
||||
}
|
@ -1,15 +1,13 @@
|
||||
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
|
||||
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
|
||||
public class Main {
|
||||
import javax.swing.*;
|
||||
class Main {
|
||||
public static void main(String[] args) {
|
||||
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
|
||||
// to see how IntelliJ IDEA suggests fixing it.
|
||||
System.out.printf("Hello and welcome!");
|
||||
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
//TIP Press <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
|
||||
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
|
||||
System.out.println("i = " + i);
|
||||
}
|
||||
JFrame.setDefaultLookAndFeelDecorated(false);
|
||||
JFrame frame = new JFrame("Project Cleaning Car");
|
||||
frame.setContentPane(new FormCleaningCar().pictureBox);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setLocation(200, 200);
|
||||
frame.pack();
|
||||
frame.setSize(1000, 600);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user