graphical shapes and graphical shapes with colors
Graphical Shapes:-
The write a Java program to demonstrate the concepts of Various graphical Shapes using Applet.
Graphical Shapes procedure:-
- step 1: Import Jow awt package and applet package.
- step 2: Define a class by name "SHAPES" that extunds "Applet Class"
- step 3: Declare paint (Graphicg) to display in Applet.
- step 4: Use g.draw (line() to draw aline it.
- step 5: Invoke g.draw reat() to draw Rectangle if Takes Four Parameter.
- step 6: Invoke g.draw reat() to draw Round Rectangle if Takes six Parameter.
- step 7: Invoke g.draw Arc() to draw Arc if Takes six Parameter.
- step 8: The write HTML APPLET code to view in Applet view
For Example:Program to draw various graphical Shapes.
import java.applet.awt.*;
import java.applet.*;
/*
<applet code = "Shapes.class width=400 height=100>
</applet>
*/
public class Shapes extends Applet
{
public void paint(Graphics g)
{
g.draw(200,0,200,99);
g.drawRect(100,20,70,60);
g.drawRoundRectangle(220,20,40,60,40,30);
g.drawArc(300,20,70,60,0,150);
}
}
Output:
E:\graphical\java>javac shapes.java
E:\graphical\java>appletviewer shapes.java
RESULT:
Thus the program Successfully Executed.
Incorporation of colors in an Applet.
The write a Java Program to Demonstrate the Concept of incorporation of colors in an Applet.
Incorporation of colors in an Applet in procedure:-
- Step 1: Import a out and Applet package.
- Step 2: Define a class "Color Demo" that Extends "Applet" class.
- Step 3: Declare a Paint(Graphicg).
- Step 4: Invoke g.set color(color blue)and invoke g.drow (line() to draw line in blue color.
- Step 5: Invoke g.set color (color red)and invoke g.fill rect() to fill the rectngle with red color.
- Step 6: Invoke g.set color (color green)and invoke g fill Rac() to fill the with green color.
- Step 7: Invoke g.set color (color green)and invoke g fill Arc to fill Arc with yellow color.
- step 8: The write HTML APPLET code to view in Applet view.
For Example:Incorporation of colors in an Applet Program.
Import java.awt.*;
import java.applet.*;
/*
<applet code = "ColorsDemo.class" width =400 height =100>
</applet>
*/
public ColorsDemo extends Applet
{
public void paint(Graphics g)
{
g.setColor(Color,blue);
g.drawLine(200,0,200,99);
g.setColor(Color.red);
g.fillRect(100,20,70,60);
g.setColor(Color.green);
g.fillRoundRect(220,20,70,60,0,270);
g.setcolor(Color.Yellow);
g.fillArc(300,20,70,60,0,270);
}
}
OUTPUT
E:\AR\java>java ColorsDemo.java
E:\AR\java>appletviewer ColorsDemo.java
Thus the program Successfully Executed.
No comments:
Post a Comment