Второй коммит. Вторая усложненная лабораторная работа. Выполнена (много изменений из за перехода на IntellIJ Ultimate)
This commit is contained in:
parent
efbca96f66
commit
13eaeb49ed
63
src/DrawingField.java
Normal file
63
src/DrawingField.java
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class DrawingField extends JPanel{
|
||||||
|
private final FormWarship Field;
|
||||||
|
DrawingWarship _warship=null;
|
||||||
|
public DrawingField(FormWarship field) {
|
||||||
|
Field = field;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void paintComponent(Graphics g) {
|
||||||
|
super.paintComponent(g);
|
||||||
|
Graphics2D g2 =(Graphics2D)g;
|
||||||
|
if (_warship!=null)
|
||||||
|
_warship.DrawTransport(g2);
|
||||||
|
else return;
|
||||||
|
}
|
||||||
|
public void DirectionButtonAction(Direction side){
|
||||||
|
if(_warship == null)
|
||||||
|
return;
|
||||||
|
_warship.MoveTransport(side);
|
||||||
|
}
|
||||||
|
private void SetData() {
|
||||||
|
Random rand=new Random();
|
||||||
|
_warship.SetPosition(rand.nextInt(100)+10,rand.nextInt(100)+10,getWidth(),getHeight());
|
||||||
|
Field.SpeedLabel.setText("Скорость: "+_warship.GetWarship().GetSpeed());
|
||||||
|
Field.WeightLabel.setText("Вес: "+_warship.GetWarship().GetWeight());
|
||||||
|
Field.BodyColorLabel.setText("Цвет: "+Integer.toHexString(_warship.GetWarship().GetBodyColor().getRGB()).substring(2));
|
||||||
|
}
|
||||||
|
public void CreateButtonAction(){
|
||||||
|
Random rand=new Random();
|
||||||
|
Color color1 = JColorChooser.showDialog(Field, "Выберите цвет тела корабля", null);
|
||||||
|
if(color1==null)
|
||||||
|
color1=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
|
||||||
|
_warship=new DrawingWarship(rand.nextInt(50)+10,rand.nextInt(3000)+20000,color1,rand.nextInt(3));
|
||||||
|
SetData();
|
||||||
|
}
|
||||||
|
public void CreateModifButtonAction(){
|
||||||
|
Random rand=new Random();
|
||||||
|
Color color1=JColorChooser.showDialog(Field, "Выберите цвет тела корабля",null);
|
||||||
|
Color color2=JColorChooser.showDialog(Field, "Выборите цвет модификаций корабля",null);
|
||||||
|
if(color1==null)
|
||||||
|
color1=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
|
||||||
|
if (color2==null)
|
||||||
|
color2=new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
|
||||||
|
_warship = new DrawingAdvancedWarship(rand.nextInt(50) + 10, rand.nextInt(3000) + 20000, color1,
|
||||||
|
color2, rand.nextBoolean(), rand.nextBoolean(), rand.nextBoolean(),rand.nextInt(3));
|
||||||
|
SetData();
|
||||||
|
}
|
||||||
|
public void ResizeField(){
|
||||||
|
if (_warship!=null)
|
||||||
|
_warship.ChangeBorders(getWidth(),getHeight());
|
||||||
|
else return;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Draw(Graphics2D graphics) {
|
||||||
|
if (_warship!=null)
|
||||||
|
_warship.DrawTransport(graphics);
|
||||||
|
else return;
|
||||||
|
}
|
||||||
|
}
|
@ -170,15 +170,6 @@
|
|||||||
</model>
|
</model>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
<grid id="da53e" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
<border type="none"/>
|
|
||||||
<children/>
|
|
||||||
</grid>
|
|
||||||
</children>
|
</children>
|
||||||
</grid>
|
</grid>
|
||||||
</form>
|
</form>
|
||||||
|
164
src/FormWarship.form
Normal file
164
src/FormWarship.form
Normal file
@ -0,0 +1,164 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormWarship">
|
||||||
|
<grid id="27dc6" binding="PictureBox" layout-manager="GridLayoutManager" row-count="3" column-count="5" 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="637" height="507"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<grid id="11e3d" layout-manager="GridLayoutManager" row-count="1" 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>
|
||||||
|
<grid row="2" column="0" row-span="1" col-span="5" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<component id="d468f" class="javax.swing.JLabel" binding="SpeedLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Скорость: "/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<hspacer id="321ab">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
<component id="d033b" class="javax.swing.JLabel" binding="WeightLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Вес: "/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="ba46a" class="javax.swing.JLabel" binding="BodyColorLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Цвет: "/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<grid id="ba3a6" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<component id="f38f9" class="javax.swing.JButton" binding="ButtonLeft">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<icon value="arrowLeft.jpg"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="ab65" class="javax.swing.JButton" binding="ButtonDown">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<icon value="arrowDown.jpg"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="ae569" class="javax.swing.JButton" binding="ButtonRight">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<icon value="arrowRight.jpg"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="8e604" class="javax.swing.JButton" binding="ButtonUp">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<icon value="arrowUp.jpg"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<grid id="98f8a" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<component id="6de46" class="javax.swing.JButton" binding="ButtonCreate">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Создать"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="e329e" class="javax.swing.JButton" binding="ButtonCreateModif">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Модификация"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<hspacer id="73825">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
<vspacer id="5a84c">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</vspacer>
|
||||||
|
<grid id="e85d9" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="4" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<hspacer id="e5ed3">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<grid id="a3aed" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<hspacer id="c4971">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</form>
|
80
src/FormWarship.java
Normal file
80
src/FormWarship.java
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ComponentAdapter;
|
||||||
|
import java.awt.event.ComponentEvent;
|
||||||
|
|
||||||
|
public class FormWarship extends JFrame{
|
||||||
|
private int Width;
|
||||||
|
private int Height;
|
||||||
|
DrawingField field = new DrawingField(this);
|
||||||
|
private JButton ButtonDown;
|
||||||
|
private JButton ButtonRight;
|
||||||
|
private JButton ButtonLeft;
|
||||||
|
private JButton ButtonUp;
|
||||||
|
private JButton ButtonCreate;
|
||||||
|
private JButton ButtonCreateModif;
|
||||||
|
public JLabel SpeedLabel;
|
||||||
|
public JLabel WeightLabel;
|
||||||
|
public JLabel BodyColorLabel;
|
||||||
|
private JPanel PictureBox;
|
||||||
|
|
||||||
|
public FormWarship(){
|
||||||
|
super("Военный корабль");
|
||||||
|
setContentPane(PictureBox);
|
||||||
|
setSize(1000,700);
|
||||||
|
Width = getWidth();
|
||||||
|
Height = getHeight();
|
||||||
|
ShowWindow();
|
||||||
|
field.setBounds(0,0,Width,Height);
|
||||||
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ShowWindow(){
|
||||||
|
|
||||||
|
ButtonCreate.addActionListener(e -> {
|
||||||
|
field.CreateButtonAction();
|
||||||
|
ReDraw();
|
||||||
|
});
|
||||||
|
ButtonCreateModif.addActionListener(e -> {
|
||||||
|
field.CreateModifButtonAction();
|
||||||
|
ReDraw();
|
||||||
|
});
|
||||||
|
ButtonUp.addActionListener(e -> {
|
||||||
|
field.DirectionButtonAction(Direction.Up);
|
||||||
|
ReDraw();
|
||||||
|
});
|
||||||
|
ButtonLeft.addActionListener(e -> {
|
||||||
|
field.DirectionButtonAction(Direction.Left);
|
||||||
|
ReDraw();
|
||||||
|
});
|
||||||
|
ButtonRight.addActionListener(e -> {
|
||||||
|
field.DirectionButtonAction(Direction.Right);
|
||||||
|
ReDraw();
|
||||||
|
});
|
||||||
|
ButtonDown.addActionListener(e -> {
|
||||||
|
field.DirectionButtonAction(Direction.Down);
|
||||||
|
ReDraw();
|
||||||
|
});
|
||||||
|
|
||||||
|
addComponentListener(new ComponentAdapter() {
|
||||||
|
@Override
|
||||||
|
public void componentResized(ComponentEvent e){
|
||||||
|
super.componentResized(e);
|
||||||
|
Width=getWidth();
|
||||||
|
Height=getHeight();
|
||||||
|
|
||||||
|
field.ResizeField();
|
||||||
|
ReDraw();
|
||||||
|
field.setBounds(0,0,Width,Height);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
private void ReDraw()
|
||||||
|
{
|
||||||
|
Graphics2D graphics = (Graphics2D) PictureBox.getGraphics();
|
||||||
|
graphics.clearRect(0, 0, PictureBox.getWidth(), PictureBox.getHeight());
|
||||||
|
PictureBox.paintComponents(graphics);
|
||||||
|
field.Draw(graphics);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user