In: Computer Science
create a java class with name ModernArt:
For the first part of the assignment, you will be extending the JApplet class and creating a work of modern using the Graphics class to draw various shapes to the applet window. As part of your masterpiece, you should incorporate the following elements:
You may use more elements than the minimal requirements above, but you must use at least that many. There are unit tests for this question that will determine if you have correctly included the required shapes and colors, but there are no tests to judge your work itself as it is not possible to write unit tests which measure the sheer lack of sophistication typically embodied by so much of modern art.
import java.applet.*;
import java.awt.*;
public class GApplet extends Applet
{
public void paint(Graphics g)
{
//x coordinates for polygon
int x[] = { 10, 30, 40, 50, 110, 140 };
//y coordinates for polygon
int y[] = { 140, 110, 50, 40, 30, 10 };
// number of vertices
int numberofpoints = 6;
//Colour is set to red
g.setColor(Color.RED);
//non-solid rectangle
g.drawRect(20, 40, 200, 40);
g.fillRect(300, 40, 200, 40);
//non-solid oval
g.drawOval(20, 160, 200,
100);
g.fillOval(300, 160, 200,
100);
// non-solid polygon
g.drawPolygon(x, y, numberofpoints);
//line1(red)
g.drawLine(30, 20, 80, 90);
// set the color to blue
g.setColor(Color.blue);
//solid oval
draw3Oval(g,Color.blue,30,40,50,true);
//solid polygon
g.draw3DRect(100,100,50,50,true);
g.fill3DRect(10,150,50,100,true);
//line2(blue)
g.drawLine(20, 20, 500, 20);
// set the color to orange
g.setColor(Color.orange);
//line3 (orange)
g.drawLine(40, 20, 80, 90);
}
void draw3DOval(Graphics g, Color bg, int x, int y,
int w, int h, boolean raised)
{
Color c = g.getColor();
Color shadow = bg.darker();
Color highlight = bg.brighter();
g.setColor(raised ? highlight : shadow);
g.drawArc(x, y, w, h, 45, 180);
g.setColor(raised ? shadow : highlight);
g.drawArc(x, y, w, h, 225, 180);
g.setColor(c);
}
}