问答题

本程序是一个Applet,它的功能是在窗口上添加12×12个标签,并且标签的颜色为黑白相间(横向和纵向都是黑白相间的),如图所示。


import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class exam_75 extends Applet
{ GridLayout grid;
public void init()
{ grid=new GridLayout(12,12);
setLayout(grid);
Label ______ =new Label[12] [12];
for(int i=0;i<12;i++)
{ for(int j=0;j<12;j++)
{ label [i] [j]= ______;
if ((i+j) %2==0)
label[i] [j].setBackground(Color.black);
else
label [i] [j] .setBackground (Color .white);
add(label[i][j]);
}
}
}
}
exam_75.html:
<html>
<head><title>exam_75</title></head>
<body>
<applet code="exam_75.class" width="400" height="500">
</applet>
</body>
</html>

【参考答案】

第1处:label[][]
第2处:new Label()
热门 试题

问答题
本程序的功能是对下拉菜单项的操作,包括添加和删除。页面中包括一个下拉菜单、一个文本框和两个按钮(“删除”和“添加”),选中下拉菜单的一项后,可以通过“删除”按钮从下拉菜单中删除该项,在文本框中填入字符串后,单击“添加”按钮就可以将该项添加到下拉菜单中,所有这些信息都将显示在右侧的文本域中,如图所示。import java. awt. *;import java.awt.event.*;public class exam_77 extends java.applet.Applet implements ItemListener,ActionListener{ Choice choice;TextField text;TextArea area;Button add, del;public void init(){ choice=new Choice();text=new TextField(8);area=new TextArea(6,15);choice.add( 音乐天地 );choice.add( 武术天地 );choice.add( 象棋乐园 );choice.add( 交友聊天 );add=new Button( 添加 );del=new Button( 删除 );add.addActionListener(this);del.addActi0nListener(this);choice.addItemListener(this);add(choice);add(del);add(text);add(add);add(area);}public void itemStateChanged(ItemEvent e){ String name= ______;int index=choice.getSelectedIndex();area.setText( n +index+ : +name);}public void actionPerformed(ActionEvent e){ if(e.getSource()==add||e.getSource()==text){ String name=text.getText();if(name.length()>0){ choice.add(name);choice.select(name);area.append( n添加 +name);}}else if(e.getSource()==del){ choice.remove(______);area.append( n删除 +choice.getSelectedItem());}exam_77.html:<html><head><title>exam_77< title>< head><body><applet code= exam_77.class width= 400 height= 500 >< applet>< body>< html>