How do you draw a straight line in Java?
How do you draw lines in Java? To draw a line we can use the Line2D. Double static-inner class. This class constructor takes four integers values that represent the start (x1, y1) and end (x2, y2) coordinate of the line.
Which is used to draw a line in applet?
void drawLine(int x1, int y1, int x2, int y2) The DrawLine method can be used for drawing straight lines between two points (x1, y1) and (x2, y2) data. Following example DrawLine shows how to Draw a Line on Applet window using drawLine method of Graphics class.
How do you draw a graph in Java applet?
Draw Line Graph in Java Applet
- import java. awt.*;
- import java. applet.*;
- public class Line_Graph extends Applet.
- {
- int x[]={ 0, 60, 120, 180, 240, 300, 360, 400};
- int y[]={ 400, 280, 220, 140, 60, 60, 100, 220};
- int z=x. length;
- public void paint(Graphics g)
How do you draw a shape in an applet?
To Draw Various Shapes Using Applet In Java Program
- import java.awt.*;
- import java.applet.*;
- public class shap extends Applet.
- {
- public void paint(Graphics g)
- {
- g.drawLine(25,25,100,25);
- g.drawRect(25,40,100,50);
How do you draw a 2d line in Java?
To draw a line we can use the Line2D. Double static-inner class. This class constructor takes four integers values that represent the start (x1, y1) and end (x2, y2) coordinate of the line.
Which method is used to draw a line?
In order to draw a line, you need to use the drawLine method of the Graphics class. This method takes four parameters, the starting x and y coordinates and the ending x and y coordinates.
How can you draw polygon in Java?
We can draw Polygon in java applet by three ways :
- drawPolygon(int[] x, int[] y, int numberofpoints) : draws a polygon with the given set of x and y points.
- drawPolygon(Polygon p) : draws a polygon with the given object of Polygon class.
How do you draw a rectangle in Java applet?
Draw a rectangle in Java Applet:
- import java. awt.*;
- import java. applet.*;
- public class Rectangle extends Applet.
- {
- public void paint(Graphics g)
- {
- g. setColor(Color. black);
- g. drawRect(120, 50, 100, 100);
How do you draw a line and rectangle explain with an example?
Steps
- Draw a straight, horizontal line using a ruler.
- Make a shorter vertical line coming down from one end of the first line.
- Draw a horizontal line coming off the bottom end of the vertical line.
- Draw a vertical line between the ends of the two horizontal lines.
- Color in your rectangle to make it pop.