Java Aap Let Methods
Java Aap Let Methods
Java Aap Let Methods
1. getParameter() Method :
- Description : The `getParameter()` method is used to retrieve the value of a parameter
passed to the applet in the HTML code. Parameters can be used to customize the behavior of the
applet.
- Syntax :
Public String getParameter(String paramName)
Example :
Import java.applet.Applet;
Public class MyApplet extends Applet {
Public void init() {
String message = getParameter(“message”);
// Use the value of the “message” parameter
}
}
2. drawString() Method :
- Description : The `drawString()` method is used to draw a text string at the specified
coordinates.
- Syntax :
Public abstract void drawString(String str, int x, int y)
3. drawLine() Method :
- Description : The `drawLine()` method is used to draw a straight line between two points.
- Syntax :
Public abstract void drawLine(int x1, int y1, int x2, int y2)
Example :
Import java.applet.Applet;
Import java.awt.Graphics;
Public class MyApplet extends Applet {
Public void paint(Graphics g) {
g.drawLine(20, 30, 100, 150);
}
}
4. drawRect() Method :
- Description : The `drawRect()` method is used to draw the outline of a rectangle.
- Syntax :
Public abstract void drawRect(int x, int y, int width, int height)
Example :
Import java.applet.Applet;
Import java.awt.Graphics;
Public class MyApplet extends Applet {
Public void paint(Graphics g) {
g.drawRect(50, 50, 100, 80);
}
}
5. fillRect() Method :
- Description : The `fillRect()` method is used to draw a filled rectangle.
- Syntax :
Public abstract void fillRect(int x, int y, int width, int height)
Example :
Import java.applet.Applet;
Import java.awt.Graphics;
Public class MyApplet extends Applet {
Public void paint(Graphics g) {
g.fillRect(50, 50, 100, 80);
}
}
6. drawRoundRect() Method :
- Description : The `drawRoundRect()` method is used to draw the outline of a rectangle with
rounded corners.
- Syntax :
Public abstract void drawRoundRect(int x, int y, int width, int height, int arcWidth, int
arcHeight)
Example :
Import java.applet.Applet;
Import java.awt.Graphics;
Public class MyApplet extends Applet {
Public void paint(Graphics g) {
g.drawRoundRect(50, 50, 100, 80, 20, 20);
}
}
7. fillRoundRect() Method :
- Description : The `fillRoundRect()` method is used to draw a filled rectangle with rounded
corners.
- Syntax :
Public abstract void fillRoundRect(int x, int y, int width, int height, int arcWidth, int
arcHeight)
Example :
Import java.applet.Applet;
Import java.awt.Graphics;
Public class MyApplet extends Applet {
Public void paint(Graphics g) {
g.fillRoundRect(50, 50, 100, 80, 20, 20);
}
}
Example usage:
g.draw3DRect(10, 10, 100, 50, true);
Example usage:
g.fill3DRect(10, 10, 100, 50, true
7. DRAW OVAL
The methods `public void drawOval` and `public void fillOval` are used in Java’s graphics
libraries (such as AWT or Swing) to draw or fill an oval shape on a graphical component. Here’s
an explanation of each method and its parameters:
Example usage:
g.drawOval(50, 50, 100, 80);
Example usage:
g.fillOval(50, 50, 100, 80);
8. DRAW POLYGON
The `public void drawPolygon` method is used in Java’s graphics libraries, such as AWT or
Swing, to draw the outline of a polygon on a graphical component. Here’s an explanation of the
method and its parameters:
- **public void drawPolygon**:
- This method is used to draw the outline of a polygon, which is defined by a series of points.
- Parameters:
- `int[] xPoints`: An array of x-coordinates of the points that define the polygon.
- `int[] yPoints`: An array of y-coordinates of the points that define the polygon.
- `int nPoints`: The number of points in the polygon.
Example usage:
Int[] xPoints = {100, 200, 300}; // X-coordinates of the polygon points
Int[] yPoints = {150, 250, 200}; // Y-coordinates of the polygon points
Int nPoints = 3; // Number of points in the polygon
g.drawPolygon(xPoints, yPoints, nPoints); // Draws the outline of the polygon
9. DRAW POLYLINE
Example usage:
Int[] xPoints = {100, 200, 150}; // x-coordinates of endpoints
Int[] yPoints = {100, 100, 200}; // y-coordinates of endpoints
Int nPoints = 3; // number of endpoints
g.drawPolyline(xPoints, yPoints, nPoints); // Draws a polyline connecting specified points
In this example, `xPoints` and `yPoints` arrays contain the coordinates of the endpoints of the
line segments, and `nPoints` specifies the number of endpoints.
Both `drawPolygon` and `drawPolyline` methods are useful for creating custom shapes or paths
in graphical user interfaces. The coordinates in the arrays define the vertices or endpoints of the
shapes or lines to be drawn.
Example usage:
Int x = 50, y = 50, width = 100, height = 80;
Int startAngle = 45, arcAngle = 90; // Start at 45 degrees, arc extent of 90 degrees
g.drawArc(x, y, width, height, startAngle, arcAngle); // Draws an arc within the specified
bounding rectangle
```
In this example, the arc is drawn within the bounding rectangle defined by `x`, `y`, `width`, and
`height`. The `startAngle` specifies where the arc begins, and `arcAngle` specifies the extent of
the arc.
Example usage:
Int x = 50, y = 50, width = 100, height = 80;
Int startAngle = 45, arcAngle = 90; // Start at 45 degrees, arc extent of 90 degrees
g.fillArc(x, y, width, height, startAngle, arcAngle); // Fills an arc within the specified bounding
rectangle
Similar to `drawArc`, `fillArc` fills the arc within the bounding rectangle with a specified
color.
These methods are commonly used to create arcs or segments of ellipses in graphical user
interfaces, such as for creating pie charts or circular progress indicators.
11. SET COLOR
In Java’s graphics libraries like AWT or Swing, `public void setColor(Color c)` is a method used
to set the drawing color for subsequent drawing operations. Here’s an explanation of its
parameters:
- `Color c`: This parameter specifies the color to be used for drawing. It can be an instance
of the `java.awt.Color` class, which represents a color in terms of its red, green, and blue
(RGB) components.
Example usage:
Color redColor = Color.RED; // Create a Color object for red color
g.setColor(redColor); // Set the drawing color to red
g.fillRect(50, 50, 100, 80); // Fill a rectangle with the current drawing color (red in this case)
```
In this example, `setColor(Color c)` is used to set the drawing color to red (`Color.RED`), and
then a rectangle is filled with this red color using `fillRect(int x, int y, int width, int height)`.
The `setColor(Color c)` method allows you to customize the appearance of shapes, text, and
other graphical elements by specifying the color to be used in subsequent drawing operations.