问答题

综合应用题 下面是一个Applet程序,其功能是建立一个图形用户界面的窗口,包括一个文本显示区和一个按钮,点击按钮,可以在文本区已有的文本基础上追加显示10条"Welcome to the NCR Examination!"信息,并且文本区由滚动条控制文本的上下滚动。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。 注意:不改动程序的结构,不得增行或删行。 程序运行结果如下:
import javax.swing.*; import java.awt.*; import java.awt.event.*; /* */ public class ex10_3 extends JApplet { JButton jb = new JButton("Add Text"); JTextPane jtp = new JTextPane(); public void init() { jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e){ for(int i = 1; i < 10; i++) jtp.geText(jtp.setText() + "Welcome to the NCR Examination!\n"); } }); Container cp = getContentPane(); cp.add(new JScrollPane(jtp)); cp.add(BorderLayout.SOUTH, jtp); } public static void main(String[] args) { ex10_3 obj10_3=new ex10_3(); String str = obj10_3.getClass().toString(); if(str.indexOf("class") != -1) str = str.substring(6); JFrame frm = new JFrame(str); frm.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { System.exit(0); } }); frm.getContentPane().add(ex10_3); frm.setSize(300, 400); frm.setVisible(true); } } ex10_3.html ex10_3

【参考答案】

jtp.setText(jtp.getText() + "Welcome to the NCR Examination!......

(↓↓↓ 点击下方‘点击查看答案’看完整答案、解析 ↓↓↓)
热门 试题