主观

●试题六

【说明】

下面是一个Applet程序,其功能是建立2个文本区域,一个为编辑区,一个为只读区;建立2个按钮,一个实现将编辑区中被鼠标选定的文本内容拷贝到只读区中,一个实现将只读区的全部文本内容清空。

程序运行结果如图3所示。

 图3

import javA.awt.*;

import javA.applet.*;

/*

*/

public class ex3_6 extends Applet{

private Button okBtn, clearBtn;

private String strMessage;

private TextArea tArea1, tArea2;

public void init(){

strMessage = "Hello! Welcome to the test!\n" +

"Wish you good luck!";

tArea1 = new TextArea( 10, 25 );

 (1) ;

tArea2 = new TextArea( 10, 25 );

 (2) ;

okBtn = new Button( "Copy" );

clearBtn = (3) ;

add( tArea1 );

add( tArea2 );

add( okBtn );

add( clearBtn );

}

public boolean action( Event e, Object o ){

if( e.target == okBtn )

tArea2.setText( (4) );

else if( e.target == clearBtn )

 (5) ;

return true;

}

}

ex3_6.html

ex3_6

   code="ex3_6.class" width=800 height=400 >

 

参考答案
您可能感兴趣的试题

●试题四

阅读下列程序说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。

【程序4.1说明】

"背包问题"的基本描述是:有一个背包,能盛放的物品总重量为S,设有N件物品,其重量分别为w1,w2,...,wn,希望从N件物品中选择若干件物品,所选物品的重量之和恰能放入该背包,即所选物品的重量之和等于S。

如下程序均能求得"背包问题"的一组解,其中程序4.1是"背包问题"的递归解法,而程序4.2是"背包问题"的非递归解法。

【程序4.1】

#include

#define N 7

#define S 15

int w[N+1]={0,1,4,3,4,5,2,7};

int knap(int s,int n)

{ if(s==0)return 1;

if (s<0||(s>0& &n<1))return 0;

if( (1) )){

printf(″%4d″,w[n]);return 1;

}return (2) ;

}

main(){

if( knap(S,N))printf(″OK!\n″);

else printf(″N0!\n″);

}

【程序4.2】

#include

#define N 7

#define S 15

typedef struct {

int s;

int n:

int job;

} KNAPTP;

int w[N+1]={0,1,4,3,4,5,2,7};

int knap (int s,int n);

main( ) {

if (knap (S,N)) printf (″OK!\n″);

else printf (″NO!\n″);}

int knap (int s,int n)

{ KNAPTP stack[100],x;

int top,k,rep;

x.s=s;x.n=n;

x.job=0;

top=l;stack[top]=x;

k=0;

while( (3) ) {

x=stack [ top ];

rep=1;

while ( !k && rep ) {

if (x.s==0)k=1;/*已求得一组解*/

else if (x.s<0 || x.n<=0)rep=0;

else{x.s= (4) ;x.job=1;

 (5) =x;

}

}

if(!k){

rep=1;

while(top>=1&&rep){

x=stack[top--];

if(x.job==1){

x.s+=w[x.n+1];

x.job=2;

stack[++top]=x;

 (6) ;

}

}

}

}

if(k){/*输出一组解*/

while(top>=1){

x=stack[top--];

if(x.job==1)

printf(″%d\t″,w[x.n+1]);

}

}

return k;

}

¥

订单号:

遇到问题请联系在线客服

订单号:

遇到问题请联系在线客服