Advertisement
codisinmyvines

PaintTask1

Nov 12th, 2021
690
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.02 KB | None | 0 0
  1. package hw9;
  2.  
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.geom.Ellipse2D;
  6. import java.awt.geom.Line2D;
  7. import java.awt.geom.Rectangle2D;
  8.  
  9. class MyFrame extends JFrame {
  10.     public MyFrame() {
  11.         setSize(800, 600);
  12.         setTitle("Picture 1");
  13.         setDefaultCloseOperation(EXIT_ON_CLOSE);
  14.         setVisible(true);
  15.         DrawComponent mc = new DrawComponent();
  16.         add(mc);
  17.  
  18.     }
  19. }
  20.  
  21. class DrawComponent extends JComponent {
  22.     public void paint(Graphics g) {
  23.         Graphics2D g2 = (Graphics2D) g;
  24.         //все что за окном
  25.         Rectangle2D horizon = new Rectangle2D.Double(200, 80, 400, 200);
  26.         g2.setPaint(new Color(98, 238, 209));
  27.         g2.fill(horizon);
  28.         g2.draw(horizon);
  29.         Rectangle2D grass = new Rectangle2D.Double(200, 280, 400, 200);
  30.         g2.setPaint(new Color(61, 155, 41));
  31.         g2.fill(grass);
  32.         g2.draw(grass);
  33.         //солнце
  34.         Ellipse2D sun = new Ellipse2D.Double(480, 120, 80, 80);
  35.         g2.setPaint(new Color(255, 255, 0));
  36.         g2.fill(sun);
  37.         g2.draw(sun);
  38.         Line2D l1 = new Line2D.Double(520, 100, 520, 220);
  39.         g2.draw(l1);
  40.         Line2D l2 = new Line2D.Double(460, 160, 580, 160);
  41.         g2.draw(l2);
  42.         Line2D l3 = new Line2D.Double(570, 105, 480, 220);
  43.         g2.draw(l3);
  44.         Line2D l4 = new Line2D.Double(470, 115, 570, 210);
  45.         g2.draw(l4);
  46.         //окно
  47.         g2.setPaint(new Color(162, 94, 59));
  48.         Rectangle2D podokonnik = new Rectangle2D.Double(160, 480, 480, 20);
  49.         g2.fill(podokonnik);
  50.         g2.draw(podokonnik);
  51.         Rectangle2D p1 = new Rectangle2D.Double(190, 70, 10, 410);
  52.         g2.fill(p1);
  53.         g2.draw(p1);
  54.         Rectangle2D p2 = new Rectangle2D.Double(190, 70, 420, 10);
  55.         g2.fill(p2);
  56.         g2.draw(p2);
  57.         Rectangle2D p3 = new Rectangle2D.Double(600, 70, 10, 410);
  58.         g2.fill(p3);
  59.         g2.draw(p3);
  60.         Rectangle2D p4 = new Rectangle2D.Double(395, 70, 10, 410);
  61.         g2.fill(p4);
  62.         g2.draw(p4);
  63.         //горшок
  64.         g2.setPaint(new Color(255, 159, 17));
  65.         Rectangle2D gorshok = new Rectangle2D.Double(260, 400, 60, 80);
  66.         g2.fill(gorshok);
  67.         g2.draw(gorshok);
  68.         //цветок
  69.         g2.setPaint(new Color(17, 255, 0));
  70.         Line2D stvol = new Line2D.Double(290, 360, 290, 400);
  71.         g2.draw(stvol);
  72.         g2.setPaint(new Color(255, 38, 38));
  73.         Polygon pol1 = new Polygon(new int[]{275, 275, 300}, new int[]{340, 360, 360}, 3);
  74.         g2.fill(pol1);
  75.         g2.draw(pol1);
  76.         Polygon pol2 = new Polygon(new int[]{305, 305, 280}, new int[]{340, 360, 360}, 3);
  77.         g2.fill(pol2);
  78.         g2.draw(pol2);
  79.         g2.setPaint(new Color(17, 255, 0));
  80.         Polygon pol3 = new Polygon(new int[]{290, 300, 300}, new int[]{380, 370, 380}, 3);
  81.         g2.fill(pol3);
  82.         g2.draw(pol3);
  83.     }
  84. }
  85.  
  86. public class PaintTask1 {
  87.     public static void main(String[] args) {
  88.         MyFrame f = new MyFrame();
  89.     }
  90. }
  91.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement