Guest User

Untitled

a guest
Jan 18th, 2020
71
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.company;
  2.  
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7. import java.awt.event.WindowAdapter;
  8. import java.awt.event.WindowEvent;
  9.  
  10. public class ViewPaint extends Panel {
  11.  
  12. public ViewPaint(){
  13. setLayout(new BorderLayout());
  14. ChoiseColor choiseColor = new ChoiseColor();
  15. Button buttonBlue = new Button("Синий");
  16. buttonBlue.addActionListener(new ActionListener() {
  17. @Override
  18. public void actionPerformed(ActionEvent e) {
  19. choiseColor.setColor(Color.BLUE);
  20. }
  21. });
  22. Button buttonGreen = new Button("Зеленый");
  23. buttonGreen.addActionListener(new ActionListener() {
  24. @Override
  25. public void actionPerformed(ActionEvent e) {
  26. choiseColor.setColor(Color.GREEN);
  27. }
  28. });
  29. Button buttonRed = new Button("Красный");
  30. buttonRed.addActionListener(new ActionListener() {
  31. @Override
  32. public void actionPerformed(ActionEvent e) {
  33. choiseColor.setColor(Color.RED);
  34. }
  35. });
  36. Button buttonWhite = new Button("Белая");
  37. buttonWhite.addActionListener(new ActionListener() {
  38. @Override
  39. public void actionPerformed(ActionEvent e) {
  40. choiseColor.setColor(Color.WHITE);
  41. }
  42. });
  43. Button buttonYellow = new Button("Желтый");
  44. buttonYellow.addActionListener(new ActionListener() {
  45. @Override
  46. public void actionPerformed(ActionEvent e) {
  47. choiseColor.setColor(Color.YELLOW);
  48. }
  49. });
  50. Button buttonBlack = new Button("Черный");
  51. buttonBlack.addActionListener(new ActionListener() {
  52. @Override
  53. public void actionPerformed(ActionEvent e) {
  54. choiseColor.setColor(Color.BLACK);
  55. }
  56. });
  57. Button buttonBrash = new Button("Кисть");
  58. buttonBrash.addActionListener(new ActionListener() {
  59. @Override
  60. public void actionPerformed(ActionEvent e) {
  61. choiseColor.setBrush();
  62. }
  63. });
  64. Button clear = new Button("Очистить");
  65. clear.addActionListener(new ActionListener() {
  66. @Override
  67. public void actionPerformed(ActionEvent e) {
  68. choiseColor.clear();
  69. }
  70. });
  71. Panel buttons = new Panel();
  72. buttons.setLayout(new GridLayout(4,2));
  73. buttons.add(buttonBlue);
  74. buttons.add(buttonGreen);
  75. buttons.add(buttonRed);
  76. buttons.add(buttonWhite);
  77. buttons.add(buttonBlack);
  78. buttons.add(buttonYellow);
  79. buttons.add(buttonBrash);
  80. buttons.add(clear);
  81. add(buttons , BorderLayout.NORTH);
  82. add(choiseColor , BorderLayout.CENTER);
  83.  
  84. }
  85. public static void main(String[] args) {
  86. Frame frame = new Frame("ViewForm");
  87. frame.add(new ViewPaint());
  88. frame.setSize(600, 400);
  89. frame.setLocation(100, 100);
  90. frame.setVisible(true);
  91. frame.addWindowListener(new WindowAdapter() {
  92. public void windowClosing(WindowEvent e) {
  93. System.exit(0);
  94. }
  95. });
  96. }
  97. }
RAW Paste Data