Answered step by step
Verified Expert Solution
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
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started