Draw different shape in Java


//Write a program to draw different shape in Java

import java.applet.*;
import java.awt.*;

public class DrawStuff extends Applet {

int width, height;

public void init() {
width = getSize().width;
height = getSize().height;
setBackground( Color.black );
}

public void paint( Graphics g ) {
g.setColor( Color.blue);
g.drawRect( 30, 40, 150, 20 );
g.setColor( Color.pink );
g.fillRect( 240, 160, 40, 110 );

g.setColor( Color.red );
g.drawOval( 50, 225, 100, 50 );
g.setColor( Color.orange );
g.fillOval( 225, 37, 50, 25 );

g.setColor( Color.magenta );
g.drawArc( 10, 110, 80, 80, 90, 180 );
g.setColor( Color.cyan );
g.fillArc( 140, 40, 120, 120, 90, 45 );

g.setColor( Color.yellow );
g.fillArc( 150, 150, 100, 100, 90, 90 );
g.setColor( Color.black );
g.fillArc( 160, 160, 80, 80, 90, 90 );

g.setColor( Color.green );
g.drawString( “computernotes.in by Veneeta phutela!”, 50, 150 );
}
}
/*<applet code=”DrawStuff.class” height=300 width=400>
</applet>*/

output:

ds1

 

 

 

ds2

Related Posts

Comments are closed.