diff --git a/DrawingShip.java b/DrawingShip.java
index b2c2188..24462b0 100644
--- a/DrawingShip.java
+++ b/DrawingShip.java
@@ -57,16 +57,35 @@ public class DrawingShip extends JPanel {
}
//Отрисовка транспорта
- public void DrawTransport()
+ public void DrawTransport(Graphics g)
{
+ if (GetWarmlyShip() == null) return;
+
if (_startPosX < 0 || _startPosY < 0 || _pictureWidth == null || _pictureHeight == null)
{
return;
}
- repaint();
+ Graphics2D g2d = (Graphics2D) g;
+ g2d.setColor(warmlyShip.GetBodyColor());
+ int[] xPol = new int[] {(int)(_startPosX), (int)(_startPosX + _warmlyShipWidth), (int)(_startPosX + _warmlyShipWidth - 25), (int)(_startPosX + 25)};
+ int[] yPol = new int[] {(int)(_startPosY + 20), (int)(_startPosY + 20), (int)(_startPosY + _warmlyShipHeight), (int)(_startPosY + _warmlyShipHeight)};
+ g2d.fillPolygon(new Polygon(xPol, yPol, xPol.length));
+ g2d.fillRect((int)(_startPosX + _warmlyShipWidth / 5), (int)_startPosY, _warmlyShipWidth * 3 / 5, 20);
+ g2d.setColor(Color.CYAN);
+ g2d.fillOval((int)(_startPosX + _warmlyShipWidth / 5), (int)_startPosY + 25, 20, 20);
+ g2d.fillOval((int)(_startPosX + _warmlyShipWidth * 3 / 5 + 5), (int)_startPosY + 25, 20, 20);
+ g2d.fillOval((int)(_startPosX + _warmlyShipWidth * 2 / 5 + 2.5f), (int)_startPosY + 25, 20, 20);
+ g2d.setColor(Color.BLACK);
+ g2d.drawPolygon(new Polygon(xPol, yPol, xPol.length));
+ g2d.drawRect((int)(_startPosX + _warmlyShipWidth / 5), (int)(_startPosY), _warmlyShipWidth * 3 / 5, 20);
+ g2d.setColor(Color.BLUE);
+ g2d.drawOval((int)(_startPosX + _warmlyShipWidth / 5), (int)_startPosY + 25, 20, 20);
+ g2d.drawOval((int)(_startPosX + _warmlyShipWidth * 3 / 5 + 5), (int)_startPosY + 25, 20, 20);
+ g2d.drawOval((int)(_startPosX + _warmlyShipWidth * 2 / 5 + 2.5f), (int)_startPosY + 25, 20, 20);
+ dd.DrawningDeck(_startPosX, _startPosY, _warmlyShipWidth, g2d, warmlyShip.GetBodyColor());
}
- @Override
+ /*@Override
public void paintComponent(Graphics g){
if (GetWarmlyShip() == null) return;
@@ -93,7 +112,7 @@ public class DrawingShip extends JPanel {
g2d.drawOval((int)(_startPosX + _warmlyShipWidth * 3 / 5 + 5), (int)_startPosY + 25, 20, 20);
g2d.drawOval((int)(_startPosX + _warmlyShipWidth * 2 / 5 + 2.5f), (int)_startPosY + 25, 20, 20);
dd.DrawningDeck(_startPosX, _startPosY, _warmlyShipWidth, g2d, warmlyShip.GetBodyColor());
- }
+ }*/
//Изменение границ отрисовки
public void ChangeBorders(int width, int height)
diff --git a/FormShip.form b/FormShip.form
index ee8a98c..42e407f 100644
--- a/FormShip.form
+++ b/FormShip.form
@@ -36,14 +36,6 @@
-
-
-
-
-
-
-
-
@@ -83,7 +75,7 @@
-
+
@@ -102,6 +94,14 @@
+
+
+
+
+
+
+
+
diff --git a/FormShip.java b/FormShip.java
index 5967181..2548441 100644
--- a/FormShip.java
+++ b/FormShip.java
@@ -5,43 +5,56 @@ import java.awt.event.*;
import java.awt.image.*;
import java.util.*;
-public class FormShip {
+public class FormShip extends JFrame{
private JToolBar statusStrip;
public JPanel Mainpanel;
- private DrawingShip pictureShip;
+ private DrawingShip ship;
private JButton buttonRight;
private JButton buttonCreate;
private JButton buttonLeft;
private JButton buttonUp;
private JButton buttonDown;
+ private JPanel GraphicsOutput;
private JLabel JLabelSpeed = new JLabel();
private JLabel JLabelWeight = new JLabel();
private JLabel JLabelColor = new JLabel();
private void Draw()
{
- if (pictureShip.GetWarmlyShip() == null) return;
- pictureShip.DrawTransport();
+ if (ship == null || ship.GetWarmlyShip() == null) return;
+ GraphicsOutput.removeAll();
+ BufferedImage bmp = new BufferedImage(GraphicsOutput.getWidth(), GraphicsOutput.getHeight(),BufferedImage.TYPE_INT_RGB);
+ Graphics g = bmp.getGraphics();
+ g.setColor(new Color(238, 238, 238));
+ g.fillRect(0, 0, GraphicsOutput.getWidth(), GraphicsOutput.getHeight());
+ ship.DrawTransport(g);
+ JLabel imageOfShip = new JLabel();
+ imageOfShip.setPreferredSize(GraphicsOutput.getSize());
+ imageOfShip.setMinimumSize(new Dimension(1, 1));
+ imageOfShip.setIcon(new ImageIcon(bmp));
+ GraphicsOutput.add(imageOfShip,BorderLayout.CENTER);
+ validate();
}
private void ButtonMove_Click(String name)
{
- if (pictureShip == null) return;
+ if (ship == null) return;
switch (name)
{
case "buttonLeft":
- pictureShip.MoveTransport(Direction.Left);
+ ship.MoveTransport(Direction.Left);
break;
case "buttonUp":
- pictureShip.MoveTransport(Direction.Up);
+ ship.MoveTransport(Direction.Up);
break;
case "buttonRight":
- pictureShip.MoveTransport(Direction.Right);
+ ship.MoveTransport(Direction.Right);
break;
case "buttonDown":
- pictureShip.MoveTransport(Direction.Down);
+ ship.MoveTransport(Direction.Down);
break;
}
+ GraphicsOutput.revalidate();
Draw();
}
@@ -70,11 +83,12 @@ public class FormShip {
@Override
public void actionPerformed(ActionEvent e) {
Random random = new Random();
- pictureShip.Init(random.nextInt(100, 300), random.nextInt(1000, 2000), new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)));
- pictureShip.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100), pictureShip.getWidth(), pictureShip.getHeight());
- JLabelSpeed.setText("Cкорость: " + pictureShip.GetWarmlyShip().GetSpeed() + " ");
- JLabelWeight.setText("Вес: " + pictureShip.GetWarmlyShip().GetWeight() + " ");
- JLabelColor.setText(("Цвет: " + pictureShip.GetWarmlyShip().GetBodyColor() + " "));
+ ship = new DrawingShip();
+ ship.Init(random.nextInt(100, 300), random.nextInt(1000, 2000), new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)));
+ ship.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100), GraphicsOutput.getWidth(), GraphicsOutput.getHeight());
+ JLabelSpeed.setText("Cкорость: " + ship.GetWarmlyShip().GetSpeed() + " ");
+ JLabelWeight.setText("Вес: " + ship.GetWarmlyShip().GetWeight() + " ");
+ JLabelColor.setText(("Цвет: " + ship.GetWarmlyShip().GetBodyColor() + " "));
Draw();
}
});
@@ -102,11 +116,13 @@ public class FormShip {
ButtonMove_Click("buttonRight");
}
});
- pictureShip.addComponentListener(new ComponentAdapter() {
+ GraphicsOutput.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
super.componentResized(e);
- pictureShip.ChangeBorders(pictureShip.getWidth(), pictureShip.getHeight());
+ if (ship == null || ship.GetWarmlyShip() == null) return;
+ ship.ChangeBorders(GraphicsOutput.getWidth(), GraphicsOutput.getHeight());
+ GraphicsOutput.revalidate();
Draw();
}
});