сделанная работа
This commit is contained in:
parent
702e485daa
commit
cece533ed5
@ -89,16 +89,9 @@ public class DrawningAbstractCompany extends JComponent {
|
||||
if (boat == null) {
|
||||
return;
|
||||
}
|
||||
JFrame.setDefaultLookAndFeelDecorated(false);
|
||||
JFrame frame = new JFrame("Катамаран");
|
||||
FormCatamaran formCatamaran = new FormCatamaran();
|
||||
frame.setContentPane(formCatamaran.PanelWrapper);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setLocation(500, 200);
|
||||
formCatamaran.setBoat(boat);
|
||||
frame.pack();
|
||||
frame.setSize(1000, 725);
|
||||
frame.setVisible(true);
|
||||
formCatamaran.setDrawningBoat(boat);
|
||||
formCatamaran.OpenFrame();
|
||||
|
||||
|
||||
}
|
||||
|
@ -16,8 +16,8 @@ public class DrawningBoat {
|
||||
protected Integer _startPosY;
|
||||
private int _drawingBoatWidth = 107;
|
||||
private int _drawingBoatHeight = 80;
|
||||
public int GetPosX(){return _startPosX;}
|
||||
public int GetPosY(){return _startPosY;}
|
||||
public Integer GetPosX(){return _startPosX;}
|
||||
public Integer GetPosY(){return _startPosY;}
|
||||
public int GetWidth(){return _drawingBoatWidth;}
|
||||
public int GetHeight(){return _drawingBoatHeight;}
|
||||
public IDrawPaddles drawPaddles;
|
||||
|
71
ProjectCatamaran/src/Drawnings/DrawningFormCatamaran.java
Normal file
71
ProjectCatamaran/src/Drawnings/DrawningFormCatamaran.java
Normal file
@ -0,0 +1,71 @@
|
||||
package Drawnings;
|
||||
|
||||
import MovementStrategy.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningFormCatamaran extends JComponent {
|
||||
DrawningBoat drawningBoat;
|
||||
|
||||
private int _pictureHeight = -1;
|
||||
private int _pictureWidth = -1;
|
||||
private AbstractStrategy _strategy;
|
||||
public void setDrawningBoat(DrawningBoat drawningBoat) {
|
||||
this.drawningBoat = drawningBoat;
|
||||
}
|
||||
|
||||
public boolean setPictureSize(int width, int height) {
|
||||
if (drawningBoat.GetHeight() > height || drawningBoat.GetWidth() > width)
|
||||
return false;
|
||||
_pictureHeight = height;
|
||||
_pictureWidth = width;
|
||||
return true;
|
||||
}
|
||||
public void buttonStrategyStep(JComboBox<String> comboBox) {
|
||||
if (drawningBoat == null)
|
||||
return;
|
||||
if (comboBox.isEnabled()) {
|
||||
switch (comboBox.getSelectedIndex()) {
|
||||
case 0:
|
||||
_strategy = new MoveToCenter();
|
||||
break;
|
||||
case 1:
|
||||
_strategy = new MoveToBorder();
|
||||
break;
|
||||
|
||||
default:
|
||||
_strategy = null;
|
||||
break;
|
||||
|
||||
}
|
||||
if (_strategy == null) {
|
||||
return;
|
||||
}
|
||||
_strategy.SetData(new MoveableBoat(drawningBoat), _pictureWidth, _pictureHeight);
|
||||
}
|
||||
if (_strategy == null) {
|
||||
return;
|
||||
}
|
||||
comboBox.setEnabled(false);
|
||||
_strategy.MakeStep();
|
||||
if (_strategy.GetStatus() == StrategyStatus.Finish) {
|
||||
comboBox.setEnabled(true);
|
||||
_strategy = null;
|
||||
}
|
||||
|
||||
}
|
||||
public void MoveButtonsAction(MovementDirection direction) {
|
||||
if (drawningBoat == null)
|
||||
return;
|
||||
drawningBoat.moveTransport(direction);
|
||||
}
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
if (drawningBoat == null) {
|
||||
return;
|
||||
}
|
||||
drawningBoat.drawBoat(g);
|
||||
}
|
||||
}
|
@ -1,107 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="Forms.FormCatamaran">
|
||||
<grid id="27dc6" binding="PanelWrapper" 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>
|
||||
<xy x="20" y="20" width="599" height="476"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="1ff9a" binding="PictureBox" layout-manager="GridLayoutManager" row-count="6" 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>
|
||||
<grid row="0" 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>
|
||||
<toolTipText value=""/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<vspacer id="7b40c">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="2" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="88" height="14"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<hspacer id="e0b21">
|
||||
<constraints>
|
||||
<grid row="4" column="1" 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="fe25b" class="javax.swing.JButton" binding="buttonLeft">
|
||||
<constraints>
|
||||
<grid row="5" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="4" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<icon value="30px_arrow_left.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="3eabd" class="javax.swing.JButton" binding="buttonStrategyStep">
|
||||
<constraints>
|
||||
<grid row="1" column="3" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Шаг"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="86d84" class="javax.swing.JButton" binding="buttonRight">
|
||||
<constraints>
|
||||
<grid row="5" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<icon value="30px_arrow_right.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="3dc0" class="javax.swing.JButton" binding="buttonDown">
|
||||
<constraints>
|
||||
<grid row="5" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<icon value="30px_arrow_down.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="ccb2a" class="javax.swing.JButton" binding="buttonUp">
|
||||
<constraints>
|
||||
<grid row="4" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<icon value="30px_arrow_up.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="988c8" class="javax.swing.JComboBox" binding="comboBoxStrategy">
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="3" vsize-policy="0" hsize-policy="2" anchor="9" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<actionCommand value=""/>
|
||||
<doubleBuffered value="false"/>
|
||||
<toolTipText value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
@ -4,154 +4,110 @@ import Drawnings.*;
|
||||
import MovementStrategy.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
|
||||
|
||||
public class FormCatamaran extends JFrame {
|
||||
protected DrawningBoat _drawningBoat;
|
||||
public JPanel PanelWrapper;
|
||||
private JPanel PictureBox;
|
||||
private JButton buttonRight;
|
||||
private JButton buttonDown;
|
||||
private JButton buttonLeft;
|
||||
private JButton buttonUp;
|
||||
private JComboBox comboBoxStrategy;
|
||||
private JButton buttonStrategyStep;
|
||||
private AbstractStrategy _strategy;
|
||||
final private JFrame JFrameCatamaran = new JFrame();
|
||||
final private JButton buttonRight = new JButton(new ImageIcon("ProjectCatamaran\\Resources\\30px_arrow_right.png"));
|
||||
final private JPanel RightPanel = new JPanel();
|
||||
final private JButton buttonDown = new JButton(new ImageIcon("ProjectCatamaran\\Resources\\30px_arrow_down.png"));
|
||||
final private JPanel DownPanel = new JPanel();
|
||||
final private JButton buttonLeft = new JButton(new ImageIcon("ProjectCatamaran\\Resources\\30px_arrow_left.png"));
|
||||
final private JPanel LeftPanel = new JPanel();
|
||||
final private JButton buttonUp = new JButton(new ImageIcon("ProjectCatamaran\\Resources\\30px_arrow_up.png"));
|
||||
|
||||
private List<JComponent> controls;
|
||||
public FormCatamaran() {
|
||||
buttonUp.setName("buttonUp");
|
||||
buttonDown.setName("buttonDown");
|
||||
buttonLeft.setName("buttonLeft");
|
||||
buttonRight.setName("buttonRight");
|
||||
_strategy = null;
|
||||
Draw();
|
||||
final private JPanel UpPanel = new JPanel();
|
||||
final private String [] itemsComboBox = {
|
||||
"К центру",
|
||||
"К краю"
|
||||
};
|
||||
final private JComboBox<String> comboBoxStrategy =new JComboBox<>(itemsComboBox);
|
||||
final private JButton buttonStrategyStep = new JButton("Шаг");
|
||||
final private JPanel StrategyPanel = new JPanel(new BorderLayout());
|
||||
|
||||
InitializeControlsRepaintList();
|
||||
final private DrawningFormCatamaran form = new DrawningFormCatamaran();
|
||||
public void setDrawningBoat(DrawningBoat boat) {form.setDrawningBoat(boat);}
|
||||
public void OpenFrame() {
|
||||
JFrameCatamaran.setVisible(true);
|
||||
Toolkit tolls = Toolkit.getDefaultToolkit();
|
||||
Dimension dimension = tolls.getScreenSize();
|
||||
JFrameCatamaran.setBounds(dimension.width / 2 - 250, dimension.height / 2 - 250,
|
||||
970, 700);
|
||||
JFrameCatamaran.setTitle("Катамаран");
|
||||
|
||||
comboBoxStrategy.setPreferredSize(new Dimension(100, 35));
|
||||
buttonStrategyStep.setPreferredSize(new Dimension(100, 35));
|
||||
StrategyPanel.setSize(100, 70);
|
||||
StrategyPanel.add(comboBoxStrategy, BorderLayout.NORTH);
|
||||
StrategyPanel.add(buttonStrategyStep, BorderLayout.SOUTH);
|
||||
|
||||
|
||||
UpPanel.setSize(30, 30);
|
||||
buttonUp.setPreferredSize(new Dimension(30, 30));
|
||||
UpPanel.add(buttonUp, BorderLayout.CENTER);
|
||||
|
||||
ActionListener buttonMoveClickedListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String buttonName = ((JButton) e.getSource()).getName();
|
||||
boolean result = false;
|
||||
DownPanel.setSize(30, 30);
|
||||
buttonDown.setPreferredSize(new Dimension(30, 30));
|
||||
DownPanel.add(buttonDown, BorderLayout.CENTER);
|
||||
|
||||
switch (buttonName) {
|
||||
case "buttonUp": {
|
||||
result = _drawningBoat.moveTransport(MovementDirection.Up);
|
||||
}
|
||||
break;
|
||||
case "buttonDown": {
|
||||
result = _drawningBoat.moveTransport(MovementDirection.Down);
|
||||
}
|
||||
break;
|
||||
case "buttonLeft": {
|
||||
result = _drawningBoat.moveTransport(MovementDirection.Left);
|
||||
}
|
||||
break;
|
||||
case "buttonRight": {
|
||||
result = _drawningBoat.moveTransport(MovementDirection.Right);
|
||||
}
|
||||
break;
|
||||
RightPanel.setSize(30, 30);
|
||||
buttonRight.setPreferredSize(new Dimension(30, 30));
|
||||
RightPanel.add(buttonRight, BorderLayout.CENTER);
|
||||
|
||||
}
|
||||
if (result)
|
||||
Draw();
|
||||
LeftPanel.setSize(30, 30);
|
||||
buttonLeft.setPreferredSize(new Dimension(30, 30));
|
||||
LeftPanel.add(buttonLeft, BorderLayout.CENTER);
|
||||
|
||||
JFrameCatamaran.add(StrategyPanel);
|
||||
JFrameCatamaran.add(UpPanel);
|
||||
JFrameCatamaran.add(DownPanel);
|
||||
JFrameCatamaran.add(RightPanel);
|
||||
JFrameCatamaran.add(LeftPanel);
|
||||
JFrameCatamaran.add(form);
|
||||
|
||||
JFrameCatamaran.addComponentListener(new ComponentAdapter() {
|
||||
public void componentResized(ComponentEvent e) {
|
||||
StrategyPanel.setLocation(JFrameCatamaran.getWidth() - 100, 0);
|
||||
UpPanel.setLocation(JFrameCatamaran.getWidth() - 80, JFrameCatamaran.getHeight()-100);
|
||||
DownPanel.setLocation(JFrameCatamaran.getWidth() - 80, JFrameCatamaran.getHeight()-70);
|
||||
RightPanel.setLocation(JFrameCatamaran.getWidth() - 45, JFrameCatamaran.getHeight()-70);
|
||||
LeftPanel.setLocation(JFrameCatamaran.getWidth() - 115, JFrameCatamaran.getHeight()-70);
|
||||
|
||||
form.setPictureSize(JFrameCatamaran.getWidth(), JFrameCatamaran.getHeight());
|
||||
JFrameCatamaran.repaint();
|
||||
|
||||
}
|
||||
};
|
||||
buttonRight.addActionListener(buttonMoveClickedListener);
|
||||
buttonDown.addActionListener(buttonMoveClickedListener);
|
||||
buttonLeft.addActionListener(buttonMoveClickedListener);
|
||||
buttonUp.addActionListener(buttonMoveClickedListener);
|
||||
|
||||
String[] itemsComboBox = {
|
||||
"К центру",
|
||||
"К краю"
|
||||
};
|
||||
for (String item: itemsComboBox) {
|
||||
comboBoxStrategy.addItem(item);
|
||||
}
|
||||
buttonStrategyStep.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_drawningBoat == null)
|
||||
return;
|
||||
if (comboBoxStrategy.isEnabled()) {
|
||||
switch (comboBoxStrategy.getSelectedIndex()) {
|
||||
case 0:
|
||||
_strategy = new MoveToCenter();
|
||||
break;
|
||||
case 1:
|
||||
_strategy = new MoveToBorder();
|
||||
break;
|
||||
|
||||
default:
|
||||
_strategy = null;
|
||||
break;
|
||||
|
||||
}
|
||||
if (_strategy == null) {
|
||||
return;
|
||||
}
|
||||
_strategy.SetData(new MoveableBoat(_drawningBoat), PictureBox.getWidth(), PictureBox.getHeight());
|
||||
}
|
||||
if (_strategy == null) {
|
||||
return;
|
||||
}
|
||||
comboBoxStrategy.setEnabled(false);
|
||||
_strategy.MakeStep();
|
||||
Draw();
|
||||
|
||||
if (_strategy.GetStatus() == StrategyStatus.Finish) {
|
||||
comboBoxStrategy.setEnabled(true);
|
||||
_strategy = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void Draw() {
|
||||
if (_drawningBoat == null)
|
||||
return;
|
||||
if (PictureBox.getWidth() == 0 || PictureBox.getHeight() == 0) {
|
||||
return;
|
||||
}
|
||||
Graphics g = PictureBox.getGraphics();
|
||||
g.setColor(PictureBox.getBackground());
|
||||
g.fillRect(0,0, PictureBox.getWidth(), PictureBox.getHeight());
|
||||
_drawningBoat.drawBoat(g);
|
||||
buttonUp.addActionListener(e -> {
|
||||
form.setPictureSize(JFrameCatamaran.getWidth(), JFrameCatamaran.getHeight());
|
||||
form.MoveButtonsAction(MovementDirection.Up);
|
||||
JFrameCatamaran.repaint();
|
||||
});
|
||||
|
||||
RepaintControls();
|
||||
buttonDown.addActionListener(e -> {
|
||||
form.setPictureSize(JFrameCatamaran.getWidth(), JFrameCatamaran.getHeight());
|
||||
form.MoveButtonsAction(MovementDirection.Down);
|
||||
JFrameCatamaran.repaint();
|
||||
});
|
||||
buttonLeft.addActionListener(e -> {
|
||||
form.setPictureSize(JFrameCatamaran.getWidth(), JFrameCatamaran.getHeight());
|
||||
form.MoveButtonsAction(MovementDirection.Left);
|
||||
JFrameCatamaran.repaint();
|
||||
});
|
||||
buttonRight.addActionListener(e -> {
|
||||
form.setPictureSize(JFrameCatamaran.getWidth(), JFrameCatamaran.getHeight());
|
||||
form.MoveButtonsAction(MovementDirection.Right);
|
||||
JFrameCatamaran.repaint();
|
||||
});
|
||||
buttonStrategyStep.addActionListener(e -> {
|
||||
form.setPictureSize(JFrameCatamaran.getWidth(), JFrameCatamaran.getHeight());
|
||||
form.buttonStrategyStep(comboBoxStrategy);
|
||||
JFrameCatamaran.repaint();
|
||||
});
|
||||
|
||||
}
|
||||
public void setBoat(DrawningBoat boat) {
|
||||
_drawningBoat = boat;
|
||||
_drawningBoat.setPictureSize(PictureBox.getWidth(), PictureBox.getHeight());
|
||||
comboBoxStrategy.setEnabled(true);
|
||||
_strategy = null;
|
||||
PictureBox.repaint();
|
||||
|
||||
Draw();
|
||||
|
||||
}
|
||||
private void RepaintControls() {
|
||||
for (JComponent control : controls) {
|
||||
control.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeControlsRepaintList() {
|
||||
controls = new LinkedList<>();
|
||||
controls.add(buttonUp);
|
||||
controls.add(buttonDown);
|
||||
controls.add(buttonLeft);
|
||||
controls.add(buttonRight);
|
||||
controls.add(comboBoxStrategy);
|
||||
controls.add(buttonStrategyStep);
|
||||
}
|
||||
}
|
||||
}
|
@ -8,8 +8,8 @@ public class MoveToBorder extends AbstractStrategy {
|
||||
if (objParams == null) {
|
||||
return false;
|
||||
}
|
||||
return objParams.RightBorder() + GetStep() >= FieldWidth - GetStep() &&
|
||||
objParams.DownBorder() + GetStep() >= FieldHeight - GetStep();
|
||||
return objParams.RightBorder() + GetStep() >= FieldWidth &&
|
||||
objParams.DownBorder() + GetStep() >= FieldHeight;
|
||||
}
|
||||
@Override
|
||||
protected void MoveToTarget()
|
||||
|
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user