From b672e4c67b5e76f6fce23321d03d00d99da7ede4 Mon Sep 17 00:00:00 2001 From: dlopatin Date: Mon, 19 Feb 2024 15:06:47 +0300 Subject: [PATCH] =?UTF-8?q?=D1=82=D0=B5=D0=BF=D0=BB=D0=BE=D0=B2=D0=BE?= =?UTF-8?q?=D0=B7=D1=8B=20=D0=BF=D0=BE=D1=8F=D0=B2=D0=BB=D1=8F=D1=8E=D1=82?= =?UTF-8?q?=D1=81=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/DrawingWarmlyLocomotive.java | 1 + .../src/FormWarmlyLocomotive.java | 54 ++++++++++++++++++- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/WarmlyLocomotive/src/DrawingWarmlyLocomotive.java b/WarmlyLocomotive/src/DrawingWarmlyLocomotive.java index 3d56d68..cae8405 100644 --- a/WarmlyLocomotive/src/DrawingWarmlyLocomotive.java +++ b/WarmlyLocomotive/src/DrawingWarmlyLocomotive.java @@ -1,5 +1,6 @@ import java.awt.*; + public class DrawingWarmlyLocomotive { private EntityWarmlyLocomotive EntityWarmlyLocomotive; diff --git a/WarmlyLocomotive/src/FormWarmlyLocomotive.java b/WarmlyLocomotive/src/FormWarmlyLocomotive.java index 656ff9e..3f94f80 100644 --- a/WarmlyLocomotive/src/FormWarmlyLocomotive.java +++ b/WarmlyLocomotive/src/FormWarmlyLocomotive.java @@ -1,6 +1,13 @@ +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Random; + import javax.swing.*; public class FormWarmlyLocomotive extends JFrame { + DrawingWarmlyLocomotive _drawningWarmlyLocomotive; + JPanel pictureBox; public void Initialize(){ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); @@ -10,14 +17,25 @@ public class FormWarmlyLocomotive extends JFrame { setResizable(false); //pictireBox - JPanel pictureBox = new JPanel(); + pictureBox = new JPanel(); pictureBox.setSize(getWidth(), getHeight()); pictureBox.setLayout(null); //createButton JButton createButton = new JButton("Создать"); - createButton.setBounds(10, 420, 90, 30); + createButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + createButton_Click(); + //repaint(); + System.out.println("helpmepls"); + } + }); + //createButton.setBounds(10, 420, 90, 30); + createButton.setSize(90, 30); + createButton.setLocation(10, 420); pictureBox.add(createButton); + //upButton JButton upButton = new JButton(); @@ -52,6 +70,38 @@ public class FormWarmlyLocomotive extends JFrame { pictureBox.add(leftButton); repaint(); add(pictureBox); + + Graphics g = pictureBox.getGraphics(); + g.setColor(Color.BLACK); + g.fillRect(100, 100, 100, 100); + repaint(); + + } + // private void Draw() + // { + // if (_drawningWarmlyLocomotive.equals(null)) + // { + // return; + // } + // BufferedImage bmp = new BufferedImage(getWidth(), getHeight(), 1); + // Graphics gr = bmp.getGraphics(); + // _drawningWarmlyLocomotive.DrawTransport(gr); + // repaint(); + // } + + private void createButton_Click(){ + Random random = new Random(); + _drawningWarmlyLocomotive = new DrawingWarmlyLocomotive(); + _drawningWarmlyLocomotive.Init( + random.nextInt(200) + 100, + random.nextInt(2000) + 1000, + new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)), + new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)), + random.nextInt(2) != 0, random.nextInt(2) != 0); + _drawningWarmlyLocomotive.SetPictureSize(getWidth(), getHeight()); + _drawningWarmlyLocomotive.SetPosition(random.nextInt(90) + 10, random.nextInt(90) + 10); + _drawningWarmlyLocomotive.DrawTransport(getGraphics()); + } }