问题 填空题

下列JApplet实现了一个不可编辑的JTextArea和一个JButton。请填写正确的程序代码。 import javax.swing.*; import java.awt.*; public class Testl7 extends JApplet { JTextArea jta; public void init() {Container cp=getContentPane();cp.setLayout(new GridLayeut(2,1));jta=new JTextArea(30,30);jta.setEditable(true); 【15】 jta.setText(“你好”);JButton jb=new JButton ("Ok");cp.add(jb); } }

答案

参考答案:cp.add(jta)

解析: 在JApplet中添加构件就是在内容面板中添加构件,因此需要先得到内容面板,然后再向其中添加Swing构件。

问答题
单项选择题 案例分析题