Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.BorderLayout;
- import java.awt.Color;
- import java.awt.FlowLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.image.BufferedImage;
- import javax.swing.Box;
- import javax.swing.Icon;
- import javax.swing.ImageIcon;
- import javax.swing.JButton;
- import javax.swing.JColorChooser;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- public class GUIforPaint extends JFrame {
- private JButton lineButton;
- private JButton rectangleButton;
- private JButton ellipseButton;
- private JButton strokeButton;
- private JButton fillButton;
- private Box boxForButtons;
- private JPanel iconPanel;
- private int shapeSelected;
- private Color stroke;
- private Color fill;
- DrawingArea drawingPad;
- public GUIforPaint() {
- stroke = Color.RED;
- fill = Color.BLACK;
- shapeSelected = 1;
- setTitle("Paint Vectors");
- setSize(600, 600);
- setVisible(true);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- iconPanel = new JPanel();
- boxForButtons = Box.createVerticalBox();
- initializeButtons();
- add(iconPanel , BorderLayout.WEST);
- drawingPad = new DrawingArea();
- add(drawingPad , BorderLayout.CENTER);
- }
- private void initializeButtons() {
- lineButton = makeButton1("/home/moamen/Desktop/Paint/images/t1_left3_16_16.gif", 1);
- rectangleButton = makeButton1("/home/moamen/Desktop/Paint/images/rect1_16_16.gif", 2);
- ellipseButton = makeButton1("/home/moamen/Desktop/Paint/images/elipse_16_16.gif", 3);
- strokeButton = makeButton2("/home/moamen/Desktop/Paint/images/t1_point3_16_16.gif", 4, true);
- fillButton = makeButton2("/home/moamen/Desktop/Paint/images/paint_16_16.gif", 5, false);
- boxForButtons.add(lineButton);
- boxForButtons.add(rectangleButton);
- boxForButtons.add(ellipseButton);
- boxForButtons.add(strokeButton);
- boxForButtons.add(fillButton);
- iconPanel.add(boxForButtons);
- }
- private JButton makeButton1(String sourcePath , final int actionForit) {
- JButton retButton = new JButton();
- Icon icon = new ImageIcon(sourcePath);
- retButton.setIcon(icon);
- retButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- shapeSelected = actionForit;
- }
- });
- return retButton;
- }
- public JButton makeButton2(String sourcePath , final int actionForit , final boolean actio) {
- JButton retButton = new JButton();
- Icon icon = new ImageIcon(sourcePath);
- retButton.setIcon(icon);
- retButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- if(actio)
- stroke = JColorChooser.showDialog(null, "Select color", Color.BLACK);
- else
- fill = JColorChooser.showDialog(null, "Select color", Color.BLACK);
- drawingPad.setColors(stroke, fill);
- }
- });
- return retButton;
- }
- public static void main(String[] args) {
- new GUIforPaint();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement