Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lab04 finished #3

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
cea48ac
ant mySimpleGui1 and -cp java working
Oct 21, 2016
b4890ae
copied simple directory from pconrad to mchavez
Oct 27, 2016
f7d645b
added snowman's head
Oct 27, 2016
73c3ee7
copied advanced
Oct 27, 2016
298d2cd
added CaliHelmet class and modified AllMyDrawings class to test CaliH…
Oct 27, 2016
85493f1
created Helmet class and fix resizing issues.
Oct 28, 2016
d2e85be
cleaned classes
Oct 28, 2016
e72342b
added updated version of SimpleGUI1 to my src directory - done with S…
sean-shelton Oct 28, 2016
68472b2
Made g_whiter dir with SimpleGui1
Oct 29, 2016
307669b
Drawers class begins
Oct 29, 2016
f6c2bcb
Step 5
wdlzz926 Oct 29, 2016
9e2b657
Finish lab04
wdlzz926 Oct 29, 2016
d97c96c
delete vim add-on
wdlzz926 Oct 29, 2016
864e5a0
delete vim add-on
wdlzz926 Oct 29, 2016
9aebf9b
Finished all of the necessary functions and checked through the code …
sean-shelton Oct 29, 2016
4d6fcf4
Drawings of drawers
Oct 29, 2016
7beaf34
update
UCSBWillHuang1997 Oct 29, 2016
002f07b
Fixed AllMyDrawinsg to not look terrible
gwhiter Oct 29, 2016
5c7e388
update
UCSBWillHuang1997 Oct 29, 2016
d7f9974
Made the javadoc a bit better
sean-shelton Oct 29, 2016
7dcdaea
Attempt to improve javadoc
gwhiter Oct 29, 2016
eadcf75
Removed pconrad exclusive files
gwhiter Oct 29, 2016
44c9e47
Fixing username for commits
gwhiter Oct 29, 2016
41d681c
lab04 finished - Tables and CoffeeTables
Oct 29, 2016
c3cd3a5
final product
UCSBWillHuang1997 Oct 29, 2016
6e54d60
final product
UCSBWillHuang1997 Oct 29, 2016
524238d
added basketballs and basketball with player
Oct 29, 2016
a850e80
final
ttsherpa1996 Oct 29, 2016
4e25cbf
final product!
UCSBWillHuang1997 Oct 29, 2016
c6549be
final product.
UCSBWillHuang1997 Oct 31, 2016
d22ebef
Merge pull request #2 from wdlzz926/master
jalexanderqed Nov 3, 2016
e44d7d7
Merge pull request #8 from amahini95/master
jalexanderqed Nov 3, 2016
8128b70
Merge pull request #3 from sean-shelton/master
jalexanderqed Nov 3, 2016
6247d7e
Merge pull request #4 from gwhiter/master
jalexanderqed Nov 3, 2016
50a2ba6
Merge pull request #5 from UCSBWillHuang1997/master
jalexanderqed Nov 3, 2016
7423a04
Merge pull request #6 from rayouyang/master
jalexanderqed Nov 3, 2016
82fce59
made my lab04
The3TC Nov 3, 2016
3fc72ab
Merge pull request #9 from The3TC/master
jalexanderqed Nov 3, 2016
5c5624f
Merge pull request #1 from chavez95/master
jalexanderqed Nov 3, 2016
b17c842
Fixed wrong package name in williamwhuang/SimpleGui1.java
jalexanderqed Nov 3, 2016
08f3687
updated version
ttsherpa1996 Nov 3, 2016
7036284
Merge pull request #7 from ttsherpa1996/master
jalexanderqed Nov 3, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/edu/ucsb/cs56/drawings/amahini/SimpleGui1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package edu.ucsb.cs56.drawings.amahini;

import javax.swing.*;

/** SimpleGui1 comes from Head First Java 2nd Edition p. 355.
It illustrates a simple GUI with a Button that doesn't do anything yet.

@author Head First Java, 2nd Edition p. 355
@author P. Conrad (who only typed it in and added the Javadoc comments)
@author TODO: Add additional author here
@version CS56, Spring 2013, UCSB
*/

public class SimpleGui1 {

/** main method to fire up a JFrame on the screen
@param args not used
*/

public static void main (String[] args) {
JFrame frame = new JFrame() ;

JButton button = new JButton("Click me, you won't!") ;

java.awt.Color myColor = new java.awt.Color(204,255,153); // R, G, B values.
button.setBackground(myColor);
button.setOpaque(true);

frame. setDefaultCloseOperation(JFrame. EXIT_ON_CLOSE) ;
frame. getContentPane() . add(button) ;
frame. setSize(300,300) ;
frame. setVisible(true) ;
}
}
142 changes: 142 additions & 0 deletions src/edu/ucsb/cs56/drawings/amahini/advanced/AllMyDrawings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package edu.ucsb.cs56.drawings.amahini.advanced;

import java.awt.Graphics2D;
import java.awt.Shape; // general class for shapes
import java.awt.Color; // class for Colors
import java.awt.Stroke;
import java.awt.BasicStroke;

import edu.ucsb.cs56.drawings.utilities.ShapeTransforms;
import edu.ucsb.cs56.drawings.utilities.GeneralPathWrapper;

/**
* A class with static methods for drawing various pictures
*
* @author Armin Mahini
* @version for UCSB CS56, F16
*/

public class AllMyDrawings
{
/** Draw a picture with a few tables
@param g2
*/
public static void drawPicture1(Graphics2D g2) {

Table t1 = new Table(100,250,50,75);
g2.setColor(Color.CYAN); g2.draw(t1);

// Make a black table that's half the size,
// and moved over 150 pixels in x direction

Shape t2 = ShapeTransforms.scaledCopyOfLL(t1,0.5,0.5);
t2 = ShapeTransforms.translatedCopyOf(t2,150,0);
g2.setColor(Color.BLACK); g2.draw(t2);

// Here's a table that's 4x as big (2x the original)
// and moved over 150 more pixels to right.
t2 = ShapeTransforms.scaledCopyOfLL(t2,4,4);
t2 = ShapeTransforms.translatedCopyOf(t2,150,0);

// We'll draw this with a thicker stroke
Stroke thick = new BasicStroke (4.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);

// for hex colors, see (e.g.) http://en.wikipedia.org/wiki/List_of_colors
// #002FA7 is "International Klein Blue" according to Wikipedia
// In HTML we use #, but in Java (and C/C++) its 0x

Stroke orig=g2.getStroke();
g2.setStroke(thick);
g2.setColor(new Color(0x002FA7));
g2.draw(t2);

// @@@ FINALLY, SIGN AND LABEL YOUR DRAWING

g2.setStroke(orig);
g2.setColor(Color.BLACK);
g2.drawString("A few tables by Armin Mahini", 20,20);
}


/** Draw a picture with a few tables and coffee tabless
*/
public static void drawPicture2(Graphics2D g2) {

// Draw some coffee tables.

CoffeeTable large = new CoffeeTable(100,50,225,150);
CoffeeTable smallCT = new CoffeeTable(20,50,40,30);
CoffeeTable tall = new CoffeeTable(20,150,20,40);
CoffeeTable small = new CoffeeTable(20,250,40,20);

g2.setColor(Color.RED); g2.draw(large);
g2.setColor(Color.GREEN); g2.draw(smallCT);
g2.setColor(Color.BLUE); g2.draw(tall);
g2.setColor(Color.MAGENTA); g2.draw(small);

Table t1 = new Table(50,250,50,75);
g2.setColor(Color.CYAN); g2.draw(t1);

// Make a black table that's half the size,
// and moved over 150 pixels in x direction
Shape t2 = ShapeTransforms.scaledCopyOfLL(t1,0.5,0.5);
t2 = ShapeTransforms.translatedCopyOf(t2,150,0);
g2.setColor(Color.BLACK); g2.draw(t2);

// Here's a table that's 4x as big (2x the original)
// and moved over 150 more pixels to right.
t2 = ShapeTransforms.scaledCopyOfLL(t2,4,4);
t2 = ShapeTransforms.translatedCopyOf(t2,150,0);

// We'll draw this with a thicker stroke
Stroke thick = new BasicStroke (4.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);

// for hex colors, see (e.g.) http://en.wikipedia.org/wiki/List_of_colors
// #002FA7 is "International Klein Blue" according to Wikipedia
// In HTML we use #, but in Java (and C/C++) its 0x

Stroke orig=g2.getStroke();
g2.setStroke(thick);
g2.setColor(new Color(0x002FA7));
g2.draw(t2);

// Draw a Table to rotate

Table rotateT1 = new Table(50,300,40,75);
Table rotateT2 = new Table(200,300,200,100);


g2.draw(rotateT1);
g2.setColor(new Color(0x8F00FF));

// Rotate the second table 45 degrees around its center.
Shape t3 = ShapeTransforms.rotatedCopyOf(rotateT2, Math.PI/4.0);

g2.draw(t3);

// @@@ FINALLY, SIGN AND LABEL YOUR DRAWING

g2.setStroke(orig);
g2.setColor(Color.BLACK);
g2.drawString("A bunch of Coffee Tables and a few tables by Armin Mahini", 20,20);
}

/** Draw a different picture with a few tables and coffee tables
*/
public static void drawPicture3(Graphics2D g2) {

// label the drawing

g2.drawString("A bunch of Coffee Tables by Armin Mahini", 20,20);


// Draw some coffee tables.

CoffeeTable large = new CoffeeTable(100,50,225,150);
CoffeeTable smallCT = new CoffeeTable(20,50,40,30);

g2.setColor(Color.RED); g2.draw(large);
g2.setColor(Color.GREEN); g2.draw(smallCT);

}
}
71 changes: 71 additions & 0 deletions src/edu/ucsb/cs56/drawings/amahini/advanced/CoffeeTable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package edu.ucsb.cs56.drawings.amahini.advanced;
import java.awt.geom.GeneralPath; // combinations of lines and curves
import java.awt.Shape; // general class for shapes

import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;

import edu.ucsb.cs56.drawings.utilities.ShapeTransforms;
import edu.ucsb.cs56.drawings.utilities.GeneralPathWrapper;

/**
A vector drawing of a coffee table that implements
the Shape interface, and so can be drawn, as well as
rotated, scaled, etc.

@author Armin Mahini
@version for CS56, F16, UCSB

*/
public class CoffeeTable extends Table implements Shape
{
/**
Constructor

@param x x coord of lower left corner of table
@param y y coord of lower left corner of table
@param width width of the table
@param height of table
*/
public CoffeeTable(double x, double y, double width, double height)
{

// Rather than having to scale at the end, we can just
// draw things the right way to begin with, using the
// x, y, width and height. If you haven't already
// hard coded a particular drawing, this may be an easier
// way.

super(x,y,width,height);

GeneralPath gp = this.get();

double topHeight = .25 * height;
double legWidth = .1 * width;
double legHeight = height - (2 * topHeight);

// Make the top

Rectangle2D.Double top =
new Rectangle2D.Double(x, y,
width, topHeight);

// make the legs. Remember that y goes DOWN the page,
// so we ADD to y to get a "lower" value on the screen

Rectangle2D.Double leg1 =
new Rectangle2D.Double (x + legWidth, y + topHeight,
legWidth, legHeight);

Rectangle2D.Double leg2 =
new Rectangle2D.Double (x + (.7 * width), y + topHeight,
legWidth, legHeight);

// put the whole table together

GeneralPath wholeTable = this.get();
wholeTable.append(top, false);
wholeTable.append(leg1, false);
wholeTable.append(leg2, false);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package edu.ucsb.cs56.drawings.amahini.advanced;

import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JComponent;

/**
A component that draws a Picture by Phill Conrad

@author Phill Conrad (original drawing)
@version CS56, W16, UCSB
*/


public class MultiPictureComponent extends JComponent
{
private int whichPicture = 0;

public MultiPictureComponent(int whichPicture) {
this.whichPicture = whichPicture;
}

/** The paintComponent method is always required if you want
* any graphics to appear in your JComponent.
*
* There is a paintComponent
* method that is created for you in the JComponent class, but it
* doesn't do what we want, so we have to "override" that method with
* our own method.
*/

public void paintComponent(Graphics g)
{
Graphics2D g2 = (Graphics2D) g;
switch (this.whichPicture) {
case 1:
AllMyDrawings.drawPicture1(g2);
break;
case 2:
AllMyDrawings.drawPicture2(g2);
break;
case 3:
AllMyDrawings.drawPicture3(g2);
break;
default:
throw new IllegalArgumentException("Unknown value for whichPicture in MultiPictureComponent" + this.whichPicture);
} // switch
} // paintComponent
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package edu.ucsb.cs56.drawings.amahini.advanced;

import javax.swing.JFrame;

/** A viewer class to see a picture I drew with
* just three simple Java graphics objects, namely
* Rectangle, Line2D.Double, Ellipse2D.Double
*
* @author A. Mahini
* @version for UCSB CS56, F16
*/

public class MultiPictureViewer
{
public static void main(String[] args)
{
int whichPicture = 1;

// If user passed a command line argument,
// get which picture we want to display from the user

if (args.length== 1) {
whichPicture = Integer.parseInt(args[0]);
}

JFrame frame = new JFrame();

// Set the size to whatever size you like (width, height)
// For projects you turn in, lets not get any bigger than 640,480

frame.setSize(640,480); // @@@ MODIFY THIS LINE IF YOU LIKE

// Set your own title
frame.setTitle("Armin's First Drawing"); // @@@ MODIFY THIS LINE

// Always do this so that the red X (or red circle) works
// to close the window.

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

// Instantiate your drawing as a "component"

MultiPictureComponent component =
new MultiPictureComponent(whichPicture);

// Always add your component to the frame
// and then make the window visible

frame.add(component);
frame.setVisible(true);
}
}
Loading