Advertisement
sfrsnyz

Григорьев ЯП8

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