Advertisement
Guest User

Untitled

a guest
Mar 1st, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. import java.awt.*;
  2. import javax.swing.*;
  3. import java.awt.event.*;
  4. import java.util.ArrayList;
  5. import java.awt.event.ActionListener;
  6. import java.awt.event.ActionEvent;
  7. import javax.swing.JPanel;
  8. import javax.swing.JButton;
  9. import javax.swing.JComboBox; // black, red, blue, green, orange
  10.  
  11.  
  12. public class WholePanel extends JPanel
  13. {
  14. private Color currentColor;
  15. private CanvasPanel canvas;
  16. private JPanel leftPanel, buttonPanel, main;
  17. private JButton undo, clear;
  18. private ArrayList rectList;
  19. private JComboBox comboBox;
  20. private String [] cList= {"black", "red", "blue", "green", "orange"};
  21. Point p;
  22.  
  23. public class Rectangle
  24. {
  25. private int x1;
  26. private int y1;
  27. private int width;
  28. private int height;
  29. private Color color;
  30.  
  31.  
  32. }
  33. public void Rectangle(int x1, int y1, int width1, int height1, Color color)
  34. {
  35. x1=0;
  36. y1=0;
  37. width1 = 0;
  38. height1 = 0;
  39. color = new Color(height1);
  40.  
  41. }
  42.  
  43. public void draw(Graphics page){
  44. }
  45. public void fillRect(int x1, int y1, int hieght1, int width1){
  46.  
  47. }
  48. public void drawLine(int x1, int y1, int x2, int y2){
  49.  
  50. }
  51.  
  52. public WholePanel()
  53. {
  54. //default color to draw is black
  55. currentColor = Color.BLACK;
  56. rectList = new ArrayList();
  57.  
  58. undo = new JButton ("Undo");
  59. clear = new JButton("Clear");
  60. // undo.addActionListener(new ButtonListener());
  61. //clear.addActionListener(new ButtonListener());
  62.  
  63. comboBox= new JComboBox(cList);
  64. String selectedString = (String) comboBox.getSelectedItem();
  65.  
  66. main= new JPanel(new GridLayout(5,1));
  67. p=null;
  68.  
  69. buttonPanel = new JPanel(new GridLayout(2,1));
  70. buttonPanel.add(undo);
  71. buttonPanel.add(clear);
  72.  
  73. leftPanel= new JPanel();
  74. leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.Y_AXIS));
  75. leftPanel.add(main);
  76. leftPanel.add(buttonPanel);
  77. leftPanel.add(comboBox);
  78.  
  79. canvas = new CanvasPanel();
  80. canvas.setBackground(Color.white);
  81. // canvas.addMouseListener(new PointListener());
  82. //canvas.addMouseMotionListener(new PointListener());
  83.  
  84. JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, canvas);
  85.  
  86. setLayout(new BorderLayout());
  87. add(sp);
  88.  
  89. }
  90.  
  91.  
  92. //ButtonListener defined actions to take in case
  93. //"Undo", or "Clear" is chosen.
  94. private class ButtonListener implements ActionListener
  95. {
  96. public void actionPerformed (ActionEvent event)
  97. {
  98.  
  99. //needs to be filled
  100. /*if(!rectList.isEmpty())
  101. {
  102. rectList.remove(rectList.size()-1);
  103. canvas.repaint();*/
  104.  
  105.  
  106. if (event.getActionCommand().equals("Undo"))
  107. {
  108. int size = rectList.size();
  109. if (size >=1)
  110. {
  111. rectList.remove(size-1);
  112. canvas.repaint();
  113. }
  114. }
  115. else
  116. {
  117. if(rectList.size() >=1)
  118. {
  119. rectList.clear();
  120. canvas.repaint();
  121. }
  122. }
  123. }
  124.  
  125. }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement