How do you write a triangle in Java?

We call the drawLine() method to draw a line. As we want to create a triangle that three lines, we need to call drawLine() three times. drawLine() takes four arguments, the x and y coordinates of both the first and second points of the line.

How do you print a triangle in Java?

1. Right Triangle Star Pattern

  1. public class RightTrianglePattern.
  2. {
  3. public static void main(String args[])
  4. {
  5. //i for rows and j for columns.
  6. //row denotes the number of rows you want to print.
  7. int i, j, row=6;
  8. //outer loop for rows.

How do you draw a triangle in Java applet?

Draw Triangle in Java Applet

  1. import java. applet.*;
  2. import java. awt.*;
  3. public class Triangle extends Applet.
  4. {
  5. public void paint(Graphics g1)
  6. {
  7. g1. drawLine(180,150,180,370);
  8. g1. drawLine(180,150,440,370);

How is inheritance defined in Java?

Inheritance in Java is a concept that acquires the properties from one class to other classes; for example, the relationship between father and son. In Java, a class can inherit attributes and methods from another class. The class that inherits the properties is known as the sub-class or the child class.

IT IS IMPORTANT:  Question: Why do we use transactions in SQL Server?

Is there a triangle class in Java?

(The Triangle class) Design a class named Triangle that extends GeometricObject. The class contains: Three double data fields named side1, side2, and side3 with default values 1.0 to denote three sides of the triangle. A no-arg constructor that creates a triangle with specified side1, side2,and side3.

How do you fill a Shape in Java?

To fill rectangles with the current colour, we use the fillRect() method. In the example we draw nine coloured rectangles. Graphics2D g2d = (Graphics2D) g; There is no need to create a copy of the Graphics2D class or to reset the value when we change the colour property of the graphics context.

How do you draw a 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.

How do you draw a Shape in an applet?

To Draw Various Shapes Using Applet In Java Program

  1. import java.awt.*;
  2. import java.applet.*;
  3. public class shap extends Applet.
  4. {
  5. public void paint(Graphics g)
  6. {
  7. g.drawLine(25,25,100,25);
  8. g.drawRect(25,40,100,50);

How do you draw a circle in Java applet?


  1. import java. awt.*;
  2. import java. applet.*;
  3. public class circle extends Applet.
  4. {
  5. public void paint(Graphics g)
  6. {
  7. g. drawOval(20,20,200,120);
  8. g. setColor(Color. green);

How do I fill a circle with color in Java applet?

To View the Shapes :

1. Use method drawPolygon and fillPolygon of the Graphics class to draw and fill the shapes – Square, Pentagon, Rectangle and Triangle. 2. Use method drawOval and fillOval of the Graphics class to draw and fill the shapes – Oval and Circle.

IT IS IMPORTANT:  Frequent question: What is sync Binlog in MySQL?

What is triangle JavaScript?

The triangle() function is an inbuilt function in p5. js which is used to draw a triangle in a plane. This function accepts three vertices of triangle.

How do you draw an isosceles triangle in Java?

This is the problem: Create an IsoTri application that prompts the user for the size of an isosceles triangle and then displays the triangle with that many lines. The IsoTri application code should include the printChar(int n, char ch) method.