Question: This lab was designed to teach you how to design and use classes, instantiate objects, and use graphic methods. Lab Description : Write a program

This lab was designed to teach you how to design and use classes, instantiate objects, and use graphic methods.
Lab Description : Write a program to create a unique shape using graphics, instance variables, constructors, and classes.
Part One :: Use the Shape.java file to create your own shape. Complete the Shape constructor and add code to the draw method to draw your own shape. Use ShapePanel.java and GraphicsRunner.java to test your Shape class. Be creative and come up with something really cool. By using //(c) A+ Computer Science
//www.apluscompsci.com
//Name -
import java.awt.Color;
import java.awt.Graphics;
public class Shape
{
//instance variables
private int xPos;
private int yPos;
private int width;
private int height;
private Color color;
public Shape(int x, int y, int wid, int ht, Color col)
{
xPos = x;
//finish this constructor
}
public void draw(Graphics window)
{
window.setColor(color);
window.fillRect(xPos, yPos, width, height);
//draw whatever you want
//^
//[ :: ]
//()
}
//BONUS
//add in set and get methods for all instance variables
public String toString()
{
return xPos+""+yPos+""+width+""+height+""+color;
}
} setVisible(true);
}
public void update(Graphics window)
{
paint(window);
}
/*
*All of your test code should be placed in paint.
*/
public void paint(Graphics window)
{
window.setColor(Color.WHITE);
window.fillRect(0,0,getWidth(), getHeight());
window.setColor(Color.BLUE);
window.drawRect(20,20,getWidth()-40,getHeight()-40);
window.setFont(new Font("TAHOMA",Font.BOLD,18));
window.drawString("CREATE YOUR OWN SHAPE!",40,40);
//instantiate a Shape
//tell your shape to draw
//instantiate a Shape
//tell your shape to draw
//instantiate a Shape
//tell your shape to draw
}
}//(c) A+ Computer Science
//www.apluscompsci.com
//Name -
//Date -
//Class -
//Lab -
import javax.swing.JFrame;
public class GraphicsRunner extends JFrame
{
private static final int WIDTH =800;
private static final int HEIGHT =600;
public GraphicsRunner()
{
super("Graphics Runner");
setSize(WIDTH,HEIGHT);
getContentPane().add(new ShapePanel());
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main( String args[])
{
GraphicsRunner run = new GraphicsRunner();
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!