Permalink
Browse files

Problem Set 3

Added
  • Loading branch information...
1 parent f2666c3 commit efe3691ca564ca197698912bd36f70c0aed79c57 @simyseng committed Jul 21, 2013
View
Binary file not shown.
View
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path=""/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="lib" path="acm.jar"/>
+ <classpathentry kind="output" path=""/>
+</classpath>
View
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>Empty Project</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
@@ -0,0 +1,12 @@
+#Fri Jul 12 14:38:05 SGT 2013
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
Binary file not shown.
@@ -0,0 +1,19 @@
+import acm.program.*;
+import acm.graphics.*;
+import java.awt.event.*;
+
+public class MouseTracker extends GraphicsProgram {
+ public void run() {
+ label = new GLabel("");
+ label.setFont("Times New Roman-36");
+ add(label, 50, 50);
+
+ addMouseListeners();
+ }
+
+ public void mouseClicked(MouseEvent e) {
+ label.setLabel("Mouse: (" + e.getX() + ", " + e.getY() + ")");
+ }
+
+ private GLabel label;
+}
Binary file not shown.
@@ -0,0 +1,44 @@
+import java.awt.Color;
+import acm.program.*;
+import acm.util.RandomGenerator;
+import acm.graphics.*;
+
+public class RandomCircles extends GraphicsProgram{
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ public void run() {
+ /* Creates 10 random circles */
+ for(int i = 0 ; i < 10 ; i++) {
+ createRandomCircle();
+ }
+ }
+ /**
+ * Creates a random circle of size between 50 and 300 px
+ * @Creates a random circle of size between 50 and 300 px
+ */
+ private void createRandomCircle() {
+ /* Creates a random circle */
+ double diameter = rgen.nextDouble(SMALLEST_DIAMETER, LARGEST_DIAMETER);
+ GOval circle = new GOval(diameter, diameter);
+ Color color = rgen.nextColor();
+ /* Get another random color if white was returned */
+ while(true) {
+ if(color != Color.WHITE) break;
+ color = rgen.nextColor();
+ }
+ circle.setColor(color);
+ circle.setFilled(true);
+
+ /* Create a random coordinates set */
+ double x = rgen.nextDouble(0, getWidth() - diameter);
+ double y = rgen.nextDouble(0, getHeight() - diameter);
+
+ add(circle, x, y);
+ }
+
+ private static final RandomGenerator rgen = new RandomGenerator();
+ private static final double SMALLEST_DIAMETER = 10;
+ private static final double LARGEST_DIAMETER = 250;
+}
Binary file not shown.
@@ -0,0 +1,20 @@
+import acm.program.*;
+import acm.graphics.*;
+import java.awt.event.*;
+
+public class RubberBanding extends GraphicsProgram {
+ public void init() {
+ addMouseListeners();
+ }
+
+ public void mousePressed(MouseEvent e) {
+ line = new GLine(e.getX(), e.getY(), e.getX(), e.getY());
+ add(line);
+ }
+
+ public void mouseDragged(MouseEvent e) {
+ line.setEndPoint(e.getX(), e.getY());
+ }
+
+ private GLine line;
+}
View
Binary file not shown.
Submodule bin added at 821921

0 comments on commit efe3691

Please sign in to comment.