diff --git a/Lab1App.class b/Lab1App.class new file mode 100644 index 0000000..09fbf06 Binary files /dev/null and b/Lab1App.class differ diff --git a/Lab1App.ctxt b/Lab1App.ctxt new file mode 100644 index 0000000..4c6daca --- /dev/null +++ b/Lab1App.ctxt @@ -0,0 +1,7 @@ +#BlueJ class context +comment0.target=Lab1App +comment1.params=title +comment1.target=Lab1App(java.lang.String) +comment2.params=args +comment2.target=void\ main(java.lang.String[]) +numComments=3 diff --git a/Lab1App.java b/Lab1App.java new file mode 100644 index 0000000..2eb0c76 --- /dev/null +++ b/Lab1App.java @@ -0,0 +1,17 @@ +import javax.swing.*; +import java.awt.*; + +public class Lab1App extends JFrame{ + + public Lab1App(String title){ + super(title); + this.setSize(1024, 768); + this.setDefaultCloseOperation(EXIT_ON_CLOSE); + this.add(new ShapesPanel()); + this.setVisible(true); + } + + public static void main (String[] args){ + Lab1App app = new Lab1App("Lab 1 Solution"); + } +} diff --git a/README.TXT b/README.TXT new file mode 100644 index 0000000..2bea2dd --- /dev/null +++ b/README.TXT @@ -0,0 +1,12 @@ +------------------------------------------------------------------------ +This is the project README file. Here, you should describe your project. +Tell the reader (someone who does not know anything about this project) +all he/she needs to know. The comments should usually include at least: +------------------------------------------------------------------------ + +PROJECT TITLE: +PURPOSE OF PROJECT: +VERSION or DATE: +HOW TO START THIS PROJECT: +AUTHORS: +USER INSTRUCTIONS: diff --git a/ShapesPanel.class b/ShapesPanel.class new file mode 100644 index 0000000..dfae3c1 Binary files /dev/null and b/ShapesPanel.class differ diff --git a/ShapesPanel.ctxt b/ShapesPanel.ctxt new file mode 100644 index 0000000..6671750 --- /dev/null +++ b/ShapesPanel.ctxt @@ -0,0 +1,7 @@ +#BlueJ class context +comment0.target=ShapesPanel +comment1.params= +comment1.target=ShapesPanel() +comment2.params=aBrush +comment2.target=void\ paintComponent(java.awt.Graphics) +numComments=3 diff --git a/ShapesPanel.java b/ShapesPanel.java new file mode 100644 index 0000000..94f8cda --- /dev/null +++ b/ShapesPanel.java @@ -0,0 +1,53 @@ +import javax.swing.*; +import java.awt.*; + + +public class ShapesPanel extends JPanel{ + private SmartEllipse _ellipse; + private SmartRectangle _rectangle; + private SmartRectangle _diamond; + private Polygon _triangle; + private SmartRectangle _star1; + private SmartRectangle _star2; + + public ShapesPanel(){ + _ellipse = new SmartEllipse(java.awt.Color.BLUE); + _ellipse.setLocation(200,200); + _ellipse.setSize(50,50); + + _rectangle = new SmartRectangle(java.awt.Color.RED); + _rectangle.setLocation(300,250); + _rectangle.setSize(70,100); + + _diamond = new SmartRectangle(java.awt.Color.GREEN); + _diamond.setLocation(86, 75); + _diamond.setSize(30,30); + _diamond.setRotation(150); + + _star1 = new SmartRectangle(java.awt.Color.GRAY); + _star1.setLocation(500,100); + _star1.setSize(60,60); + _star1.setRotation(150); + + _star2 = new SmartRectangle(java.awt.Color.GRAY); + _star2.setLocation(500,100); + _star2.setSize(60,60); + + + + } + public void paintComponent(java.awt.Graphics aBrush) { + super.paintComponent(aBrush); + java.awt.Graphics2D aBetterBrush = (java.awt.Graphics2D) aBrush; + _ellipse.fill(aBetterBrush); + _rectangle.fill(aBetterBrush); + _diamond.fill(aBetterBrush); + _star1.fill(aBetterBrush); + _star2.fill(aBetterBrush); + int[] tr1 = {10, 20, 30}; + int[] tr2 = {60, 50, 60}; + _triangle = new Polygon(tr1, tr2, 3); + aBrush.setColor(Color.yellow); + aBrush.fillPolygon(_triangle); + } +} diff --git a/SmartEllipse.class b/SmartEllipse.class new file mode 100644 index 0000000..bb5f6e3 Binary files /dev/null and b/SmartEllipse.class differ diff --git a/SmartEllipse.ctxt b/SmartEllipse.ctxt new file mode 100644 index 0000000..f24a2a7 --- /dev/null +++ b/SmartEllipse.ctxt @@ -0,0 +1,22 @@ +#BlueJ class context +comment0.target=SmartEllipse +comment0.text=\r\n\ Chapter\ 9\:\ SmartEllipse.java\r\n\ Adds\ capabilities\ to\ the\ Java2D.Double\ ellipse.\r\n\ Same\ as\ the\ class\ defined\ in\ Chapter\ 7.\r\n +comment1.params=aColor +comment1.target=SmartEllipse(java.awt.Color) +comment2.params=aColor +comment2.target=void\ setBorderColor(java.awt.Color) +comment3.params=aColor +comment3.target=void\ setFillColor(java.awt.Color) +comment4.params=aColor +comment4.target=void\ setColor(java.awt.Color) +comment5.params=aRotation +comment5.target=void\ setRotation(double) +comment6.params=x\ y +comment6.target=void\ setLocation(double,\ double) +comment7.params=aWidth\ aHeight +comment7.target=void\ setSize(int,\ int) +comment8.params=aBrush +comment8.target=void\ fill(java.awt.Graphics2D) +comment9.params=aBrush +comment9.target=void\ draw(java.awt.Graphics2D) +numComments=10 diff --git a/SmartEllipse.java b/SmartEllipse.java new file mode 100644 index 0000000..4b198b9 --- /dev/null +++ b/SmartEllipse.java @@ -0,0 +1,60 @@ +/** + * Chapter 9: SmartEllipse.java + * Adds capabilities to the Java2D.Double ellipse. + * Same as the class defined in Chapter 7. + */ +public class SmartEllipse extends java.awt.geom.Ellipse2D.Double { + private java.awt.Color _borderColor, _fillColor; + private double _rotation; + private final int STROKE_WIDTH = 2; + + public SmartEllipse(java.awt.Color aColor){ + _borderColor = aColor; + _fillColor = aColor; // solid color to start + _rotation = 0; + } + + // methods not provided by Java + public void setBorderColor (java.awt.Color aColor) { + _borderColor = aColor; + } + public void setFillColor (java.awt.Color aColor) { + _fillColor = aColor; + } + public void setColor (java.awt.Color aColor) { + _borderColor = aColor; + _fillColor = aColor; + } + public void setRotation (double aRotation) { + _rotation = aRotation; + } + + // more readable versions of methods provided by Java + public void setLocation (double x, double y) { + this.setFrame (x, y, this.getWidth(), this.getHeight()); + } + public void setSize (int aWidth, int aHeight) { + this.setFrame(this.getX(), this.getY(), aWidth, aHeight); + } + + // not provided by Java + public void fill (java.awt.Graphics2D aBrush){ + java.awt.Color oldColor = aBrush.getColor(); + aBrush.setColor(_fillColor); + aBrush.rotate(_rotation, this.getX()+(this.getWidth()/2), this.getY()+(this.getHeight()/2)); + aBrush.fill(this); + aBrush.rotate(-_rotation, this.getX()+(this.getWidth()/2), this.getY()+(this.getHeight()/2)); + aBrush.setColor(oldColor); + } + public void draw (java.awt.Graphics2D aBrush) { + java.awt.Color oldColor = aBrush.getColor(); + aBrush.setColor(_borderColor); + java.awt.Stroke oldStroke = aBrush.getStroke(); + aBrush.setStroke(new java.awt.BasicStroke(STROKE_WIDTH)); + aBrush.rotate(_rotation, this.getX()+(this.getWidth()/2), this.getY()+(this.getHeight()/2)); + aBrush.draw(this); + aBrush.rotate(-_rotation, this.getX()+(this.getWidth()/2), this.getY()+(this.getHeight()/2)); + aBrush.setStroke(oldStroke); + aBrush.setColor(oldColor); + } +} diff --git a/SmartRectangle.class b/SmartRectangle.class new file mode 100644 index 0000000..2cc7346 Binary files /dev/null and b/SmartRectangle.class differ diff --git a/SmartRectangle.ctxt b/SmartRectangle.ctxt new file mode 100644 index 0000000..e679c58 --- /dev/null +++ b/SmartRectangle.ctxt @@ -0,0 +1,22 @@ +#BlueJ class context +comment0.target=SmartRectangle +comment0.text=\r\n\ Write\ a\ description\ of\ class\ SmartRectangle\ here.\r\n\r\n\ @author\ (your\ name)\r\n\ @version\ (a\ version\ number\ or\ a\ date)\r\n +comment1.params=aColor +comment1.target=SmartRectangle(java.awt.Color) +comment2.params=aColor +comment2.target=void\ setBorderColor(java.awt.Color) +comment3.params=aColor +comment3.target=void\ setFillColor(java.awt.Color) +comment4.params=aColor +comment4.target=void\ setColor(java.awt.Color) +comment5.params=aRotation +comment5.target=void\ setRotation(double) +comment6.params=x\ y +comment6.target=void\ setLocation(double,\ double) +comment7.params=aWidth\ aHeight +comment7.target=void\ setSize(int,\ int) +comment8.params=aBrush +comment8.target=void\ fill(java.awt.Graphics2D) +comment9.params=aBrush +comment9.target=void\ draw(java.awt.Graphics2D) +numComments=10 diff --git a/SmartRectangle.java b/SmartRectangle.java new file mode 100644 index 0000000..8ae8ed4 --- /dev/null +++ b/SmartRectangle.java @@ -0,0 +1,65 @@ + +/** + * Write a description of class SmartRectangle here. + * + * @author (your name) + * @version (a version number or a date) + */ +public class SmartRectangle extends java.awt.geom.Rectangle2D.Double +{ + private java.awt.Color _borderColor, _fillColor; + private double _rotation; + private final int STROKE_WIDTH = 2; + + public SmartRectangle(java.awt.Color aColor){ + _borderColor = aColor; + _fillColor = aColor; // solid color to start + _rotation = 0; + } + + // methods not provided by Java + public void setBorderColor (java.awt.Color aColor) { + _borderColor = aColor; + } + public void setFillColor (java.awt.Color aColor) { + _fillColor = aColor; + } + public void setColor (java.awt.Color aColor) { + _borderColor = aColor; + _fillColor = aColor; + } + public void setRotation (double aRotation) { + _rotation = aRotation; + } + + + // more readable versions of methods provided by Java + public void setLocation (double x, double y) { + this.setFrame (x, y, this.getWidth(), this.getHeight()); + } + public void setSize (int aWidth, int aHeight) { + this.setFrame(this.getX(), this.getY(), aWidth, aHeight); + } + + // not provided by Java + public void fill (java.awt.Graphics2D aBrush){ + java.awt.Color oldColor = aBrush.getColor(); + aBrush.setColor(_fillColor); + aBrush.rotate(_rotation, this.getX()+(this.getWidth()/2), this.getY()+(this.getHeight()/2)); + aBrush.fill(this); + aBrush.rotate(-_rotation, this.getX()+(this.getWidth()/2), this.getY()+(this.getHeight()/2)); + aBrush.setColor(oldColor); + } + public void draw (java.awt.Graphics2D aBrush) { + java.awt.Color oldColor = aBrush.getColor(); + aBrush.setColor(_borderColor); + java.awt.Stroke oldStroke = aBrush.getStroke(); + aBrush.setStroke(new java.awt.BasicStroke(STROKE_WIDTH)); + aBrush.rotate(_rotation, this.getX()+(this.getWidth()/2), this.getY()+(this.getHeight()/2)); + aBrush.draw(this); + aBrush.rotate(-_rotation, this.getX()+(this.getWidth()/2), this.getY()+(this.getHeight()/2)); + aBrush.setStroke(oldStroke); + aBrush.setColor(oldColor); + } +} + diff --git a/package.bluej b/package.bluej new file mode 100644 index 0000000..a305f5a --- /dev/null +++ b/package.bluej @@ -0,0 +1,62 @@ +#BlueJ package file +dependency1.from=Lab1App +dependency1.to=ShapesPanel +dependency1.type=UsesDependency +dependency2.from=ShapesPanel +dependency2.to=SmartEllipse +dependency2.type=UsesDependency +dependency3.from=ShapesPanel +dependency3.to=SmartRectangle +dependency3.type=UsesDependency +editor.fx.0.height=744 +editor.fx.0.width=1382 +editor.fx.0.x=-8 +editor.fx.0.y=-8 +objectbench.height=157 +objectbench.width=1342 +package.divider.horizontal=0.6 +package.divider.vertical=0.7453416149068323 +package.editor.height=473 +package.editor.width=1252 +package.editor.x=-8 +package.editor.y=-8 +package.frame.height=744 +package.frame.width=1382 +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=50 +target1.name=Lab1App +target1.showInterface=false +target1.type=ClassTarget +target1.width=80 +target1.x=130 +target1.y=90 +target2.height=50 +target2.name=ShapesPanel +target2.showInterface=false +target2.type=ClassTarget +target2.width=110 +target2.x=10 +target2.y=160 +target3.height=50 +target3.name=SmartEllipse +target3.showInterface=false +target3.type=ClassTarget +target3.width=100 +target3.x=270 +target3.y=210 +target4.height=50 +target4.name=SmartRectangle +target4.showInterface=false +target4.type=ClassTarget +target4.width=120 +target4.x=130 +target4.y=290