你这个例子一看就是错误的,java都是用类实现的,你的类呢?怎么只有方法?Java中有Graphics2D吗?我没有看见.我估计你下载的不完全

解决方案 »

  1.   

    class a extends Japplet
    {
    public void paint(Graphics g)
    {
      Ellipse2D.Float shape;
      GradientPaint gp;
      // create a Graphics2D  Graphics2D g2 = (Graphics2D) g ;  // create a Ellipse2D (x,y,w,h)  shape = new Ellipse2D.Float (200,200,60,60);  // create a Cyclic GradientPaint   // (x1,y1,color1,x2,y2,color2, boolean cyclic)  gp = new GradientPaint (180,190,Color.yellow,220,210,Color.red,true);  g2.setPaint(gp);  g2.fill(shape);}static void main (String arg[])
    {
     Frame f= new Frame("demo");
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
    System.exit(0);
        }
    );
    f.getContentPane().add(new a());
    f.pack();
    f.setVisible(true);}}大概可以吧
      

  2.   

    一般你可以把它用applet的方法调用,修改一下为:
    但是我尝试过你这个程序没有效果显示的
    import java.awt.*;
    import java.awt.geom.*;
    public class testapplet extends java.applet.Applet {
    public synchronized void paint(Graphics g){
      Ellipse2D.Float shape;
      GradientPaint gp;
      // create a Graphics2D
      Graphics2D g2 = (Graphics2D)g;
      // create a Ellipse2D (x,y,w,h)
      shape = new Ellipse2D.Float(200,200,60,60);
      // create a Cyclic GradientPaint 
      // (x1,y1,color1,x2,y2,color2, boolean cyclic)
      gp = new GradientPaint(180,190,Color.yellow,220,210,Color.red,true);
      g2.setPaint(gp);
      g2.fill(shape);
    }
    }
    然后在html中:
    <html>
    <body>
    <applet id=myApplet id=myApplet code="testapplet.class" height=400 width=400>
    </applet>
    </body>
    </html>
    以下这个程序可以运行的
    import java.awt.*;
    import java.awt.geom.*;
    public class testapplet extends java.applet.Applet {
    public void paint(Graphics g){
      g.setColor(Color.blue);
      g.drawString("test",20,20);
    }
    }
      

  3.   

    不好意思,原来ie中看不到,用java来调用就可以了,真奇怪
    import java.awt.*;
    import java.awt.geom.*;
    public class testapplet extends java.applet.Applet {
    public void paint(Graphics g){
      Ellipse2D.Float shape;
      GradientPaint gp;
      // create a Graphics2D
      Graphics2D g2 = (Graphics2D)g;
      // create a Ellipse2D (x,y,w,h)
      shape = new Ellipse2D.Float(200,200,60,60);
      // create a Cyclic GradientPaint 
      // (x1,y1,color1,x2,y2,color2, boolean cyclic)
      gp = new GradientPaint(180,190,Color.yellow,220,210,Color.red,true);
      g2.setPaint(gp);
      g2.fill(shape);
    }

    public static void main(String args[]) {
    Frame f = new Frame("Pie");
    testapplet p = new testapplet();
    f.add("Center",p);
    f.resize(512,512);
    f.show();
    }
    }