Drawing a simple picture:

  1. The picture that we want to draw:

  2. The Applet:

    public class CarDrawer extends Applet
    {  public void paint(Graphics g)
        { 
          Graphics2D g2 = (Graphics2D)g;
    
          Point2D.Double r1 = new Point2D.Double(110, 110);
          Point2D.Double r2 = new Point2D.Double(120, 100);
          Point2D.Double r3 = new Point2D.Double(140, 100);
          Point2D.Double r4 = new Point2D.Double(150, 110);
    
          Line2D.Double frontWindshield = new Line2D.Double(r1, r2);
          Line2D.Double roofTop         = new Line2D.Double(r2, r3);
          Line2D.Double rearWindshield  = new Line2D.Double(r3, r4);
    
          Rectangle body = new Rectangle(100, 110, 60, 10);
    
          Ellipse2D.Double frontTire
                         = new Ellipse2D.Double(110, 120, 10, 10);
          Ellipse2D.Double rearTire
                         = new Ellipse2D.Double(140, 120, 10, 10);
    
          g2.draw(roofTop);
          g2.draw(frontWindshield);
          g2.draw(rearWindshield);
          g2.draw(body);
          g2.draw(frontTire);
          g2.draw(rearTire);
    
          Font myFont = new Font("Helvetica", Font.BOLD, 18);
          g2.setFont(myFont);
          Color myColor = new Color(0.3F, 0.2F, 0.7F);
          g2.setColor(myColor);
          g2.drawString("JavaMobile 1.2ti", 100, 150);
       }
    }
    
    

  3. The source code (I modified the example slightly): click here

  4. Putting it in your web page:

        <EMBED
           TYPE="application/x-java-applet;version=1.2"
           archive="classes111.zip"
           CODE="DEMO/CarDrawer.class"
           WIDTH="400" HEIGHT="300">
       </EMBED>
       

    The result: