问题
单项选择题
阅读下面Applet程序import javax. swing. *;import java. awt. *; public class SwintgApplet extends JApplet{ JLabel 1=new JLabel("This is a Swing Applet."); public void init(){ ________________________________ } } 在程序下画线处填入正确的选项是
A.Container contentPane=getContenPane(); cotentPan add(1);
B.JPanel comtenPane=new Jpane(); contentPan add(1);
C.contentPan add(1);
D.add(1);
答案
参考答案:A
解析: 不能直接调用add方法将“1”标签加到JApplet对象上,而要先调用JApplet类的getContentPane()方法获得此applet的eontentPane对象,然后再调用add方法将“1”标签对象加到此contentPane对象上。