Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////////////// Menu
- package Laba8;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.geom.Ellipse2D;
- import java.awt.geom.Rectangle2D;
- import java.awt.geom.RoundRectangle2D;
- import java.util.Scanner;
- public class Menu {
- public static void menu() {
- Scanner scanner = new Scanner(System.in);
- int figure = -1;
- while (true) {
- System.out.println("Выберете фигуру, которую нужно добавить в меню: ");
- System.out.println("1-Квадрат\n2-Прямоугольник\n3-Круг\n4-Суперэллипс\n0-Выход");
- figure = scanner.nextInt();
- if(figure==0)
- break;
- if (figure == 1) {
- System.out.println("Выберете цвет:");
- System.out.println("red-красный\nyellow-желтый\nblue-синий\nblack-черный\nwhite-белый\ngreen-зеленый\ngradient-разноцветный\n0-Выход");
- JFrame jFrame = new JFrame();
- jFrame.setTitle("Лабораторная работа №8");
- jFrame.setVisible(true);
- jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- jFrame.setSize(800, 800);
- jFrame.setLocation(500, 100);
- String color = scanner.next();
- if (color.equals("0"))
- break;
- if (!color.equals("gradient")){
- System.out.println("Выберете тип линии: ");
- System.out.println("1-сплошная\n2-прерывистая");
- int line= scanner.nextInt();
- jFrame.add(new Quadrate(color,line));
- }
- else{
- System.out.println("Выберете вариант градиента: ");
- System.out.println("1-красно-белый\n2-Черно-желтый\n3-Красно-синий\n4-Сине-зеленый\n5-Желто-синий");
- int line=scanner.nextInt();
- jFrame.add(new Quadrate(color,line));
- }
- } else if (figure == 2) {
- System.out.println("Выберете цвет:");
- System.out.println("red-красный\nyellow-желтый\nblue-синий\nblack-черный\nwhite-белый\ngreen-зеленый\ngradient-разноцветный\n0-Выход");
- JFrame jFrame = new JFrame();
- jFrame.setTitle("Лабораторная работа №8");
- jFrame.setVisible(true);
- jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- jFrame.setSize(800, 800);
- jFrame.setLocation(500, 100);
- String color = scanner.next();
- if (color.equals("0"))
- break;
- if (!color.equals("gradient")){
- System.out.println("Выберете тип линии: ");
- System.out.println("1-сплошная\n2-прерывистая");
- int line= scanner.nextInt();
- jFrame.add(new Rectangle(color,line));
- }
- else{
- System.out.println("Выберете вариант градиента: ");
- System.out.println("1-красно-белый\n2-Черно-желтый\n3-Красно-синий\n4-Сине-зеленый\n5-Желто-синий");
- int line=scanner.nextInt();
- jFrame.add(new Rectangle(color,line));
- }
- } else if (figure == 3) {
- System.out.println("Выберете цвет:");
- System.out.println("red-красный\nyellow-желтый\nblue-синий\nblack-черный\nwhite-белый\ngreen-зеленый\ngradient-разноцветный\n0-Выход");
- JFrame jFrame = new JFrame();
- jFrame.setTitle("Лабораторная работа №8");
- jFrame.setVisible(true);
- jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- jFrame.setSize(800, 800);
- jFrame.setLocation(500, 100);
- String color = scanner.next();
- if (color.equals("0"))
- break;
- if (!color.equals("gradient")){
- System.out.println("Выберете тип линии: ");
- System.out.println("1-сплошная\n2-прерывистая");
- int line= scanner.nextInt();
- jFrame.add(new Ocrug(color,line));
- }
- else{
- System.out.println("Выберете вариант градиента: ");
- System.out.println("1-красно-белый\n2-Черно-желтый\n3-Красно-синий\n4-Сине-зеленый\n5-Желто-синий");
- int line=scanner.nextInt();
- jFrame.add(new Ocrug(color,line));
- }
- } else if (figure == 4) {
- System.out.println("Выберете цвет:");
- System.out.println("red-красный\nyellow-желтый\nblue-синий\nblack-черный\nwhite-белый\ngreen-зеленый\ngradient-разноцветный\n0-Выход");
- JFrame jFrame = new JFrame();
- jFrame.setTitle("Лабораторная работа №8");
- jFrame.setVisible(true);
- jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- jFrame.setSize(800, 800);
- jFrame.setLocation(500, 100);
- String color = scanner.next();
- if (color.equals("0"))
- break;
- if (!color.equals("gradient")){
- System.out.println("Выберете тип линии: ");
- System.out.println("1-сплошная\n2-прерывистая");
- int line= scanner.nextInt();
- jFrame.add(new SuperEllipse(color,line));
- }
- else{
- System.out.println("Выберете вариант градиента: ");
- System.out.println("1-красно-белый\n2-Черно-желтый\n3-Красно-синий\n4-Сине-зеленый\n5-Желто-синий");
- int line=scanner.nextInt();
- jFrame.add(new SuperEllipse(color,line));
- }
- }
- }
- }
- public static class Quadrate extends JComponent {
- private final String color;
- private final int lineType;
- public Quadrate(String color, int lineType) {
- this.color = color;
- this.lineType = lineType;
- }
- @Override
- protected void paintComponent(Graphics g) {
- Font font = new Font("Serif", Font.BOLD, 40);
- Graphics2D g2 = (Graphics2D) g;
- g2.setFont(font);
- if (color.equals("red"))
- g2.setPaint(Color.RED);
- if (color.equals("yellow"))
- g2.setPaint(Color.YELLOW);
- if (color.equals("blue"))
- g2.setPaint(Color.BLUE);
- if (color.equals("black"))
- g2.setPaint(Color.BLACK);
- if (color.equals("white"))
- g2.setPaint(Color.WHITE);
- if (color.equals("green"))
- g2.setPaint(Color.GREEN);
- if(color.equals("gradient")){
- if (lineType==1)
- g2.setPaint(new GradientPaint(50,60,Color.RED,60,50,Color.WHITE));
- if (lineType==2)
- g2.setPaint(new GradientPaint(50,60,Color.BLACK,60,50,Color.YELLOW));
- if (lineType==3)
- g2.setPaint(new GradientPaint(50,60,Color.RED,60,50,Color.BLUE));
- if (lineType==4)
- g2.setPaint(new GradientPaint(50,60,Color.BLUE,60,50,Color.GREEN));
- if (lineType==5)
- g2.setPaint(new GradientPaint(50,60,Color.YELLOW,60,50,Color.BLUE));
- Rectangle2D r = new Rectangle2D.Double(300, 250, 200, 200);
- g2.draw(r);
- g2.drawString("Ноздрюхин", 250, 45);
- g2.fill(r);
- }
- else {
- if (lineType == 1) {
- g2.drawString("Ноздрюхин", 250, 45);
- Rectangle2D r = new Rectangle2D.Double(300, 250, 200, 200);
- g2.draw(r);
- g2.fill(r);
- } else if (lineType == 2) {
- float[] dash2 = {20, 20};
- g2.setStroke(new BasicStroke(5, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL, 1, dash2, 0));
- g2.drawString("Ноздрюхин", 250, 45);
- Rectangle2D r = new Rectangle2D.Double(280, 250, 200, 200);
- g2.draw(r);
- }
- }
- }
- }
- Rectangle2D r = new Rectangle2D.Double(280, 250, 200, 200);
- public static class Rectangle extends JComponent {
- private final String color;
- private final int lineType; //1-спло
- public Rectangle(String color, int lineType) {
- this.color = color;
- this.lineType = lineType;
- }
- @Override
- protected void paintComponent(Graphics g) {
- Font font = new Font("Complex", Font.ITALIC, 40);
- Graphics2D g2 = (Graphics2D) g;
- g2.setFont(font);
- if (color.equals("red"))
- g2.setPaint(Color.RED);
- if (color.equals("yellow"))
- g2.setPaint(Color.YELLOW);
- if (color.equals("blue"))
- g2.setPaint(Color.BLUE);
- if (color.equals("black"))
- g2.setPaint(Color.BLACK);
- if (color.equals("white"))
- g2.setPaint(Color.WHITE);
- if (color.equals("green"))
- g2.setPaint(Color.GREEN);
- if(color.equals("gradient")){
- if (lineType==1)
- g2.setPaint(new GradientPaint(50,60,Color.RED,60,50,Color.WHITE));
- if (lineType==2)
- g2.setPaint(new GradientPaint(50,60,Color.BLACK,60,50,Color.YELLOW));
- if (lineType==3)
- g2.setPaint(new GradientPaint(50,60,Color.RED,60,50,Color.BLUE));
- if (lineType==4)
- g2.setPaint(new GradientPaint(50,60,Color.BLUE,60,50,Color.GREEN));
- if (lineType==5)
- g2.setPaint(new GradientPaint(50,60,Color.YELLOW,60,50,Color.BLUE));
- Rectangle2D r = new Rectangle2D.Double(300, 250, 150, 300);
- g2.draw(r);
- g2.drawString("Ноздрюхин", 250, 45);
- g2.fill(r);
- }
- else {
- if (lineType == 1) {
- g2.drawString("Ноздрюхин", 250, 45);
- Rectangle2D r = new Rectangle2D.Double(300, 250, 150, 300);
- g2.draw(r);
- g2.fill(r);
- } else if (lineType == 2) {
- float[] dash2 = {20, 20};
- g2.setStroke(new BasicStroke(5, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL, 1, dash2, 0));
- g2.drawString("Ноздрюхин", 250, 45);
- Rectangle2D r = new Rectangle2D.Double(300, 250, 150, 300);
- g2.draw(r);
- }
- }
- }
- }
- public static class Ocrug extends JComponent {
- private final String color;
- private final int lineType; //1-спло
- public Ocrug(String color, int lineType) {
- this.color = color;
- this.lineType = lineType;
- }
- @Override
- protected void paintComponent(Graphics g) {
- Font font = new Font("Arial Black", Font.PLAIN, 40);
- Graphics2D g2 = (Graphics2D) g;
- g2.setFont(font);
- if (color.equals("red"))
- g2.setPaint(Color.RED);
- if (color.equals("yellow"))
- g2.setPaint(Color.YELLOW);
- if (color.equals("blue"))
- g2.setPaint(Color.BLUE);
- if (color.equals("black"))
- g2.setPaint(Color.BLACK);
- if (color.equals("white"))
- g2.setPaint(Color.WHITE);
- if (color.equals("green"))
- g2.setPaint(Color.GREEN);
- if(color.equals("gradient")){
- if (lineType==1)
- g2.setPaint(new GradientPaint(50,60,Color.RED,60,50,Color.WHITE));
- if (lineType==2)
- g2.setPaint(new GradientPaint(50,60,Color.BLACK,60,50,Color.YELLOW));
- if (lineType==3)
- g2.setPaint(new GradientPaint(50,60,Color.RED,60,50,Color.BLUE));
- if (lineType==4)
- g2.setPaint(new GradientPaint(50,60,Color.BLUE,60,50,Color.GREEN));
- if (lineType==5)
- g2.setPaint(new GradientPaint(50,60,Color.YELLOW,60,50,Color.BLUE));
- Ellipse2D r = new Ellipse2D.Double(280, 250, 200, 200);
- g2.draw(r);
- g2.drawString("Ноздрюхин", 250, 45);
- g2.fill(r);
- }
- else {
- if (lineType == 1) {
- g2.drawString("Ноздрюхин", 250, 45);
- Ellipse2D r = new Ellipse2D.Double(280, 250, 200, 200);
- g2.draw(r);
- g2.fill(r);
- } else if (lineType == 2) {
- float[] dash2 = {20, 20};
- g2.setStroke(new BasicStroke(5, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL, 1, dash2, 0));
- g2.drawString("Ноздрюхин", 250, 45);
- Ellipse2D r = new Ellipse2D.Double(280, 250, 200, 200);
- g2.draw(r);
- }
- }
- }
- }
- public static class SuperEllipse extends JComponent {
- private final String color;
- private final int lineType;
- public SuperEllipse(String color, int lineType) {
- this.color = color;
- this.lineType = lineType;
- }
- @Override
- protected void paintComponent(Graphics g) {
- Font font = new Font("Calibri Light", Font.ITALIC, 40);
- Graphics2D g2 = (Graphics2D) g;
- g2.setFont(font);
- if (color.equals("red"))
- g2.setPaint(Color.RED);
- if (color.equals("yellow"))
- g2.setPaint(Color.YELLOW);
- if (color.equals("blue"))
- g2.setPaint(Color.BLUE);
- if (color.equals("black"))
- g2.setPaint(Color.BLACK);
- if (color.equals("white"))
- g2.setPaint(Color.WHITE);
- if (color.equals("green"))
- g2.setPaint(Color.GREEN);
- if(color.equals("gradient")){
- if (lineType==1)
- g2.setPaint(new GradientPaint(50,60,Color.RED,60,50,Color.WHITE));
- if (lineType==2)
- g2.setPaint(new GradientPaint(50,60,Color.BLACK,60,50,Color.YELLOW));
- if (lineType==3)
- g2.setPaint(new GradientPaint(50,60,Color.RED,60,50,Color.BLUE));
- if (lineType==4)
- g2.setPaint(new GradientPaint(50,60,Color.BLUE,60,50,Color.GREEN));
- if (lineType==5)
- g2.setPaint(new GradientPaint(50,60,Color.YELLOW,60,50,Color.BLUE));
- RoundRectangle2D r = new RoundRectangle2D.Double(280, 250, 200, 200, 100, 100);
- g2.draw(r);
- g2.drawString("Ноздрюхин", 250, 45);
- g2.fill(r);
- }
- else {
- if (lineType == 1) {
- g2.drawString("Ноздрюхин", 250, 45);
- RoundRectangle2D r = new RoundRectangle2D.Double(280, 250, 200, 200, 100, 100);
- g2.draw(r);
- g2.fill(r);
- } else if (lineType == 2) {
- float[] dash2 = {20, 20};
- g2.setStroke(new BasicStroke(5, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL, 1, dash2, 0));
- g2.drawString("Ноздрюхин", 250, 45);
- RoundRectangle2D r = new RoundRectangle2D.Double(280, 250, 200, 200, 100, 100);
- g2.draw(r);
- }
- }
- }
- }
- }
- /////////// Main
- package Laba8;
- public class Main {
- public static void main(String[] args) {
- Menu.menu();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement