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
wwwapluscompsci.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 Shapeint x int y int wid, int ht Color col
xPos x;
finish this constructor
public void drawGraphics window
window.setColorcolor;
window.fillRectxPos yPos, width, height;
draw whatever you want
::
BONUS
add in set and get methods for all instance variables
public String toString
return xPosyPoswidthheightcolor;
setVisibletrue;
public void updateGraphics window
paintwindow;
All of your test code should be placed in paint.
public void paintGraphics window
window.setColorColorWHITE;
window.fillRectgetWidth getHeight;
window.setColorColorBLUE;
window.drawRectgetWidthgetHeight;
window.setFontnew FontTAHOMAFont.BOLD,;
window.drawStringCREATE YOUR OWN SHAPE!",;
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
wwwapluscompsci.com
Name
Date
Class
Lab
import javax.swing.JFrame;
public class GraphicsRunner extends JFrame
private static final int WIDTH ;
private static final int HEIGHT ;
public GraphicsRunner
superGraphics Runner";
setSizeWIDTHHEIGHT;
getContentPaneaddnew ShapePanel;
setVisibletrue;
setDefaultCloseOperationJFrameEXITONCLOSE;
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
