//folder: d
//Programmer: ericfox
//date: 01/2004import java.Applet.Applet;
import jave.awt.*;
 public class FontsApplet extends Applet
{// creat two label components
Label lblName= new Label("ericfox");
Label lilPhone= new Label("555-1111");
// creat two fonts
Font fntName= new Font("Serif",Font.ITALIC,14);
Font fntPhone= new Font("Sans Serif",Font.BOLD,12);
  public void init()
  {  // set colors and font;add labels
setBackground(Color.cyan);
lblName.setFont(fntName);
add(lblName);
lblPhone.setFont(fntPhone);
lblPhone.setForeground(Color.red);
add(lblPhone);
  }
}
我后来没有用JB来RUN, 直接用JDK来编译,但是还是提示有错误,而且错误更多了?跟JDK的版本有关? 我用的是教程自带光盘的JDK1.3.1啊!谢谢了!

解决方案 »

  1.   

    你的程序错误真多.呵呵
    import javax.swing.*;
    import java.awt.*;
     public class FontsApplet extends JApplet
    {// creat two label componentsJLabel lblName= new JLabel("ericfox");
    JLabel lblPhone= new JLabel("555-1111");
    // creat two fonts
    Font fntName= new Font("Serif",Font.ITALIC,14);
    Font fntPhone= new Font("Sans Serif",Font.BOLD,12);
      public  void init()
      {  // set colors and font;add labels
    setBackground(Color.cyan);
    lblName.setFont(fntName);
    add(lblName);
    lblPhone.setFont(fntPhone);
    lblPhone.setForeground(Color.red);
    add(lblPhone);
      }
      public static void main(String[] args){
       //做自己的事情
       
      }
    }
      

  2.   

    按照楼上师兄给的代码编译的确通过了,谢谢!但是为什么我按照教程上的代码就是错的呢能给小弟讲讲以下几句吗?
    1:import java.Applet.Applet;   改为 import javax.swing.*;为什么要用这个包的类呢?
    2:为什么是JApplet 而不是Applet?
    谢谢了!
      

  3.   

    呵呵,可以认为swing 是awt的升级版本.也就是说jdk1.2以上的版本就有swing了.但是还有许多类包涵在awt里,(至少我这么认为)况且你原来的程序继承的是Applet.我使用的你程序的时候在Jdk13下运行的.也就是要改成符合jdk1.3要求的规范!去继承swing中的JApplet类!
    不知道我说的清楚不.讲究一下吧.呵呵.我语言表达能力不是很强.好运!