Advertisement
sfrsnyz

ЯП ЛАБА 8 МОЯ

May 17th, 2021
936
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 17.01 KB | None | 0 0
  1. ////////////// Menu
  2. package Laba8;
  3.  
  4. import javax.swing.*;
  5. import java.awt.*;
  6. import java.awt.geom.Ellipse2D;
  7. import java.awt.geom.Rectangle2D;
  8. import java.awt.geom.RoundRectangle2D;
  9. import java.util.Scanner;
  10.  
  11. public class Menu {
  12.     public static void menu() {
  13.         Scanner scanner = new Scanner(System.in);
  14.         int figure = -1;
  15.         while (true) {
  16.             System.out.println("Выберете фигуру, которую нужно добавить в меню: ");
  17.             System.out.println("1-Квадрат\n2-Прямоугольник\n3-Круг\n4-Суперэллипс\n0-Выход");
  18.             figure = scanner.nextInt();
  19.             if(figure==0)
  20.                 break;
  21.             if (figure == 1) {
  22.                 System.out.println("Выберете цвет:");
  23.                 System.out.println("red-красный\nyellow-желтый\nblue-синий\nblack-черный\nwhite-белый\ngreen-зеленый\ngradient-разноцветный\n0-Выход");
  24.                 JFrame jFrame = new JFrame();
  25.                 jFrame.setTitle("Лабораторная работа №8");
  26.                 jFrame.setVisible(true);
  27.                 jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  28.                 jFrame.setSize(800, 800);
  29.                 jFrame.setLocation(500, 100);
  30.                 String color = scanner.next();
  31.                 if (color.equals("0"))
  32.                     break;
  33.                 if (!color.equals("gradient")){
  34.                     System.out.println("Выберете тип линии: ");
  35.                     System.out.println("1-сплошная\n2-прерывистая");
  36.                     int line= scanner.nextInt();
  37.                     jFrame.add(new Quadrate(color,line));
  38.                 }
  39.                 else{
  40.                     System.out.println("Выберете вариант градиента: ");
  41.                     System.out.println("1-красно-белый\n2-Черно-желтый\n3-Красно-синий\n4-Сине-зеленый\n5-Желто-синий");
  42.                     int line=scanner.nextInt();
  43.                     jFrame.add(new Quadrate(color,line));
  44.  
  45.                 }
  46.             } else if (figure == 2) {
  47.                 System.out.println("Выберете цвет:");
  48.                 System.out.println("red-красный\nyellow-желтый\nblue-синий\nblack-черный\nwhite-белый\ngreen-зеленый\ngradient-разноцветный\n0-Выход");
  49.                 JFrame jFrame = new JFrame();
  50.                 jFrame.setTitle("Лабораторная работа №8");
  51.                 jFrame.setVisible(true);
  52.                 jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  53.                 jFrame.setSize(800, 800);
  54.                 jFrame.setLocation(500, 100);
  55.                 String color = scanner.next();
  56.                 if (color.equals("0"))
  57.                     break;
  58.                 if (!color.equals("gradient")){
  59.                     System.out.println("Выберете тип линии: ");
  60.                     System.out.println("1-сплошная\n2-прерывистая");
  61.                     int line= scanner.nextInt();
  62.                     jFrame.add(new Rectangle(color,line));
  63.                 }
  64.                 else{
  65.                     System.out.println("Выберете вариант градиента: ");
  66.                     System.out.println("1-красно-белый\n2-Черно-желтый\n3-Красно-синий\n4-Сине-зеленый\n5-Желто-синий");
  67.                     int line=scanner.nextInt();
  68.                     jFrame.add(new Rectangle(color,line));
  69.                 }
  70.             } else if (figure == 3) {
  71.                 System.out.println("Выберете цвет:");
  72.                 System.out.println("red-красный\nyellow-желтый\nblue-синий\nblack-черный\nwhite-белый\ngreen-зеленый\ngradient-разноцветный\n0-Выход");
  73.                 JFrame jFrame = new JFrame();
  74.                 jFrame.setTitle("Лабораторная работа №8");
  75.                 jFrame.setVisible(true);
  76.                 jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  77.                 jFrame.setSize(800, 800);
  78.                 jFrame.setLocation(500, 100);
  79.                 String color = scanner.next();
  80.                 if (color.equals("0"))
  81.                     break;
  82.                 if (!color.equals("gradient")){
  83.                     System.out.println("Выберете тип линии: ");
  84.                     System.out.println("1-сплошная\n2-прерывистая");
  85.                     int line= scanner.nextInt();
  86.                     jFrame.add(new Ocrug(color,line));
  87.                 }
  88.                 else{
  89.                     System.out.println("Выберете вариант градиента: ");
  90.                     System.out.println("1-красно-белый\n2-Черно-желтый\n3-Красно-синий\n4-Сине-зеленый\n5-Желто-синий");
  91.                     int line=scanner.nextInt();
  92.                     jFrame.add(new Ocrug(color,line));
  93.                 }
  94.             } else if (figure == 4) {
  95.                 System.out.println("Выберете цвет:");
  96.                 System.out.println("red-красный\nyellow-желтый\nblue-синий\nblack-черный\nwhite-белый\ngreen-зеленый\ngradient-разноцветный\n0-Выход");
  97.                 JFrame jFrame = new JFrame();
  98.                 jFrame.setTitle("Лабораторная работа №8");
  99.                 jFrame.setVisible(true);
  100.                 jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  101.                 jFrame.setSize(800, 800);
  102.                 jFrame.setLocation(500, 100);
  103.                 String color = scanner.next();
  104.                 if (color.equals("0"))
  105.                     break;
  106.                 if (!color.equals("gradient")){
  107.                     System.out.println("Выберете тип линии: ");
  108.                     System.out.println("1-сплошная\n2-прерывистая");
  109.                     int line= scanner.nextInt();
  110.                     jFrame.add(new SuperEllipse(color,line));
  111.                 }
  112.                 else{
  113.                     System.out.println("Выберете вариант градиента: ");
  114.                     System.out.println("1-красно-белый\n2-Черно-желтый\n3-Красно-синий\n4-Сине-зеленый\n5-Желто-синий");
  115.                     int line=scanner.nextInt();
  116.                     jFrame.add(new SuperEllipse(color,line));
  117.                 }
  118.             }
  119.  
  120.  
  121.         }
  122.     }
  123.  
  124.     public static class Quadrate extends JComponent {
  125.         private final String color;
  126.         private final  int lineType;
  127.  
  128.         public Quadrate(String color, int lineType) {
  129.             this.color = color;
  130.             this.lineType = lineType;
  131.         }
  132.  
  133.         @Override
  134.         protected void paintComponent(Graphics g) {
  135.             Font font = new Font("Serif", Font.BOLD, 40);
  136.             Graphics2D g2 = (Graphics2D) g;
  137.             g2.setFont(font);
  138.             if (color.equals("red"))
  139.                 g2.setPaint(Color.RED);
  140.             if (color.equals("yellow"))
  141.                 g2.setPaint(Color.YELLOW);
  142.             if (color.equals("blue"))
  143.                 g2.setPaint(Color.BLUE);
  144.             if (color.equals("black"))
  145.                 g2.setPaint(Color.BLACK);
  146.             if (color.equals("white"))
  147.                 g2.setPaint(Color.WHITE);
  148.             if (color.equals("green"))
  149.                 g2.setPaint(Color.GREEN);
  150.             if(color.equals("gradient")){
  151.                 if (lineType==1)
  152.                     g2.setPaint(new GradientPaint(50,60,Color.RED,60,50,Color.WHITE));
  153.                 if (lineType==2)
  154.                     g2.setPaint(new GradientPaint(50,60,Color.BLACK,60,50,Color.YELLOW));
  155.                 if (lineType==3)
  156.                     g2.setPaint(new GradientPaint(50,60,Color.RED,60,50,Color.BLUE));
  157.                 if (lineType==4)
  158.                     g2.setPaint(new GradientPaint(50,60,Color.BLUE,60,50,Color.GREEN));
  159.                 if (lineType==5)
  160.                     g2.setPaint(new GradientPaint(50,60,Color.YELLOW,60,50,Color.BLUE));
  161.                 Rectangle2D r = new Rectangle2D.Double(300, 250, 200, 200);
  162.                 g2.draw(r);
  163.                 g2.drawString("Ноздрюхин", 250, 45);
  164.                 g2.fill(r);
  165.             }
  166.             else {
  167.                 if (lineType == 1) {
  168.                     g2.drawString("Ноздрюхин", 250, 45);
  169.                     Rectangle2D r = new Rectangle2D.Double(300, 250, 200, 200);
  170.                     g2.draw(r);
  171.                     g2.fill(r);
  172.                 } else if (lineType == 2) {
  173.                     float[] dash2 = {20, 20};
  174.                     g2.setStroke(new BasicStroke(5, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL, 1, dash2, 0));
  175.                     g2.drawString("Ноздрюхин", 250, 45);
  176.                     Rectangle2D r = new Rectangle2D.Double(280, 250, 200, 200);
  177.                     g2.draw(r);
  178.                 }
  179.             }
  180.         }
  181.     }
  182.     Rectangle2D r = new Rectangle2D.Double(280, 250, 200, 200);
  183.     public static class Rectangle extends JComponent {
  184.         private final String color;
  185.         private final  int lineType; //1-спло
  186.  
  187.         public Rectangle(String color, int lineType) {
  188.             this.color = color;
  189.             this.lineType = lineType;
  190.         }
  191.  
  192.         @Override
  193.         protected void paintComponent(Graphics g) {
  194.             Font font = new Font("Complex", Font.ITALIC, 40);
  195.             Graphics2D g2 = (Graphics2D) g;
  196.             g2.setFont(font);
  197.             if (color.equals("red"))
  198.                 g2.setPaint(Color.RED);
  199.             if (color.equals("yellow"))
  200.                 g2.setPaint(Color.YELLOW);
  201.             if (color.equals("blue"))
  202.                 g2.setPaint(Color.BLUE);
  203.             if (color.equals("black"))
  204.                 g2.setPaint(Color.BLACK);
  205.             if (color.equals("white"))
  206.                 g2.setPaint(Color.WHITE);
  207.             if (color.equals("green"))
  208.                 g2.setPaint(Color.GREEN);
  209.             if(color.equals("gradient")){
  210.                 if (lineType==1)
  211.                     g2.setPaint(new GradientPaint(50,60,Color.RED,60,50,Color.WHITE));
  212.                 if (lineType==2)
  213.                     g2.setPaint(new GradientPaint(50,60,Color.BLACK,60,50,Color.YELLOW));
  214.                 if (lineType==3)
  215.                     g2.setPaint(new GradientPaint(50,60,Color.RED,60,50,Color.BLUE));
  216.                 if (lineType==4)
  217.                     g2.setPaint(new GradientPaint(50,60,Color.BLUE,60,50,Color.GREEN));
  218.                 if (lineType==5)
  219.                     g2.setPaint(new GradientPaint(50,60,Color.YELLOW,60,50,Color.BLUE));
  220.                 Rectangle2D r = new Rectangle2D.Double(300, 250, 150, 300);
  221.                 g2.draw(r);
  222.                 g2.drawString("Ноздрюхин", 250, 45);
  223.                 g2.fill(r);
  224.             }
  225.             else {
  226.                 if (lineType == 1) {
  227.                     g2.drawString("Ноздрюхин", 250, 45);
  228.                     Rectangle2D r = new Rectangle2D.Double(300, 250, 150, 300);
  229.                     g2.draw(r);
  230.                     g2.fill(r);
  231.                 } else if (lineType == 2) {
  232.                     float[] dash2 = {20, 20};
  233.                     g2.setStroke(new BasicStroke(5, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL, 1, dash2, 0));
  234.                     g2.drawString("Ноздрюхин", 250, 45);
  235.                     Rectangle2D r = new Rectangle2D.Double(300, 250, 150, 300);
  236.                     g2.draw(r);
  237.                 }
  238.             }
  239.  
  240.         }
  241.     }
  242.  
  243.     public static class Ocrug extends JComponent {
  244.         private final String color;
  245.         private final  int lineType; //1-спло
  246.  
  247.         public Ocrug(String color, int lineType) {
  248.             this.color = color;
  249.             this.lineType = lineType;
  250.         }
  251.  
  252.         @Override
  253.         protected void paintComponent(Graphics g) {
  254.             Font font = new Font("Arial Black", Font.PLAIN, 40);
  255.             Graphics2D g2 = (Graphics2D) g;
  256.             g2.setFont(font);
  257.             if (color.equals("red"))
  258.                 g2.setPaint(Color.RED);
  259.             if (color.equals("yellow"))
  260.                 g2.setPaint(Color.YELLOW);
  261.             if (color.equals("blue"))
  262.                 g2.setPaint(Color.BLUE);
  263.             if (color.equals("black"))
  264.                 g2.setPaint(Color.BLACK);
  265.             if (color.equals("white"))
  266.                 g2.setPaint(Color.WHITE);
  267.             if (color.equals("green"))
  268.                 g2.setPaint(Color.GREEN);
  269.             if(color.equals("gradient")){
  270.                 if (lineType==1)
  271.                     g2.setPaint(new GradientPaint(50,60,Color.RED,60,50,Color.WHITE));
  272.                 if (lineType==2)
  273.                     g2.setPaint(new GradientPaint(50,60,Color.BLACK,60,50,Color.YELLOW));
  274.                 if (lineType==3)
  275.                     g2.setPaint(new GradientPaint(50,60,Color.RED,60,50,Color.BLUE));
  276.                 if (lineType==4)
  277.                     g2.setPaint(new GradientPaint(50,60,Color.BLUE,60,50,Color.GREEN));
  278.                 if (lineType==5)
  279.                     g2.setPaint(new GradientPaint(50,60,Color.YELLOW,60,50,Color.BLUE));
  280.                 Ellipse2D r = new Ellipse2D.Double(280, 250, 200, 200);
  281.                 g2.draw(r);
  282.                 g2.drawString("Ноздрюхин", 250, 45);
  283.                 g2.fill(r);
  284.             }
  285.             else {
  286.                 if (lineType == 1) {
  287.                     g2.drawString("Ноздрюхин", 250, 45);
  288.                     Ellipse2D r = new Ellipse2D.Double(280, 250, 200, 200);
  289.                     g2.draw(r);
  290.                     g2.fill(r);
  291.                 } else if (lineType == 2) {
  292.                     float[] dash2 = {20, 20};
  293.                     g2.setStroke(new BasicStroke(5, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL, 1, dash2, 0));
  294.                     g2.drawString("Ноздрюхин", 250, 45);
  295.                     Ellipse2D r = new Ellipse2D.Double(280, 250, 200, 200);
  296.                     g2.draw(r);
  297.                 }
  298.             }
  299.  
  300.         }
  301.     }
  302.     public static class SuperEllipse extends JComponent {
  303.         private final String color;
  304.         private final  int lineType;
  305.  
  306.         public SuperEllipse(String color, int lineType) {
  307.             this.color = color;
  308.             this.lineType = lineType;
  309.         }
  310.  
  311.         @Override
  312.         protected void paintComponent(Graphics g) {
  313.             Font font = new Font("Calibri Light", Font.ITALIC, 40);
  314.             Graphics2D g2 = (Graphics2D) g;
  315.             g2.setFont(font);
  316.             if (color.equals("red"))
  317.                 g2.setPaint(Color.RED);
  318.             if (color.equals("yellow"))
  319.                 g2.setPaint(Color.YELLOW);
  320.             if (color.equals("blue"))
  321.                 g2.setPaint(Color.BLUE);
  322.             if (color.equals("black"))
  323.                 g2.setPaint(Color.BLACK);
  324.             if (color.equals("white"))
  325.                 g2.setPaint(Color.WHITE);
  326.             if (color.equals("green"))
  327.                 g2.setPaint(Color.GREEN);
  328.             if(color.equals("gradient")){
  329.                 if (lineType==1)
  330.                     g2.setPaint(new GradientPaint(50,60,Color.RED,60,50,Color.WHITE));
  331.                 if (lineType==2)
  332.                     g2.setPaint(new GradientPaint(50,60,Color.BLACK,60,50,Color.YELLOW));
  333.                 if (lineType==3)
  334.                     g2.setPaint(new GradientPaint(50,60,Color.RED,60,50,Color.BLUE));
  335.                 if (lineType==4)
  336.                     g2.setPaint(new GradientPaint(50,60,Color.BLUE,60,50,Color.GREEN));
  337.                 if (lineType==5)
  338.                     g2.setPaint(new GradientPaint(50,60,Color.YELLOW,60,50,Color.BLUE));
  339.                 RoundRectangle2D r = new RoundRectangle2D.Double(280, 250, 200, 200, 100, 100);
  340.                 g2.draw(r);
  341.                 g2.drawString("Ноздрюхин", 250, 45);
  342.                 g2.fill(r);
  343.             }
  344.             else {
  345.                 if (lineType == 1) {
  346.                     g2.drawString("Ноздрюхин", 250, 45);
  347.                     RoundRectangle2D r = new RoundRectangle2D.Double(280, 250, 200, 200, 100, 100);
  348.                     g2.draw(r);
  349.                     g2.fill(r);
  350.                 } else if (lineType == 2) {
  351.                     float[] dash2 = {20, 20};
  352.                     g2.setStroke(new BasicStroke(5, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL, 1, dash2, 0));
  353.                     g2.drawString("Ноздрюхин", 250, 45);
  354.                     RoundRectangle2D r = new RoundRectangle2D.Double(280, 250, 200, 200, 100, 100);
  355.                     g2.draw(r);
  356.                 }
  357.             }
  358.  
  359.         }
  360.     }
  361. }
  362.  
  363. /////////// Main
  364. package Laba8;
  365.  
  366.  
  367. public class Main {
  368.     public static void main(String[] args) {
  369.         Menu.menu();
  370.     }
  371. }
  372.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement