Advertisement
MnMWizard

Paint Project

Nov 25th, 2017
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.39 KB | None | 0 0
  1. //Screenshots attached to submission
  2. // By Mason Marnell
  3.  
  4. // Lab13ast.java
  5. // The Paint Brush Program
  6. // Student Version
  7.  
  8. // The Student version starts with just one color (red) and all that can be drawn is one pixel at a time.
  9.  
  10. import java.applet.Applet;
  11. import java.awt.*;
  12. import java.util.Random;
  13.  
  14. public class PaintProgram extends Applet {
  15.  
  16. Rectangle red, blue, pink, green, yellow, black, lightGray, orange, cyan, gray, rand ;
  17. int numColor, numTool, xClick, yClick;
  18.  
  19. Rectangle smallBox, mediumBox, largeBox, smallCirc, largeCirc, vertOval, horOval, splatter, ex, carat ;
  20.  
  21.  
  22. public void init() {
  23. numColor = 1;
  24. numTool = 1;
  25.  
  26. red = new Rectangle(5, 5, 42, 42);
  27. blue = new Rectangle(55, 5, 42, 42);
  28. pink = new Rectangle(105, 5, 42, 42);
  29. green = new Rectangle(155, 5, 42, 42);
  30. yellow = new Rectangle(205, 5, 42, 42);
  31. black = new Rectangle(255, 5, 42, 42);
  32. lightGray = new Rectangle(305, 5, 42, 42);
  33. orange = new Rectangle(355, 5, 42, 42);
  34. cyan = new Rectangle(405, 5, 42, 42);
  35. gray = new Rectangle(455, 5, 42, 42);
  36. rand = new Rectangle(505, 5, 42, 42);
  37. smallBox = new Rectangle(5, 55, 42, 42);
  38. mediumBox = new Rectangle(5, 105, 42, 42);
  39. largeBox = new Rectangle(5, 155, 42, 42);
  40. smallCirc = new Rectangle(5, 205, 42, 42);
  41. largeCirc = new Rectangle(5, 255, 42, 42);
  42. vertOval = new Rectangle(5, 305, 42, 42);
  43. horOval = new Rectangle(5, 355, 42, 42);
  44. splatter = new Rectangle(5, 405, 42, 42);
  45. ex = new Rectangle(5, 455, 42, 42);
  46. carat = new Rectangle(5, 505, 42, 42);
  47.  
  48.  
  49. }
  50.  
  51. public void paint(Graphics g) {
  52. g.setColor(Color.red);
  53. g.fillRect(5, 5, 42, 42);
  54. g.setColor(Color.blue);
  55. g.fillRect(55, 5, 42, 42);
  56. g.setColor(Color.pink);
  57. g.fillRect(105, 5, 42, 42);
  58. g.setColor(Color.green);
  59. g.fillRect(155, 5, 42, 42);
  60. g.setColor(Color.yellow);
  61. g.fillRect(205, 5, 42, 42);
  62. g.setColor(Color.black);
  63. g.fillRect(255, 5, 42, 42);
  64. g.setColor(Color.lightGray);
  65. g.fillRect(305, 5, 42, 42);
  66. g.setColor(Color.orange);
  67. g.fillRect(355, 5, 42, 42);
  68. g.setColor(Color.cyan);
  69. g.fillRect(405, 5, 42, 42);
  70. g.setColor(Color.gray);
  71. g.fillRect(455, 5, 42, 42);
  72.  
  73. int red = (int)(Math.random()*255);
  74. int green = (int)(Math.random()*255);
  75. int blue = (int)(Math.random()*255);
  76. Color rand = new Color(red,green, blue);
  77. g.setColor(rand);
  78. g.fillRect(505, 5, 42, 42);
  79.  
  80. int rando = red / 20;
  81.  
  82.  
  83. g.setColor(Color.black);
  84. g.drawRect(5, 55, 42, 42);
  85. g.drawRect(5, 105, 42, 42);
  86. g.drawRect(5, 155, 42, 42);
  87. g.drawOval(5, 205, 30, 30);
  88. g.drawOval(5, 255, 40, 40);
  89. g.drawOval(5, 305, 20, 40);
  90. g.drawOval(5, 355, 40, 20);
  91. g.drawRect(5, 405, 30, 30); //splatter tool
  92. g.drawRect(5, 455, 30, 30);
  93. g.drawString("x", 20, 470);
  94. g.drawRect(5, 505, 30, 30);
  95. g.drawString("^",20 ,520);
  96.  
  97. switch (numColor) {
  98. case 1:
  99. g.setColor(Color.red);
  100. break;
  101. case 2:
  102. g.setColor(Color.blue);
  103. break;
  104. case 3:
  105. g.setColor(Color.pink);
  106. break;
  107. case 4:
  108. g.setColor(Color.green);
  109. break;
  110. case 5:
  111. g.setColor(Color.yellow);
  112. break;
  113. case 6:
  114. g.setColor(Color.black);
  115. break;
  116. case 7:
  117. g.setColor(Color.lightGray);
  118. break;
  119. case 8:
  120. g.setColor(Color.orange);
  121. break;
  122. case 9:
  123. g.setColor(Color.cyan);
  124. break;
  125. case 10:
  126. g.setColor(Color.gray);
  127. break;
  128. case 11:
  129. g.setColor(rand);
  130. break;
  131. }
  132.  
  133. switch (numTool) {
  134. case 1:
  135. g.fillRect(xClick, yClick, 2, 2);
  136. break;
  137. case 2:
  138. g.fillRect(xClick, yClick, 10, 10);
  139. break;
  140. case 3:
  141. g.fillRect(xClick, yClick, 25, 25);
  142. break;
  143. case 4:
  144. g.fillOval(xClick, yClick, 22, 22);
  145. break;
  146. case 5:
  147. g.fillOval(xClick, yClick, 44, 44);
  148. break;
  149. case 6:
  150. g.fillOval(xClick, yClick, 20, 40);
  151. break;
  152. case 7:
  153. g.fillOval(xClick, yClick, 40, 20);
  154. break;
  155. case 8:
  156.  
  157. for(int i = 0;i < 50; i++){
  158. g.fillRect(xClick+rando, yClick+rando, 2, 2);
  159. g.fillRect(xClick-rando, yClick+rando, 2, 2);
  160. g.fillRect(xClick+rando, yClick-rando, 2, 2);
  161. g.fillRect(xClick-rando, yClick-rando, 2, 2);
  162. }
  163.  
  164. break;
  165. case 9:
  166. g.drawString("x", xClick, yClick);
  167. break;
  168. case 10:
  169. g.drawString("^", xClick, yClick);
  170. break;
  171.  
  172. }
  173. }
  174.  
  175. public boolean mouseDown(Event e, int x, int y) {
  176. if (red.inside(x, y)) {
  177. numColor = 1;
  178. }
  179. if (blue.inside(x, y)) {
  180. numColor = 2;
  181. }
  182. if (pink.inside(x, y)) {
  183. numColor = 3;
  184. }
  185. if (green.inside(x, y)) {
  186. numColor = 4;
  187. }
  188. if (yellow.inside(x, y)) {
  189. numColor = 5;
  190. }
  191. if (black.inside(x, y)) {
  192. numColor = 6;
  193. }
  194. if (lightGray.inside(x, y)) {
  195. numColor = 7;
  196. }
  197. if (orange.inside(x, y)) {
  198. numColor = 8;
  199. }
  200. if (cyan.inside(x, y)) {
  201. numColor = 9;
  202. }
  203. if (gray.inside(x, y)) {
  204. numColor = 10;
  205. }
  206. if (rand.inside(x, y)) {
  207. numColor = 11;
  208. }
  209.  
  210.  
  211. if (smallBox.inside(x, y)) {
  212. numTool = 1;
  213. }
  214.  
  215. if (mediumBox.inside(x, y)) {
  216. numTool = 2;
  217. }
  218.  
  219. if (largeBox.inside(x, y)) {
  220. numTool = 3;
  221. }
  222. if (smallCirc.inside(x, y)) {
  223. numTool = 4;
  224. }
  225. if (largeCirc.inside(x, y)) {
  226. numTool = 5;
  227. }
  228. if (vertOval.inside(x, y)) {
  229. numTool = 6;
  230. }
  231. if (horOval.inside(x, y)) {
  232. numTool = 7;
  233. }
  234. if (splatter.inside(x, y)) {
  235. numTool = 8;
  236. }
  237. if (ex.inside(x, y)) {
  238. numTool = 9;
  239. }
  240. if (carat.inside(x, y)) {
  241. numTool = 10;
  242. }
  243.  
  244. xClick = x;
  245. yClick = y;
  246. repaint();
  247. return true;
  248. }
  249.  
  250. public boolean mouseUp(Event e, int x, int y) {
  251.  
  252. return true;
  253. }
  254.  
  255. public boolean mouseDrag(Event e, int x, int y)
  256. {
  257. xClick = x;
  258. yClick = y;
  259. repaint();
  260. return true;
  261. }
  262.  
  263. public void update(Graphics g) {
  264. paint(g);
  265. }
  266.  
  267. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement