Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. import java.awt.BorderLayout;
  2. import java.awt.Color;
  3. import java.awt.FlowLayout;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import java.awt.image.BufferedImage;
  7.  
  8. import javax.swing.Box;
  9. import javax.swing.Icon;
  10. import javax.swing.ImageIcon;
  11. import javax.swing.JButton;
  12. import javax.swing.JColorChooser;
  13. import javax.swing.JFrame;
  14. import javax.swing.JPanel;
  15.  
  16. public class GUIforPaint extends JFrame {
  17.  
  18. private JButton lineButton;
  19. private JButton rectangleButton;
  20. private JButton ellipseButton;
  21. private JButton strokeButton;
  22. private JButton fillButton;
  23. private Box boxForButtons;
  24. private JPanel iconPanel;
  25. private int shapeSelected;
  26. private Color stroke;
  27. private Color fill;
  28. DrawingArea drawingPad;
  29. public GUIforPaint() {
  30. stroke = Color.RED;
  31. fill = Color.BLACK;
  32. shapeSelected = 1;
  33. setTitle("Paint Vectors");
  34. setSize(600, 600);
  35. setVisible(true);
  36. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  37. iconPanel = new JPanel();
  38. boxForButtons = Box.createVerticalBox();
  39. initializeButtons();
  40. add(iconPanel , BorderLayout.WEST);
  41. drawingPad = new DrawingArea();
  42. add(drawingPad , BorderLayout.CENTER);
  43. }
  44.  
  45. private void initializeButtons() {
  46. lineButton = makeButton1("/home/moamen/Desktop/Paint/images/t1_left3_16_16.gif", 1);
  47. rectangleButton = makeButton1("/home/moamen/Desktop/Paint/images/rect1_16_16.gif", 2);
  48. ellipseButton = makeButton1("/home/moamen/Desktop/Paint/images/elipse_16_16.gif", 3);
  49. strokeButton = makeButton2("/home/moamen/Desktop/Paint/images/t1_point3_16_16.gif", 4, true);
  50. fillButton = makeButton2("/home/moamen/Desktop/Paint/images/paint_16_16.gif", 5, false);
  51. boxForButtons.add(lineButton);
  52. boxForButtons.add(rectangleButton);
  53. boxForButtons.add(ellipseButton);
  54. boxForButtons.add(strokeButton);
  55. boxForButtons.add(fillButton);
  56. iconPanel.add(boxForButtons);
  57. }
  58.  
  59. private JButton makeButton1(String sourcePath , final int actionForit) {
  60.  
  61. JButton retButton = new JButton();
  62. Icon icon = new ImageIcon(sourcePath);
  63. retButton.setIcon(icon);
  64. retButton.addActionListener(new ActionListener() {
  65. public void actionPerformed(ActionEvent e) {
  66. shapeSelected = actionForit;
  67. }
  68. });
  69. return retButton;
  70. }
  71.  
  72. public JButton makeButton2(String sourcePath , final int actionForit , final boolean actio) {
  73.  
  74. JButton retButton = new JButton();
  75. Icon icon = new ImageIcon(sourcePath);
  76. retButton.setIcon(icon);
  77. retButton.addActionListener(new ActionListener() {
  78. public void actionPerformed(ActionEvent e) {
  79. if(actio)
  80. stroke = JColorChooser.showDialog(null, "Select color", Color.BLACK);
  81. else
  82. fill = JColorChooser.showDialog(null, "Select color", Color.BLACK);
  83. drawingPad.setColors(stroke, fill);
  84. }
  85. });
  86. return retButton;
  87. }
  88. public static void main(String[] args) {
  89. new GUIforPaint();
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement