diff --git a/Picture/Picture.java b/Picture/Picture.java index c5c557a..1658f1d 100644 --- a/Picture/Picture.java +++ b/Picture/Picture.java @@ -10,13 +10,32 @@ * @author Michael Kölling and David J. Barnes * @version 1.1 (24 May 2001) */ + + + public class Picture { - private Square wall; + private Square house; + private Square garage; + private Square garageDoor; + private Square door; + private Square frontDoor; private Square window; + private Square window1; + private Square window2; + private Square grass; private Triangle roof; + private Triangle garageRoof; + private Triangle tree; + private Triangle tree1; private Circle sun; + private Circle doorKnob; + private Circle bush; + private Circle bush1; + + + /** * Constructor for objects of class Picture */ @@ -30,57 +49,159 @@ public Picture() */ public void draw() { - wall = new Square(); - wall.moveVertical(80); - wall.changeSize(100); - wall.makeVisible(); + - window = new Square(); - window.changeColor("black"); - window.moveHorizontal(20); - window.moveVertical(100); - window.makeVisible(); + house = new Square(); + house.changeColor("blue"); + house.moveVertical(50); + house.moveHorizontal(-5); + house.changeSize(130); + house.makeVisible(); + + + + garage = new Square(); + garage.changeColor("blue"); + garage.moveVertical(90); + garage.moveHorizontal(80); + garage.changeSize(120); + garage.makeVisible(); + + + garageDoor = new Square(); + garageDoor.changeColor("black"); + garageDoor.moveVertical(100); + garageDoor.moveHorizontal(120); + garageDoor.changeSize(70); + garageDoor.makeVisible(); + + + + door = new Square(); + door.changeColor("black"); + door.moveVertical(140); + door.moveHorizontal(35); + door.makeVisible(); + + frontDoor = new Square(); + frontDoor.changeColor("black"); + frontDoor.moveVertical(130); + frontDoor.moveHorizontal(35); + frontDoor.makeVisible(); + + + + window = new Square(); + window.changeColor("black"); + window.moveVertical(60); + window.moveHorizontal(0); + window.makeVisible(); + + + + window1 = new Square(); + window1.changeColor("black"); + window1.moveVertical(60); + window1.moveHorizontal(40); + window1.makeVisible(); + + + + window2 = new Square(); + window2.changeColor("black"); + window2.moveVertical(60); + window2.moveHorizontal(90); + window2.makeVisible(); + + + + grass = new Square(); + grass.changeColor("green"); + grass.moveVertical(170); + grass.moveHorizontal(-60); + grass.changeSize(300); + grass.makeVisible(); + + + + roof = new Triangle(); + roof.changeColor("red"); + roof.moveVertical(5); + roof.moveHorizontal(70); + roof.changeSize(80,130); + roof.makeVisible(); + + + + garageRoof = new Triangle(); + garageRoof.changeColor("red"); + garageRoof.moveVertical(65); + garageRoof.moveHorizontal(170); + garageRoof.changeSize(60,80); + garageRoof.makeVisible(); + + + + tree = new Triangle(); + tree.changeColor("green"); + tree.moveVertical(80); + tree.moveHorizontal(-20); + tree.changeSize(130,30); + tree.makeVisible(); + + + + tree1 = new Triangle(); + tree1.changeColor("green"); + tree1.moveVertical(80); + tree1.moveHorizontal(230); + tree1.changeSize(130,30); + tree1.makeVisible(); + + + + sun = new Circle(); + sun.changeColor("yellow"); + sun.moveVertical(-60); + sun.moveHorizontal(-20); + sun.changeSize(80); + sun.makeVisible(); + + + + + doorKnob = new Circle(); + doorKnob.changeColor("magenta"); + doorKnob.moveVertical(140); + doorKnob.moveHorizontal(98); + doorKnob.changeSize(5); + doorKnob.makeVisible(); + + + + bush = new Circle(); + bush.changeColor("green"); + bush.moveVertical(140); + bush.moveHorizontal(40); + bush.changeSize(30); + bush.makeVisible(); + + + bush1 = new Circle(); + bush1.changeColor("green"); + bush1.moveVertical(140); + bush1.moveHorizontal(115); + bush1.changeSize(30); + bush1.makeVisible(); + + + - roof = new Triangle(); - roof.changeSize(50, 140); - roof.moveHorizontal(60); - roof.moveVertical(70); - roof.makeVisible(); - - sun = new Circle(); - sun.changeColor("yellow"); - sun.moveHorizontal(180); - sun.moveVertical(-10); - sun.changeSize(60); - sun.makeVisible(); + } - /** - * Change this picture to black/white display - */ - public void setBlackAndWhite() - { - if(wall != null) // only if it's painted already... - { - wall.changeColor("black"); - window.changeColor("white"); - roof.changeColor("black"); - sun.changeColor("black"); - } - } + - /** - * Change this picture to use color display - */ - public void setColor() - { - if(wall != null) // only if it's painted already... - { - wall.changeColor("red"); - window.changeColor("black"); - roof.changeColor("green"); - sun.changeColor("yellow"); - } - } + } diff --git a/Picture/package.bluej b/Picture/package.bluej index 4a5eed1..29bf213 100644 --- a/Picture/package.bluej +++ b/Picture/package.bluej @@ -2,37 +2,37 @@ dependency1.from=Circle dependency1.to=Canvas dependency1.type=UsesDependency -dependency2.from=Picture -dependency2.to=Square +dependency2.from=Triangle +dependency2.to=Canvas dependency2.type=UsesDependency -dependency3.from=Picture -dependency3.to=Triangle +dependency3.from=Square +dependency3.to=Canvas dependency3.type=UsesDependency -dependency4.from=Picture -dependency4.to=Circle +dependency4.from=PictureTest +dependency4.to=Picture dependency4.type=UsesDependency -dependency5.from=Triangle -dependency5.to=Canvas +dependency5.from=Picture +dependency5.to=Square dependency5.type=UsesDependency -dependency6.from=Square -dependency6.to=Canvas +dependency6.from=Picture +dependency6.to=Triangle dependency6.type=UsesDependency -dependency7.from=PictureTest -dependency7.to=Picture +dependency7.from=Picture +dependency7.to=Circle dependency7.type=UsesDependency -editor.fx.0.height=722 +editor.fx.0.height=721 editor.fx.0.width=800 -editor.fx.0.x=2086 -editor.fx.0.y=284 -objectbench.height=101 -objectbench.width=461 +editor.fx.0.x=240 +editor.fx.0.y=23 +objectbench.height=201 +objectbench.width=776 package.divider.horizontal=0.6 -package.divider.vertical=0.8007380073800738 -package.editor.height=427 -package.editor.width=674 -package.editor.x=239 -package.editor.y=118 -package.frame.height=600 +package.divider.vertical=0.5398230088495575 +package.editor.height=237 +package.editor.width=666 +package.editor.x=9 +package.editor.y=46 +package.frame.height=510 package.frame.width=800 package.numDependencies=7 package.numTargets=6 @@ -49,7 +49,7 @@ target1.name=Circle target1.showInterface=false target1.type=ClassTarget target1.width=80 -target1.x=110 +target1.x=100 target1.y=120 target2.association=PictureTest target2.height=40 diff --git a/Shapes/package.bluej b/Shapes/package.bluej index 5e6c247..4f5a01c 100644 --- a/Shapes/package.bluej +++ b/Shapes/package.bluej @@ -12,16 +12,16 @@ editor.fx.0.height=0 editor.fx.0.width=0 editor.fx.0.x=0 editor.fx.0.y=0 -objectbench.height=160 -objectbench.width=769 +objectbench.height=191 +objectbench.width=892 package.divider.horizontal=0.5996908809891809 -package.divider.vertical=0.7822685788787483 -package.editor.height=593 -package.editor.width=1188 -package.editor.x=246 -package.editor.y=192 -package.frame.height=825 -package.frame.width=1314 +package.divider.vertical=0.7009063444108762 +package.editor.height=457 +package.editor.width=814 +package.editor.x=348 +package.editor.y=23 +package.frame.height=720 +package.frame.width=932 package.numDependencies=3 package.numTargets=4 package.showExtends=true diff --git a/houseDrawing/Canvas.java b/houseDrawing/Canvas.java new file mode 100644 index 0000000..775ec7e --- /dev/null +++ b/houseDrawing/Canvas.java @@ -0,0 +1,221 @@ +import javax.swing.*; +import java.awt.*; +import java.util.List; +import java.util.*; + +/** + * Canvas is a class to allow for simple graphical drawing on a canvas. + * This is a modification of the general purpose Canvas, specially made for + * the BlueJ "shapes" example. + * + * @author: Bruce Quig + * @author: Michael Kölling (mik) + * + * @version: 1.6 (shapes) + */ +public class Canvas +{ + // Note: The implementation of this class (specifically the handling of + // shape identity and colors) is slightly more complex than necessary. This + // is done on purpose to keep the interface and instance fields of the + // shape objects in this project clean and simple for educational purposes. + + private static Canvas canvasSingleton; + + /** + * Factory method to get the canvas singleton object. + */ + public static Canvas getCanvas() + { + if(canvasSingleton == null) { + canvasSingleton = new Canvas("BlueJ Shapes Demo", 300, 300, + Color.white); + } + canvasSingleton.setVisible(true); + return canvasSingleton; + } + + // ----- instance part ----- + + private JFrame frame; + private CanvasPane canvas; + private Graphics2D graphic; + private Color backgroundColour; + private Image canvasImage; + private List objects; + private HashMap shapes; + + /** + * Create a Canvas. + * @param title title to appear in Canvas Frame + * @param width the desired width for the canvas + * @param height the desired height for the canvas + * @param bgClour the desired background colour of the canvas + */ + private Canvas(String title, int width, int height, Color bgColour) + { + frame = new JFrame(); + canvas = new CanvasPane(); + frame.setContentPane(canvas); + frame.setTitle(title); + canvas.setPreferredSize(new Dimension(width, height)); + backgroundColour = bgColour; + frame.pack(); + objects = new ArrayList(); + shapes = new HashMap(); + } + + /** + * Set the canvas visibility and brings canvas to the front of screen + * when made visible. This method can also be used to bring an already + * visible canvas to the front of other windows. + * @param visible boolean value representing the desired visibility of + * the canvas (true or false) + */ + public void setVisible(boolean visible) + { + if(graphic == null) { + // first time: instantiate the offscreen image and fill it with + // the background colour + Dimension size = canvas.getSize(); + canvasImage = canvas.createImage(size.width, size.height); + graphic = (Graphics2D)canvasImage.getGraphics(); + graphic.setColor(backgroundColour); + graphic.fillRect(0, 0, size.width, size.height); + graphic.setColor(Color.black); + } + frame.setVisible(visible); + } + + /** + * Draw a given shape onto the canvas. + * @param referenceObject an object to define identity for this shape + * @param color the color of the shape + * @param shape the shape object to be drawn on the canvas + */ + // Note: this is a slightly backwards way of maintaining the shape + // objects. It is carefully designed to keep the visible shape interfaces + // in this project clean and simple for educational purposes. + public void draw(Object referenceObject, String color, Shape shape) + { + objects.remove(referenceObject); // just in case it was already there + objects.add(referenceObject); // add at the end + shapes.put(referenceObject, new ShapeDescription(shape, color)); + redraw(); + } + + /** + * Erase a given shape's from the screen. + * @param referenceObject the shape object to be erased + */ + public void erase(Object referenceObject) + { + objects.remove(referenceObject); // just in case it was already there + shapes.remove(referenceObject); + redraw(); + } + + /** + * Set the foreground colour of the Canvas. + * @param newColour the new colour for the foreground of the Canvas + */ + public void setForegroundColor(String colorString) + { + if(colorString.equals("red")) + graphic.setColor(Color.red); + else if(colorString.equals("black")) + graphic.setColor(Color.black); + else if(colorString.equals("blue")) + graphic.setColor(Color.blue); + else if(colorString.equals("yellow")) + graphic.setColor(Color.yellow); + else if(colorString.equals("green")) + graphic.setColor(Color.green); + else if(colorString.equals("magenta")) + graphic.setColor(Color.magenta); + else if(colorString.equals("white")) + graphic.setColor(Color.white); + else + graphic.setColor(Color.black); + } + + /** + * Wait for a specified number of milliseconds before finishing. + * This provides an easy way to specify a small delay which can be + * used when producing animations. + * @param milliseconds the number + */ + public void wait(int milliseconds) + { + try + { + Thread.sleep(milliseconds); + } + catch (Exception e) + { + // ignoring exception at the moment + } + } + + /** + * Redraw ell shapes currently on the Canvas. + */ + private void redraw() + { + erase(); + for(Iterator i=objects.iterator(); i.hasNext(); ) { + ((ShapeDescription)shapes.get(i.next())).draw(graphic); + } + canvas.repaint(); + } + + /** + * Erase the whole canvas. (Does not repaint.) + */ + private void erase() + { + Color original = graphic.getColor(); + graphic.setColor(backgroundColour); + Dimension size = canvas.getSize(); + graphic.fill(new Rectangle(0, 0, size.width, size.height)); + graphic.setColor(original); + } + + + /************************************************************************ + * Inner class CanvasPane - the actual canvas component contained in the + * Canvas frame. This is essentially a JPanel with added capability to + * refresh the image drawn on it. + */ + private class CanvasPane extends JPanel + { + public void paint(Graphics g) + { + g.drawImage(canvasImage, 0, 0, null); + } + } + + /************************************************************************ + * Inner class CanvasPane - the actual canvas component contained in the + * Canvas frame. This is essentially a JPanel with added capability to + * refresh the image drawn on it. + */ + private class ShapeDescription + { + private Shape shape; + private String colorString; + + public ShapeDescription(Shape shape, String color) + { + this.shape = shape; + colorString = color; + } + + public void draw(Graphics2D graphic) + { + setForegroundColor(colorString); + graphic.fill(shape); + } + } + +} diff --git a/houseDrawing/Circle.java b/houseDrawing/Circle.java new file mode 100644 index 0000000..3e74bec --- /dev/null +++ b/houseDrawing/Circle.java @@ -0,0 +1,192 @@ +import java.awt.*; +import java.awt.geom.*; + +/** + * A circle that can be manipulated and that draws itself on a canvas. + * + * @author Michael Kölling and David J. Barnes + * @version 1.0 (15 July 2000) + */ + +public class Circle +{ + private int diameter; + private int xPosition; + private int yPosition; + private String color; + private boolean isVisible; + + /** + * Create a new circle at default position with default color. + */ + public Circle() + { + diameter = 30; + xPosition = 20; + yPosition = 60; + color = "blue"; + isVisible = false; + } + + /** + * Make this circle visible. If it was already visible, do nothing. + */ + public void makeVisible() + { + isVisible = true; + draw(); + } + + /** + * Make this circle invisible. If it was already invisible, do nothing. + */ + public void makeInvisible() + { + erase(); + isVisible = false; + } + + /** + * Move the circle a few pixels to the right. + */ + public void moveRight() + { + moveHorizontal(20); + } + + /** + * Move the circle a few pixels to the left. + */ + public void moveLeft() + { + moveHorizontal(-20); + } + + /** + * Move the circle a few pixels up. + */ + public void moveUp() + { + moveVertical(-20); + } + + /** + * Move the circle a few pixels down. + */ + public void moveDown() + { + moveVertical(20); + } + + /** + * Move the circle horizontally by 'distance' pixels. + */ + public void moveHorizontal(int distance) + { + erase(); + xPosition += distance; + draw(); + } + + /** + * Move the circle vertically by 'distance' pixels. + */ + public void moveVertical(int distance) + { + erase(); + yPosition += distance; + draw(); + } + + /** + * Slowly move the circle horizontally by 'distance' pixels. + */ + public void slowMoveHorizontal(int distance) + { + int delta; + + if(distance < 0) + { + delta = -1; + distance = -distance; + } + else + { + delta = 1; + } + + for(int i = 0; i < distance; i++) + { + xPosition += delta; + draw(); + } + } + + /** + * Slowly move the circle vertically by 'distance' pixels. + */ + public void slowMoveVertical(int distance) + { + int delta; + + if(distance < 0) + { + delta = -1; + distance = -distance; + } + else + { + delta = 1; + } + + for(int i = 0; i < distance; i++) + { + yPosition += delta; + draw(); + } + } + + /** + * Change the size to the new size (in pixels). Size must be >= 0. + */ + public void changeSize(int newDiameter) + { + erase(); + diameter = newDiameter; + draw(); + } + + /** + * Change the color. Valid colors are "red", "yellow", "blue", "green", + * "magenta" and "black". + */ + public void changeColor(String newColor) + { + color = newColor; + draw(); + } + + /* + * Draw the circle with current specifications on screen. + */ + private void draw() + { + if(isVisible) { + Canvas canvas = Canvas.getCanvas(); + canvas.draw(this, color, new Ellipse2D.Double(xPosition, yPosition, + diameter, diameter)); + canvas.wait(10); + } + } + + /* + * Erase the circle on screen. + */ + private void erase() + { + if(isVisible) { + Canvas canvas = Canvas.getCanvas(); + canvas.erase(this); + } + } +} diff --git a/houseDrawing/README.TXT b/houseDrawing/README.TXT new file mode 100644 index 0000000..fccb868 --- /dev/null +++ b/houseDrawing/README.TXT @@ -0,0 +1,44 @@ +Project "shapes" +Authors: Michael Kölling and David J. Barnes + +This project is part of the material for the book + + Objects First with Java - A Practical Introduction using BlueJ + David J. Barnes and Michael Kolling + Pearson Education, 2002 + +It is discussed in chapter 1. + +This is a very simple project to demonstrate some characteristics of +objects. + +You can create various shapes, and you will see, if you do, that those +shapes are drawn on screen (in a window that we call the "canvas"). + +You can then manipulate these objects: change their position, size and +colour. Try it out: create a few different squares, triangles and circles. + +This project is designed as a first example of object-oriented programming. +It illustrates a number of concepts: + + - a Java project (application) is a collection of classes + - objects can be created from classes + - from any one class, many objects may be created + - objects have operations (methods) + - operations can have parameters + - parameters have types (at least String and int) + - objects hold data (fields) + - the operations and fields are common to all objects + - the values stored in the fields can be different for each object + +The project also demonstrates + + - BlueJ object creation + - interactive method invocation + - parameter passing + +A good second project to look at after this is "picture", which adds a class +to those ones in this project. That class (named "Picture") uses the shapes +to draw a picture. It can be used to experiment with coding. + +Michael Kölling, July 2000 \ No newline at end of file diff --git a/houseDrawing/Square.java b/houseDrawing/Square.java new file mode 100644 index 0000000..d899122 --- /dev/null +++ b/houseDrawing/Square.java @@ -0,0 +1,192 @@ +import java.awt.*; + +/** + * A square that can be manipulated and that draws itself on a canvas. + * + * @author Michael Kölling and David J. Barnes + * @version 1.0 (15 July 2000) + */ + + +public class Square +{ + private int size; + private int xPosition; + private int yPosition; + private String color; + private boolean isVisible; + + /** + * Create a new square at default position with default color. + */ + public Square() + { + size = 30; + xPosition = 60; + yPosition = 50; + color = "red"; + isVisible = false; + } + + /** + * Make this square visible. If it was already visible, do nothing. + */ + public void makeVisible() + { + isVisible = true; + draw(); + } + + /** + * Make this square invisible. If it was already invisible, do nothing. + */ + public void makeInvisible() + { + erase(); + isVisible = false; + } + + /** + * Move the square a few pixels to the right. + */ + public void moveRight() + { + moveHorizontal(20); + } + + /** + * Move the square a few pixels to the left. + */ + public void moveLeft() + { + moveHorizontal(-20); + } + + /** + * Move the square a few pixels up. + */ + public void moveUp() + { + moveVertical(-20); + } + + /** + * Move the square a few pixels down. + */ + public void moveDown() + { + moveVertical(20); + } + + /** + * Move the square horizontally by 'distance' pixels. + */ + public void moveHorizontal(int distance) + { + erase(); + xPosition += distance; + draw(); + } + + /** + * Move the square vertically by 'distance' pixels. + */ + public void moveVertical(int distance) + { + erase(); + yPosition += distance; + draw(); + } + + /** + * Slowly move the square horizontally by 'distance' pixels. + */ + public void slowMoveHorizontal(int distance) + { + int delta; + + if(distance < 0) + { + delta = -1; + distance = -distance; + } + else + { + delta = 1; + } + + for(int i = 0; i < distance; i++) + { + xPosition += delta; + draw(); + } + } + + /** + * Slowly move the square vertically by 'distance' pixels. + */ + public void slowMoveVertical(int distance) + { + int delta; + + if(distance < 0) + { + delta = -1; + distance = -distance; + } + else + { + delta = 1; + } + + for(int i = 0; i < distance; i++) + { + yPosition += delta; + draw(); + } + } + + /** + * Change the size to the new size (in pixels). Size must be >= 0. + */ + public void changeSize(int newSize) + { + erase(); + size = newSize; + draw(); + } + + /** + * Change the color. Valid colors are "red", "yellow", "blue", "green", + * "magenta" and "black". + */ + public void changeColor(String newColor) + { + color = newColor; + draw(); + } + + /* + * Draw the square with current specifications on screen. + */ + private void draw() + { + if(isVisible) { + Canvas canvas = Canvas.getCanvas(); + canvas.draw(this, color, + new Rectangle(xPosition, yPosition, size, size)); + canvas.wait(10); + } + } + + /* + * Erase the square on screen. + */ + private void erase() + { + if(isVisible) { + Canvas canvas = Canvas.getCanvas(); + canvas.erase(this); + } + } +} diff --git a/houseDrawing/Triangle.java b/houseDrawing/Triangle.java new file mode 100644 index 0000000..0d7c805 --- /dev/null +++ b/houseDrawing/Triangle.java @@ -0,0 +1,195 @@ +import java.awt.*; + +/** + * A triangle that can be manipulated and that draws itself on a canvas. + * + * @author Michael Kölling and David J. Barnes + * @version 1.0 (15 July 2000) + */ + +public class Triangle +{ + private int height; + private int width; + private int xPosition; + private int yPosition; + private String color; + private boolean isVisible; + + /** + * Create a new triangle at default position with default color. + */ + public Triangle() + { + height = 30; + width = 40; + xPosition = 50; + yPosition = 15; + color = "green"; + isVisible = false; + } + + /** + * Make this triangle visible. If it was already visible, do nothing. + */ + public void makeVisible() + { + isVisible = true; + draw(); + } + + /** + * Make this triangle invisible. If it was already invisible, do nothing. + */ + public void makeInvisible() + { + erase(); + isVisible = false; + } + + /** + * Move the triangle a few pixels to the right. + */ + public void moveRight() + { + moveHorizontal(20); + } + + /** + * Move the triangle a few pixels to the left. + */ + public void moveLeft() + { + moveHorizontal(-20); + } + + /** + * Move the triangle a few pixels up. + */ + public void moveUp() + { + moveVertical(-20); + } + + /** + * Move the triangle a few pixels down. + */ + public void moveDown() + { + moveVertical(20); + } + + /** + * Move the triangle horizontally by 'distance' pixels. + */ + public void moveHorizontal(int distance) + { + erase(); + xPosition += distance; + draw(); + } + + /** + * Move the triangle vertically by 'distance' pixels. + */ + public void moveVertical(int distance) + { + erase(); + yPosition += distance; + draw(); + } + + /** + * Slowly move the triangle horizontally by 'distance' pixels. + */ + public void slowMoveHorizontal(int distance) + { + int delta; + + if(distance < 0) + { + delta = -1; + distance = -distance; + } + else + { + delta = 1; + } + + for(int i = 0; i < distance; i++) + { + xPosition += delta; + draw(); + } + } + + /** + * Slowly move the triangle vertically by 'distance' pixels. + */ + public void slowMoveVertical(int distance) + { + int delta; + + if(distance < 0) + { + delta = -1; + distance = -distance; + } + else + { + delta = 1; + } + + for(int i = 0; i < distance; i++) + { + yPosition += delta; + draw(); + } + } + + /** + * Change the size to the new size (in pixels). Size must be >= 0. + */ + public void changeSize(int newHeight, int newWidth) + { + erase(); + height = newHeight; + width = newWidth; + draw(); + } + + /** + * Change the color. Valid colors are "red", "yellow", "blue", "green", + * "magenta" and "black". + */ + public void changeColor(String newColor) + { + color = newColor; + draw(); + } + + /* + * Draw the triangle with current specifications on screen. + */ + private void draw() + { + if(isVisible) { + Canvas canvas = Canvas.getCanvas(); + int[] xpoints = { xPosition, xPosition + (width/2), xPosition - (width/2) }; + int[] ypoints = { yPosition, yPosition + height, yPosition + height }; + canvas.draw(this, color, new Polygon(xpoints, ypoints, 3)); + canvas.wait(10); + } + } + + /* + * Erase the triangle on screen. + */ + private void erase() + { + if(isVisible) { + Canvas canvas = Canvas.getCanvas(); + canvas.erase(this); + } + } +} diff --git a/houseDrawing/package.bluej b/houseDrawing/package.bluej new file mode 100644 index 0000000..d70493a --- /dev/null +++ b/houseDrawing/package.bluej @@ -0,0 +1,62 @@ +#BlueJ package file +dependency1.from=Circle +dependency1.to=Canvas +dependency1.type=UsesDependency +dependency2.from=Triangle +dependency2.to=Canvas +dependency2.type=UsesDependency +dependency3.from=Square +dependency3.to=Canvas +dependency3.type=UsesDependency +editor.fx.0.height=0 +editor.fx.0.width=0 +editor.fx.0.x=0 +editor.fx.0.y=0 +objectbench.height=192 +objectbench.width=908 +package.divider.horizontal=0.5996908809891809 +package.divider.vertical=0.6993957703927492 +package.editor.height=456 +package.editor.width=814 +package.editor.x=6 +package.editor.y=23 +package.frame.height=720 +package.frame.width=932 +package.numDependencies=3 +package.numTargets=4 +package.showExtends=true +package.showUses=true +project.charset=UTF-8 +readme.height=58 +readme.name=@README +readme.width=47 +readme.x=10 +readme.y=10 +target1.height=40 +target1.name=Circle +target1.showInterface=false +target1.type=ClassTarget +target1.width=80 +target1.x=110 +target1.y=120 +target2.height=100 +target2.name=Canvas +target2.showInterface=false +target2.type=ClassTarget +target2.width=80 +target2.x=20 +target2.y=180 +target3.height=40 +target3.name=Triangle +target3.showInterface=false +target3.type=ClassTarget +target3.width=80 +target3.x=350 +target3.y=60 +target4.height=40 +target4.name=Square +target4.showInterface=false +target4.type=ClassTarget +target4.width=100 +target4.x=230 +target4.y=90