Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add files via upload
- Loading branch information
Showing
14 changed files
with
327 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |