Bharathiar University
Programming Java LabJava Program 5 Write a Java Program to draw several shapes in the created windows.
Syntax for Methods used in this programTo draw Oval:
drawOval(int x, int y, int width, int height) 
To change Pen Color:
setColor(Color c)
To color the Oval:
fillOval(int x, int y, int width, int height)
To draw rectangle:
drawRect(int x, int y, int width, int height) 
To draw line:
drawLine(int x1, int y1, int x2, int y2)
To draw arc:
drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
Source Code import java.awt.*;  import java.applet.*;  
public class Shapes extends Applet{ public void paint(Graphics g) {  g.setFont(new Font("Calibri", Font.BOLD,30));  g.drawString("Different Shapes in Applet", 20, 20);  g.drawOval(50,50,80,100);     g.setColor(Color.RED);    g.fillOval(50,50,80,100);	  g.drawRect(150,150,120,100);	  g.drawLine(270,270,350,350);  g.drawArc(60,280,100,80,180,180);   }}/* <applet code="Shapes.class" width="400" height="400"> </applet>*/
Output:
Applet Window
 Write a Java Program to draw several shapes in the created windows.
Syntax for Methods used in this program
To draw Oval:
drawOval(int x, int y, int width, int height)
To change Pen Color:
setColor(Color c)
To color the Oval:
fillOval(int x, int y, int width, int height)
To draw rectangle:
drawRect(int x, int y, int width, int height) 
To draw line:
drawLine(int x1, int y1, int x2, int y2)
To draw arc:
drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
Source Code
import java.awt.*;  
import java.applet.*;  
public class Shapes extends Applet
{
 public void paint(Graphics g)
 {
  g.setFont(new Font("Calibri", Font.BOLD,30));
  g.drawString("Different Shapes in Applet", 20, 20);
  g.drawOval(50,50,80,100);   
  g.setColor(Color.RED);  
  g.fillOval(50,50,80,100);	
  g.drawRect(150,150,120,100);	
  g.drawLine(270,270,350,350);
  g.drawArc(60,280,100,80,180,180);  
 }
}
/* <applet code="Shapes.class" width="400" height="400"> 
</applet>
*/
Output:
Applet Window



