Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // APCS1 Lab Test 2
- //
- // Prog09.java
- //
- // Box missing front & back
- //
- // Points: 4
- //
- //
- ////////////////////////////////////////////////////////////////////////////////
- // Write a program that will draw a 3-D box without the front or back.
- // The remaining 4 sides need to be drawn as Polygon objects.
- // The colors of these 4 sides need to be red, green, blue and yellow.
- // It does not matter which side gets which of the 4 colors.
- //
- ////////////////////////////////////////////////////////////////////////////////
- // NOTE: You will need to load Prog09.html in order to execute this file.
- //
- // ALSO: The sample exection of this file is on the back of your lab test sheet.
- import java.awt.*;
- import java.applet.*;
- import java.util.*;
- public class Prog09 extends Applet
- {
- public void paint(Graphics g)
- {
- Polygon top = new Polygon();
- top.addPoint(100, 100);
- top.addPoint(200, 100);
- top.addPoint(250, 150);
- top.addPoint(150, 150);
- g.setColor(Color.blue);
- g.fillPolygon(top);
- Polygon left = new Polygon();
- left.addPoint(100, 100);
- left.addPoint(150, 150);
- left.addPoint(150, 250);
- left.addPoint(100, 200);
- g.setColor(Color.red);
- g.fillPolygon(left);
- Polygon bottom = new Polygon();
- bottom.addPoint(150, 250);
- bottom.addPoint(150, 200);
- bottom.addPoint(200, 200);
- bottom.addPoint(250, 250);
- g.setColor(Color.yellow);
- g.fillPolygon(bottom);
- Polygon right = new Polygon();
- right.addPoint(200, 150);
- right.addPoint(250, 150);
- right.addPoint(250, 250);
- right.addPoint(200, 200);
- g.setColor(Color.green);
- g.fillPolygon(right);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement