Draw a line and rectangle in Java Applet

The line is the simplest shape that we can draw with the Graphics class. The drawLine() method takes two pair of coordinates (x1, y1) and (y1, y2) as arguments and draws a line between them. It has the following syntax:

g.drawLine(x1, y2, x2, y2);  // g is the Graphics object passed to paint() method.


import java.awt.*;
import java.applet.*;
public class Line_rect extends Applet
 public void paint(Graphics g)
   g.drawRounder(20, 100, 80, 50, 10, 10);
   g.fillRounderRect(20, 110, 60, 30, 5, 5);
   g.drawLine(100,10,250, 150);

         <applet code = "linerect.class" width = "600" height = "400"></applet>

Recommended Posts:

Advanced Java
    1. Java Applet
    2. Applet Life Cycle in Java
    3. Difference Between Applet and Application
    4. Creating an Executable Applet in Java
    5. Displaying Numerical values in Applet
    6. An Applet Program to Add Two Numbers
    7. Event Handling in Applet
    8. AWT Event Classes
    9. AWT Graphics Class
    10. Draw a line and rectangle in Java Applet
    11. Draw Circles and Ellipses in Java Applet
    12. Draw a Polygon in Java Applet
    13. AWT Hierarchy | AWT Package
    14. Swing in Core Java