Create a class "DiagramDemo" click finish
now open the class "DiagramDemo"
Extends the class to Applet
when you are typing Applet just press ctrl+spacebar
it will shows you some suggestions
next create function
import java.applet.Applet;
import java.awt.Graphics;
/**
*
* @author Backtrace
*/
public class DiagramDemo extends Applet{
public void paint(Graphics g){
g.drawLine(100, 100, 200, 100);
}
}
Output
------------
To draw a rectangle
g.drawLine(100, 100, 200, 100);
g.setColor(Color.red);
g.fillRect(175, 100, 100, 100);
To draw an Oval
g.drawOval(200, 200, 100, 1);
Draw a polygon
int[] x={400,410,350,300,200,200};
int[] y={290,280,280,210,200,200};
g.drawPolygon(x, y, 4);
Full Source code
-------------------------
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
/**
*
* @author Backtrace
*/
public class DiagramDemo extends Applet{
int[] x={400,410,350,300,200,200};
int[] y={290,280,280,210,200,200};
public void paint(Graphics g){
g.drawLine(100, 100, 200, 100);
g.drawLine(100, 100, 200, 100);
g.drawRect(150, 150, 100, 100);
g.setColor(Color.red);
g.fillRect(175, 100, 100, 100);
g.drawOval(200, 200, 100, 1);
g.drawPolygon(x, y, 4);
}
}
Output
------------------












Posted in:
2 Comments:
Thanks for sharing this great article! That is very interesting I love reading and I am always searching for informative articles like this.
Java Course in Chennai
I am very glad to read your informative blog...thanks a lot for your valuable sharing
you can also visit here java programming training in Gurgaon, India. Visit us
Post a Comment