141.public class Java_1{public static void main(String[] args){//*********Found********String[] awt = new ______[3];awt[0] = "Abstract";awt[1] = "Window";awt[2] = "Tool kit";for (int i = 0; i < 3; i++)//*********Found********System.out.println(______);}}1)String2)填"awt[i]"2.public class Java_2 implements ActionListener{ Frame f;Button b;TextField tf;public Java_2(){f = new Frame("Show Date");//*********Found********______(new FlowLayout());f.setSize(300,100);//注册关闭窗口的监听器f.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){System.exit(0);}});b = new Button("显示当前日期");//*********Found********______(this);tf = new TextField(30);f.add(b);f.add(tf);f.setVisible(true);}public static void main(String[] args) {Java_2 t = new Java_2();}public void actionPerformed(ActionEvent e){Date d = new Date(); //获取当前日期。
tf.setText(d.toString());}}填"f.setLayout",填"b.addActionListener"。
具体程序如下:3.import java.awt.*;import java.awt.event.* ;//*********Found********public class Java_3 ______ ActionListener{public static void main(String args[ ]){Java_3 tb = new Java_3();Frame f = new Frame("Button Test");f.setSize(200,100);f.setLayout(new FlowLayout(FlowLayout.CENTER));Button b = new Button("Press the Button!");//*********Found********b.______(tb);f.add(b);f.setVisible(true) ;}public void actionPerformed(ActionEvent e){Frame fr = new Frame("An Other");fr.setBackground(Color.green);fr.add(new Label("This frame shows when "+"pressing the button in Button Test"));fr.pack();fr.setVisible(true) ;}}填"implements",填"addActionListener"。
151. import javax.swing.JOptionPane;public class Java_1{public static void main( String args[] ){String output = "";int count;//*********Found********for(count=1;count<=10; ______){//*********Found********if(count______)break; // 当count为5时跳出循环output += count + " ";}output += "\nBroke out of loop at count = " + count;JOptionPane.showMessageDialog( null, output );System.exit( 0 );}}即"count++"或"++count",填">=5"或">4"。
2. import java.io.*;public class Java_2{public static void main(String[] args) {//*********Found********int[] anArray=______; // 声明并创建包含10个元素的整型数组。
int i = 0;int total=0;try{// 从data.dat中读出10个整数,放在整型数组中。
DataInputStream in = new DataInputStream(new FileInputStream("data.dat"));while(in.available() != 0){//*********Found********anArray[i++]=in.______;}in.close();//将整型数组中的10个整数相加,并将这些数及其和显示输出。
System.out.print("Numbers: ");for( i = 0; i < anArray.length; i++){total = total+anArray[i];if( i<anArray.length - 1 ){System.out.print(anArray[i]);System.out.print(',');}else{System.out.println(anArray[i]);}}System.out.println("Total: "+total);}catch(IOException e1){}}}填"new int[10]"。
填"readInt()"。
3. import java.awt.*;import java.awt.event.*;//*********Found********import javax.______.*;import java.io.*;public class Java_3{public static void main(String[] args){ExceptTestFrame frame = new ExceptTestFrame();frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setVisible(true);}}class ExceptTestFrame extends JFrame{public ExceptTestFrame(){setTitle("ExceptTest");Container contentPane = getContentPane();ExceptTestPanel panel = new ExceptTestPanel();contentPane.add(panel);pack();}}class ExceptTestPanel extends Box{public ExceptTestPanel(){super(BoxLayout.Y_AXIS);group = new ButtonGroup();addRadioButton("Integer divide by zero", newActionListener(){public void actionPerformed(ActionEvent event){a[1] = 1 / (a.length - a.length);}});textField = new JTextField(30);//*********Found********add(______);}private void addRadioButton(String s, ActionListener listener){JRadioButton button = new JRadioButton(s, false){protected void fireActionPerformed(ActionEvent event){try{//*********Found********textField.______("No exception");super.fireActionPerformed(event);}catch (Exception exception){textField.setText(exception.toString());}}};button.addActionListener(listener);add(button);group.add(button);}private ButtonGroup group;private JTextField textField;private double[] a = new double[10];}填"swing"。
填"textField"。
填"setText"。
161. class Variable{int x=0,y=0,z=0;void init(int x,int y){//*********Found********______=x;this.y=y;int z=5; //局部变量System.out.println("*****在初始化中*****");System.out.println("x = "+x+" y = "+y+" z ="+z);}}public class Java_1{public static void main (String[] args){//*********Found********Variable v = new ______;System.out.println("*****在初始化之前*****");System.out.println("x = "+v.x+" y = "+v.y+" z ="+v.z);v.init(20,30);System.out.println("*****在初始化之后*****");System.out.println("x = "+v.x+" y = "+v.y+" z ="+v.z);}}填"this.x",填"Variable()"。