Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Screenshots attached to submission
- // By Mason Marnell
- // Lab13ast.java
- // The Paint Brush Program
- // Student Version
- // The Student version starts with just one color (red) and all that can be drawn is one pixel at a time.
- import java.applet.Applet;
- import java.awt.*;
- import java.util.Random;
- public class PaintProgram extends Applet {
- Rectangle red, blue, pink, green, yellow, black, lightGray, orange, cyan, gray, rand ;
- int numColor, numTool, xClick, yClick;
- Rectangle smallBox, mediumBox, largeBox, smallCirc, largeCirc, vertOval, horOval, splatter, ex, carat ;
- public void init() {
- numColor = 1;
- numTool = 1;
- red = new Rectangle(5, 5, 42, 42);
- blue = new Rectangle(55, 5, 42, 42);
- pink = new Rectangle(105, 5, 42, 42);
- green = new Rectangle(155, 5, 42, 42);
- yellow = new Rectangle(205, 5, 42, 42);
- black = new Rectangle(255, 5, 42, 42);
- lightGray = new Rectangle(305, 5, 42, 42);
- orange = new Rectangle(355, 5, 42, 42);
- cyan = new Rectangle(405, 5, 42, 42);
- gray = new Rectangle(455, 5, 42, 42);
- rand = new Rectangle(505, 5, 42, 42);
- smallBox = new Rectangle(5, 55, 42, 42);
- mediumBox = new Rectangle(5, 105, 42, 42);
- largeBox = new Rectangle(5, 155, 42, 42);
- smallCirc = new Rectangle(5, 205, 42, 42);
- largeCirc = new Rectangle(5, 255, 42, 42);
- vertOval = new Rectangle(5, 305, 42, 42);
- horOval = new Rectangle(5, 355, 42, 42);
- splatter = new Rectangle(5, 405, 42, 42);
- ex = new Rectangle(5, 455, 42, 42);
- carat = new Rectangle(5, 505, 42, 42);
- }
- public void paint(Graphics g) {
- g.setColor(Color.red);
- g.fillRect(5, 5, 42, 42);
- g.setColor(Color.blue);
- g.fillRect(55, 5, 42, 42);
- g.setColor(Color.pink);
- g.fillRect(105, 5, 42, 42);
- g.setColor(Color.green);
- g.fillRect(155, 5, 42, 42);
- g.setColor(Color.yellow);
- g.fillRect(205, 5, 42, 42);
- g.setColor(Color.black);
- g.fillRect(255, 5, 42, 42);
- g.setColor(Color.lightGray);
- g.fillRect(305, 5, 42, 42);
- g.setColor(Color.orange);
- g.fillRect(355, 5, 42, 42);
- g.setColor(Color.cyan);
- g.fillRect(405, 5, 42, 42);
- g.setColor(Color.gray);
- g.fillRect(455, 5, 42, 42);
- int red = (int)(Math.random()*255);
- int green = (int)(Math.random()*255);
- int blue = (int)(Math.random()*255);
- Color rand = new Color(red,green, blue);
- g.setColor(rand);
- g.fillRect(505, 5, 42, 42);
- int rando = red / 20;
- g.setColor(Color.black);
- g.drawRect(5, 55, 42, 42);
- g.drawRect(5, 105, 42, 42);
- g.drawRect(5, 155, 42, 42);
- g.drawOval(5, 205, 30, 30);
- g.drawOval(5, 255, 40, 40);
- g.drawOval(5, 305, 20, 40);
- g.drawOval(5, 355, 40, 20);
- g.drawRect(5, 405, 30, 30); //splatter tool
- g.drawRect(5, 455, 30, 30);
- g.drawString("x", 20, 470);
- g.drawRect(5, 505, 30, 30);
- g.drawString("^",20 ,520);
- switch (numColor) {
- case 1:
- g.setColor(Color.red);
- break;
- case 2:
- g.setColor(Color.blue);
- break;
- case 3:
- g.setColor(Color.pink);
- break;
- case 4:
- g.setColor(Color.green);
- break;
- case 5:
- g.setColor(Color.yellow);
- break;
- case 6:
- g.setColor(Color.black);
- break;
- case 7:
- g.setColor(Color.lightGray);
- break;
- case 8:
- g.setColor(Color.orange);
- break;
- case 9:
- g.setColor(Color.cyan);
- break;
- case 10:
- g.setColor(Color.gray);
- break;
- case 11:
- g.setColor(rand);
- break;
- }
- switch (numTool) {
- case 1:
- g.fillRect(xClick, yClick, 2, 2);
- break;
- case 2:
- g.fillRect(xClick, yClick, 10, 10);
- break;
- case 3:
- g.fillRect(xClick, yClick, 25, 25);
- break;
- case 4:
- g.fillOval(xClick, yClick, 22, 22);
- break;
- case 5:
- g.fillOval(xClick, yClick, 44, 44);
- break;
- case 6:
- g.fillOval(xClick, yClick, 20, 40);
- break;
- case 7:
- g.fillOval(xClick, yClick, 40, 20);
- break;
- case 8:
- for(int i = 0;i < 50; i++){
- g.fillRect(xClick+rando, yClick+rando, 2, 2);
- g.fillRect(xClick-rando, yClick+rando, 2, 2);
- g.fillRect(xClick+rando, yClick-rando, 2, 2);
- g.fillRect(xClick-rando, yClick-rando, 2, 2);
- }
- break;
- case 9:
- g.drawString("x", xClick, yClick);
- break;
- case 10:
- g.drawString("^", xClick, yClick);
- break;
- }
- }
- public boolean mouseDown(Event e, int x, int y) {
- if (red.inside(x, y)) {
- numColor = 1;
- }
- if (blue.inside(x, y)) {
- numColor = 2;
- }
- if (pink.inside(x, y)) {
- numColor = 3;
- }
- if (green.inside(x, y)) {
- numColor = 4;
- }
- if (yellow.inside(x, y)) {
- numColor = 5;
- }
- if (black.inside(x, y)) {
- numColor = 6;
- }
- if (lightGray.inside(x, y)) {
- numColor = 7;
- }
- if (orange.inside(x, y)) {
- numColor = 8;
- }
- if (cyan.inside(x, y)) {
- numColor = 9;
- }
- if (gray.inside(x, y)) {
- numColor = 10;
- }
- if (rand.inside(x, y)) {
- numColor = 11;
- }
- if (smallBox.inside(x, y)) {
- numTool = 1;
- }
- if (mediumBox.inside(x, y)) {
- numTool = 2;
- }
- if (largeBox.inside(x, y)) {
- numTool = 3;
- }
- if (smallCirc.inside(x, y)) {
- numTool = 4;
- }
- if (largeCirc.inside(x, y)) {
- numTool = 5;
- }
- if (vertOval.inside(x, y)) {
- numTool = 6;
- }
- if (horOval.inside(x, y)) {
- numTool = 7;
- }
- if (splatter.inside(x, y)) {
- numTool = 8;
- }
- if (ex.inside(x, y)) {
- numTool = 9;
- }
- if (carat.inside(x, y)) {
- numTool = 10;
- }
- xClick = x;
- yClick = y;
- repaint();
- return true;
- }
- public boolean mouseUp(Event e, int x, int y) {
- return true;
- }
- public boolean mouseDrag(Event e, int x, int y)
- {
- xClick = x;
- yClick = y;
- repaint();
- return true;
- }
- public void update(Graphics g) {
- paint(g);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement