Interfaces
6.092: Introduction to Java
Assignment 5: main()
Programs start at a main() method, but many classes can have main() public class SimpleDraw {
/* ... stuff ... */ public static void main(String args[]) {
SimpleDraw content = new SimpleDraw(new DrawGraphics());
/* ... more stuff ... */
}
}
Assignment 5: main()
Programs start at a main() method, but many classes can have main() public class SimpleDraw {
/* ... stuff ... */ public static void main(String args[]) {
SimpleDraw content = new SimpleDraw(new DrawGraphics());
/* ... more stuff ... */
}
}
public class DrawGraphics {
BouncingBox box; public DrawGraphics() { box = new BouncingBox(200, 50, Color.RED);
}
public void draw(Graphics surface) {
surface.drawLine(50, 50, 250, 250);
box.draw(surface);
}
}
public class DrawGraphics {
BouncingBox box; // a field or member variable public DrawGraphics() { box = new BouncingBox(200, 50, Color.RED);
}
public void draw(Graphics surface) {
surface.drawLine(50, 50, 250, 250);
box.draw(surface);
}
}
public class DrawGraphics {
BouncingBox box; public DrawGraphics() { // constructor box = new BouncingBox(200, 50, Color.RED);
}
public void draw(Graphics surface) {
surface.drawLine(50, 50, 250, 250);
box.draw(surface);
}
}
public class DrawGraphics { public void draw(Graphics surface) { surface.drawLine(50, 50, 250, 250); box.draw(surface); surface.fillRect (150, 100, 25, 40); surface.fillOval (40, 40, 25, 10); surface.setColor (Color.YELLOW); surface.drawString ("Mr. And Mrs. Smith", 200, 10);
}
}
public class DrawGraphics {
ArrayList boxes = new ArrayList(); public DrawGraphics() {
boxes.add(new BouncingBox(200, 50, Color.RED));
boxes.add(new BouncingBox(10, 10, Color.BLUE));
boxes.add(new BouncingBox(100, 100, Color.GREEN));
boxes.get(0).setMovementVector(1, 0);
boxes.get(1).setMovementVector(-3, -2);