Первый коммит. Вторая усложненная лабораторная работа. Начало выполнения (много изменений из за перехода на IntellIJ Ultimate)
This commit is contained in:
parent
72a1782e61
commit
6b1d2f4816
@ -3,6 +3,7 @@
|
|||||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
<exclude-output />
|
<exclude-output />
|
||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/Resource" type="java-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
|
@ -16,6 +16,11 @@ public class DrawingField extends JPanel {
|
|||||||
_warship.DrawTransport(g2);
|
_warship.DrawTransport(g2);
|
||||||
else return;
|
else return;
|
||||||
}
|
}
|
||||||
|
public void DrawWarship(Graphics g){
|
||||||
|
if (_warship!=null)
|
||||||
|
_warship.DrawTransport(g);
|
||||||
|
else return;
|
||||||
|
}
|
||||||
public void UpButtonAction(){
|
public void UpButtonAction(){
|
||||||
if (_warship!=null)
|
if (_warship!=null)
|
||||||
_warship.MoveTransport(Direction.Up);
|
_warship.MoveTransport(Direction.Up);
|
||||||
|
156
src/FormWarship.form
Normal file
156
src/FormWarship.form
Normal file
@ -0,0 +1,156 @@
|
|||||||
|
<?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="824" height="502"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<hspacer id="4a033">
|
||||||
|
<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="bfabf">
|
||||||
|
<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="eeaaa" binding="BottomPanel" 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="28bed" 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="580fb">
|
||||||
|
<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="34d49" 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="2ab53" 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="b692b" binding="CreatePanel" 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="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="8a5b" 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>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<grid id="31774" binding="DimentionPanel" 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="9224d" 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="13cf5" 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>
|
||||||
|
<component id="e46ed" 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="e8b93" 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>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<grid id="99a01" 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="925bf">
|
||||||
|
<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="9f2b7" 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="31a5a">
|
||||||
|
<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>
|
@ -1,120 +1,67 @@
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.*;
|
import java.awt.event.ComponentAdapter;
|
||||||
|
import java.awt.event.ComponentEvent;
|
||||||
|
|
||||||
public class FormWarship extends JFrame{
|
public class FormWarship extends JFrame{
|
||||||
|
JPanel BottomPanel;
|
||||||
|
JPanel CreatePanel;
|
||||||
|
JPanel DimentionPanel;
|
||||||
|
|
||||||
|
JLabel SpeedLabel;
|
||||||
|
JLabel WeightLabel;
|
||||||
|
JLabel BodyColorLabel;
|
||||||
|
|
||||||
private int Width;
|
private int Width;
|
||||||
private int Height;
|
private int Height;
|
||||||
|
|
||||||
JPanel BottomPanel = new JPanel();
|
|
||||||
JPanel CreatePanel = new JPanel();
|
|
||||||
JPanel BottomAndCreatePanel = new JPanel();
|
|
||||||
JPanel DimentionPanel = new JPanel();
|
|
||||||
JPanel UPanel = new JPanel();
|
|
||||||
JPanel DPanel = new JPanel();
|
|
||||||
JPanel LRPanel = new JPanel();
|
|
||||||
|
|
||||||
JLabel SpeedLabel = new JLabel("Скорость: ");
|
|
||||||
JLabel WeightLabel = new JLabel("Вес: ");
|
|
||||||
JLabel BodyColorLabel = new JLabel("Цвет: ");
|
|
||||||
|
|
||||||
DrawingField field = new DrawingField(this);
|
DrawingField field = new DrawingField(this);
|
||||||
|
|
||||||
JButton ButtonCreate=new JButton("Создать");
|
JButton ButtonCreate;
|
||||||
|
JButton ButtonUp;
|
||||||
Icon iconUp = new ImageIcon("Resource\\arrowUp.jpg");
|
JButton ButtonDown;
|
||||||
JButton ButtonUp=new JButton(iconUp);
|
JButton ButtonRight;
|
||||||
|
JButton ButtonLeft;
|
||||||
Icon iconDown = new ImageIcon("Resource\\arrowDown.jpg");
|
JPanel PictureBox;
|
||||||
JButton ButtonDown=new JButton(iconDown);
|
|
||||||
|
|
||||||
Icon iconRight = new ImageIcon("Resource\\arrowRight.jpg");
|
|
||||||
JButton ButtonRight=new JButton(iconRight);
|
|
||||||
|
|
||||||
Icon iconLeft = new ImageIcon("Resource\\arrowLeft.jpg");
|
|
||||||
JButton ButtonLeft=new JButton(iconLeft);
|
|
||||||
|
|
||||||
|
|
||||||
public FormWarship(){
|
public FormWarship(){
|
||||||
super("Военный корабль");
|
super("Военный корабль");
|
||||||
|
setContentPane(PictureBox);
|
||||||
setSize(700,400);
|
setSize(700,400);
|
||||||
Width=getWidth();
|
Width=getWidth();
|
||||||
Height=getHeight();
|
Height=getHeight();
|
||||||
ShowWindow();
|
ShowWindow();
|
||||||
RefreshWindow();
|
field.setBounds(0,0,Width,Height);
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ShowWindow(){
|
public void ShowWindow(){
|
||||||
|
|
||||||
Dimension dimen=new Dimension(30,30);
|
|
||||||
|
|
||||||
ButtonUp.setPreferredSize(dimen);
|
|
||||||
ButtonUp.addActionListener(e->{
|
ButtonUp.addActionListener(e->{
|
||||||
field.UpButtonAction();
|
field.UpButtonAction();
|
||||||
repaint();
|
ReDraw();
|
||||||
});
|
});
|
||||||
|
|
||||||
ButtonDown.setPreferredSize(dimen);
|
|
||||||
ButtonDown.addActionListener(e->{
|
ButtonDown.addActionListener(e->{
|
||||||
field.DownButtonAction();
|
field.DownButtonAction();
|
||||||
repaint();
|
ReDraw();
|
||||||
});
|
});
|
||||||
|
|
||||||
ButtonRight.setPreferredSize(dimen);
|
|
||||||
ButtonRight.addActionListener(e->{
|
ButtonRight.addActionListener(e->{
|
||||||
field.RightButtonAction();
|
field.RightButtonAction();
|
||||||
repaint();
|
ReDraw();
|
||||||
});
|
});
|
||||||
|
|
||||||
ButtonLeft.setPreferredSize(dimen);
|
|
||||||
ButtonLeft.addActionListener(e->{
|
ButtonLeft.addActionListener(e->{
|
||||||
field.LeftButtonAction();
|
field.LeftButtonAction();
|
||||||
repaint();
|
ReDraw();
|
||||||
});
|
});
|
||||||
|
|
||||||
LRPanel.setLayout(new FlowLayout(FlowLayout.CENTER,50,0));
|
|
||||||
LRPanel.setBackground(new Color(0,0,0,0));
|
|
||||||
LRPanel.add(ButtonLeft);
|
|
||||||
LRPanel.add(ButtonRight);
|
|
||||||
|
|
||||||
UPanel.setLayout(new FlowLayout());
|
|
||||||
UPanel.setBackground(new Color(0,0,0,0));
|
|
||||||
UPanel.add(ButtonUp);
|
|
||||||
|
|
||||||
DPanel.setLayout(new FlowLayout());
|
|
||||||
DPanel.setBackground(new Color(0,0,0,0));
|
|
||||||
DPanel.add(ButtonDown);
|
|
||||||
|
|
||||||
DimentionPanel.setLayout(new BoxLayout(DimentionPanel,BoxLayout.Y_AXIS));
|
|
||||||
DimentionPanel.setBackground(new Color(0,0,0,0));
|
|
||||||
DimentionPanel.add(UPanel);
|
|
||||||
DimentionPanel.add(LRPanel);
|
|
||||||
DimentionPanel.add(DPanel);
|
|
||||||
add(DimentionPanel);
|
|
||||||
|
|
||||||
CreatePanel.setLayout(new FlowLayout());
|
|
||||||
CreatePanel.setBackground(new Color(0,0,0,0));
|
|
||||||
CreatePanel.add(ButtonCreate);
|
|
||||||
ButtonCreate.addActionListener(e->{
|
ButtonCreate.addActionListener(e->{
|
||||||
field.CreateButtonAction();
|
field.CreateButtonAction();
|
||||||
repaint();
|
ReDraw();
|
||||||
});
|
});
|
||||||
|
|
||||||
BottomPanel.setLayout(new FlowLayout());
|
|
||||||
BottomPanel.setBackground(new Color(0,0,0,0));
|
|
||||||
BottomPanel.add(SpeedLabel);
|
|
||||||
BottomPanel.add(WeightLabel);
|
|
||||||
BottomPanel.add(BodyColorLabel);
|
|
||||||
|
|
||||||
BottomAndCreatePanel.setLayout(new BoxLayout(BottomAndCreatePanel,BoxLayout.Y_AXIS));
|
|
||||||
BottomAndCreatePanel.setBackground(new Color(0,0,0,0));
|
|
||||||
BottomAndCreatePanel.add(CreatePanel);
|
|
||||||
BottomAndCreatePanel.add(BottomPanel);
|
|
||||||
|
|
||||||
add(BottomAndCreatePanel);
|
|
||||||
add(field);
|
|
||||||
|
|
||||||
addComponentListener(new ComponentAdapter() {
|
addComponentListener(new ComponentAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void componentResized(ComponentEvent e) {
|
public void componentResized(ComponentEvent e) {
|
||||||
@ -123,14 +70,17 @@ public class FormWarship extends JFrame{
|
|||||||
Height=getHeight();
|
Height=getHeight();
|
||||||
|
|
||||||
field.ResizeField();
|
field.ResizeField();
|
||||||
repaint();
|
field.setBounds(0,0,Width,Height);
|
||||||
RefreshWindow();
|
ReDraw();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
public void RefreshWindow(){
|
private void ReDraw()
|
||||||
field.setBounds(0,0,Width,Height);
|
{
|
||||||
BottomAndCreatePanel.setBounds(-220,Height-110,Width,80);
|
Graphics2D graphics = (Graphics2D) PictureBox.getGraphics();
|
||||||
DimentionPanel.setBounds(Width-170,Height-170,190,140);
|
graphics.clearRect(0, 0, PictureBox.getWidth(), PictureBox.getHeight());
|
||||||
|
PictureBox.paintComponents(graphics);
|
||||||
|
field.DrawWarship(graphics);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
new FormWarship();
|
new FormWarship();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user