Tuesday, July 25, 2023

BCA and B.Sc Programs - Programming in Java Lab - Bharathiar University - Practical Program 5- Write a Java Program to draw several shapes in the created windows.

 

Bharathiar University

Programming Java Lab
Java Program 5
 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



No comments:

Post a Comment

Program 12 BCA Madras University BCA Object Oriented Programming using C++ Practical Madras University Program 12 Implement a telephone directory using files

  BCA Object Oriented Programming using C++ Practical Madras University  Program 12  Implement a telephone directory using files SOURCE CODE...