applet访问本地文件是不允许的,这是java的规定
,不过你可以通过一些安全选项的设置可以
不过你j2se上就没有问题,这说明你的程序调用方式没有错误

解决方案 »

  1.   

    java.lang.Object
      |
      +--java.awt.Component
            |
            +--java.awt.Buttonjava.lang.Object
      |
      +--java.awt.Component
            |
            +--java.awt.Container
                  |
                  +--javax.swing.JComponent
                        |
                        +--javax.swing.AbstractButton
                              |
                              +--javax.swing.JButton
      

  2.   

    ImageIcon中你可用ToolKit.createIamge();
    另外你的站点的安全权限及保证图片已加载完成。必要的话声明IMageTracker
      

  3.   

    建议你都改为swing的,JApplet,JButton.
      

  4.   

    还有一点忘了,this.add要改为this.getContentPane.add。
      

  5.   

    呵呵 你为什么不用JAPPLET呢 那个比较好 现在 能用SWING就用SWING 。AWT的API已经不发展拉
      

  6.   

    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import javax.swing.*;public class applet7 extends Applet {
      private boolean isStandalone = false;
      JButton one=new JButton();
      JButton two=new JButton();
      ImageIcon img1,img2;
      public applet7() {
      }  public void init() {
        try {
          jbInit();
          this.setLayout(null);
          this.add(one);
          this.add(two);
          one.setBounds(200,0,100,40);
          two.setBounds(300,0,100,40);
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      private void jbInit() throws Exception {
        img1=new ImageIcon(this.getClass().getResource("1.gif"));
        img2=new ImageIcon(this.getClass().getResource("2.gif"));
        one.setIcon(img1);
        two.setIcon(img2);
        one.setText("提交");
        two.setText("按钮");
      }
    }
      

  7.   

    如下可以在JButton和Button上放置图标:
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import javax.swing.*;public class applet7 extends Applet {
      private boolean isStandalone = false;
      JButton one=new JButton();
      button two=new button();
      ImageIcon img1,img2;
      public applet7() {
      }  public void init() {
        try {
          jbInit();
          this.setLayout(null);
          this.add(one);
          this.add(two);
          one.setBounds(200,0,100,40);
          two.setBounds(300,0,100,40);
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      private void jbInit() throws Exception {
        img1=new ImageIcon(this.getClass().getResource("1.gif"));
        img2=new ImageIcon(this.getClass().getResource("2.gif"));
        one.setIcon(img1);
        one.setText("提交");
        two.setLabel("按钮");
      }  class button extends Button {
        public void paint(Graphics g) {
          g.drawImage(img2.getImage(),this.getWidth()/2-img2.getIconWidth()/2,this.getHeight()/2-img2.getIconHeight()/2,this);
        }
      }
    }