Advertisement
sfrsnyz

Нархов 8

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