Java Reference
In-Depth Information
// Create and set a bright shade of red
Color brightRed = new Color(200, 0, 0);
g.setColor(brightRed);
// Display a message
g.drawString(“Demonstrating vector graphics in Java”,
30, 25);
// Create and set a shade of blue
Color aBlue = new Color(0, 0, 255);
g.setColor(aBlue);
// Draw a filled oval
g.fillOval(50, 60, 200, 100);
// Draw a black-border rectangle
Color aBlack = new Color(0, 0, 0);
g.setColor(aBlack);
g.drawRect(30, 180, 200, 50);
// Draw a green polygon
Color aGreen = new Color(0, 180,0);
g.setColor(aGreen);
g.drawPolygon(xCoords, yCoords, 4);
// Translate the image by adding 120 to the
// y coordinates of the polygon
for(intx=0;x<4;x++)
yCoords[x] = yCoords[x] + 120;
// Fill the translated polygon
g.fillPolygon(xCoords, yCoords, 4);
// Translate image again
for(intx=0;x<4;x++)
yCoords[x] = yCoords[x] + 120;
// Draw a magenta polyline. Note that the
// drawPolyline() does not close the figure
Color aMagenta = new Color(180,0 ,180);
g.setColor(aMagenta);
g.drawPolyline(xCoords, yCoords, 4);
// Restore the original values in the array of
// y coordinates
yCoords[0] = 50;
yCoords[1] = 150;
yCoords[2] = 50;
yCoords[3] = 150;
// Draw a cyan arc
Color aCyan = new Color(0, 120 ,120);
g.setColor(aCyan);
g.drawArc( 50,
// x of start point
280,
// y of start point
150,
// width
100,
// height
Search WWH ::




Custom Search