Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions