如果你在安裝JDK的時候,選擇安裝了demo的話,在jdk\demo\applet\drawtest下有一個簡單的繪圖例子

解决方案 »

  1.   

    import java.awt.Graphics;public class GraphApplet extends java.applet.Applet {
        double f(double x) {
    return (Math.cos(x/5) + Math.sin(x/7) + 2) * getSize().height / 4;
        }    public void paint(Graphics g) {
            for (int x = 0 ; x < getSize().width ; x++) {
        g.drawLine(x, (int)f(x), x + 1, (int)f(x + 1));
            }
        }
      public String getAppletInfo() {
        return "Draws a sin graph.";
      }
    }
      

  2.   

    package com.abl.c7mon.util;import java.awt.*;
    import javax.swing.*;
    import javax.swing.BorderFactory;
    import com.borland.jbcl.layout.*;public class BackMapPanel extends JPanel {
      Image image = null;
      BorderLayout borderLayout1 = new BorderLayout();  public BackMapPanel(Image image) {
        super();
        this.image = image;
        try {
          jbInit();
        }
        catch(Exception ex) {
          ex.printStackTrace();
        }
      }
      void jbInit() throws Exception {
        //SwingUtilities.updateComponentTreeUI(this);
        this.setLayout(borderLayout1);
      }  public void paintComponent(Graphics g)
      {
        //System.out.println(image.toString());
        if(this.image!=null)
          g.drawImage(image,0,0,image.getWidth(this),image.getHeight(this),null,this);
        else
          g.drawString("找不到图片",50,50);
       
        g.fillRect(10,10,100,100);
             g.setColor(Color.black);
             g.drawRect(110,110,200,200);
             g.dispose();
      }
    }