Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import javax.swing.*;
- import java.awt.event.*;
- import java.util.ArrayList;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import javax.swing.JPanel;
- import javax.swing.JButton;
- import javax.swing.JComboBox; // black, red, blue, green, orange
- public class WholePanel extends JPanel
- {
- private Color currentColor;
- private CanvasPanel canvas;
- private JPanel leftPanel, buttonPanel, main;
- private JButton undo, clear;
- private ArrayList rectList;
- private JComboBox comboBox;
- private String [] cList= {"black", "red", "blue", "green", "orange"};
- Point p;
- public class Rectangle
- {
- private int x1;
- private int y1;
- private int width;
- private int height;
- private Color color;
- }
- public void Rectangle(int x1, int y1, int width1, int height1, Color color)
- {
- x1=0;
- y1=0;
- width1 = 0;
- height1 = 0;
- color = new Color(height1);
- }
- public void draw(Graphics page){
- }
- public void fillRect(int x1, int y1, int hieght1, int width1){
- }
- public void drawLine(int x1, int y1, int x2, int y2){
- }
- public WholePanel()
- {
- //default color to draw is black
- currentColor = Color.BLACK;
- rectList = new ArrayList();
- undo = new JButton ("Undo");
- clear = new JButton("Clear");
- // undo.addActionListener(new ButtonListener());
- //clear.addActionListener(new ButtonListener());
- comboBox= new JComboBox(cList);
- String selectedString = (String) comboBox.getSelectedItem();
- main= new JPanel(new GridLayout(5,1));
- p=null;
- buttonPanel = new JPanel(new GridLayout(2,1));
- buttonPanel.add(undo);
- buttonPanel.add(clear);
- leftPanel= new JPanel();
- leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.Y_AXIS));
- leftPanel.add(main);
- leftPanel.add(buttonPanel);
- leftPanel.add(comboBox);
- canvas = new CanvasPanel();
- canvas.setBackground(Color.white);
- // canvas.addMouseListener(new PointListener());
- //canvas.addMouseMotionListener(new PointListener());
- JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, canvas);
- setLayout(new BorderLayout());
- add(sp);
- }
- //ButtonListener defined actions to take in case
- //"Undo", or "Clear" is chosen.
- private class ButtonListener implements ActionListener
- {
- public void actionPerformed (ActionEvent event)
- {
- //needs to be filled
- /*if(!rectList.isEmpty())
- {
- rectList.remove(rectList.size()-1);
- canvas.repaint();*/
- if (event.getActionCommand().equals("Undo"))
- {
- int size = rectList.size();
- if (size >=1)
- {
- rectList.remove(size-1);
- canvas.repaint();
- }
- }
- else
- {
- if(rectList.size() >=1)
- {
- rectList.clear();
- canvas.repaint();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement