Graphics

 

All graphical output to the screen is done via the paint() method

Example with paintComponent() method (Run Applet).

import java.awt.*;
import javax.swing.*;

public class PaintDemo extends JApplet
{
    @Override
    public void init()
    {
        this.setContentPane(new View());
    }

    public class View extends JPanel
    {
        @Override
        public void paintComponent(Graphics g)
        {
            g.drawLine(10, 10, 100, 50);
        }
    }
}
 
<div align="center"><a href="../versionC/index.html" title="DKIT Lecture notes homepage for Derek O&#39; Reilly, Dundalk Institute of Technology (DKIT), Dundalk, County Louth, Ireland. Copyright Derek O&#39; Reilly, DKIT." target="_parent" style='font-size:0;color:white;background-color:white'>&nbsp;</a></div>