|
该文章原出处 懒刺猬的BLOG 地址:http://blog.sina.com.cn/u/1224649382
31.
import java.awt.*; public class X extends Frame{ public static void main(String[] args){ X x=new X(); x.pack(); x.setVisible(true);} public X(){ setLayout(new GridLayout(2,2)); Panel p1=new Panel(); add(p1); Button b1=new Button("One"); p1.add(b1); Panel p2=new Panel(); add(p2); Button b2=new Button("Two"); p2.add(b2); Button b3=new Button("Three"); p2.add(b3); Button b4=new Button("Four"); add(b4); } } when the frame is resized, A.all change height B.all change width C.Button "One" change height D.Button "Two" change height E.Button "Three" change width F.Button "Four" change height and width
题意: 当frame改变大小时,
分析: Window类及其继承类Fram、Dialog默认的布局管理器都是BorderLayout。而Panel及其继承类Applet的默认管理器都是FlowLayout。与考试有关的布局管理器还有GridLayout。相关内容请参照教材。
解答: F
注意: 需要说明的是如果使用绝对定位控制组件的位置,需要setLayout(null),不然设置组件大小和位置都不会起作用。
示例: w31.java
32. 1)public class X{ 2) public static void main(String[] args){ 3) String foo="ABCDE"; 4) foo.substring(3); 5) foo.concat("XYZ"); 6) } 7) } what is the value of foo at line 6?
题意: 第6行的foo的值是什么?
分析: 考察String类,大纲中对String类和StringBuffer类的要求比较明确,所以在此把这两个类总结一下。
String的构造器:String(),创建一个空对象; String(byte[] bytes),用一个byte数组创建一个对象; String(byte[] bytes, String charsetName) ,用bytes数组创建一个用charseName 指定的字符集的对象; String(byte[] bytes, int offset, int length),用bytes数组的第offset到 第offset+length的子串创建一个对象; String(byte[] bytes, int offset, int length, String charsetName),用bytes数 组的第offset到第offset+length的子串创建一个用charseName指定 的字符集的对象; String(char[] value),创建一个值等于字符串value的对象; String(char[] value, int offset, int count),从value字符串中第offset个位置 截取count个字符创建一个对象; String(String original),用original对象的值创建一个新的对象 String(StringBuffer buffer),用buffer对象的值创建一个新的对象。
StringBuffer的构造器: StringBuffer(),创建一个值为空的对象; StringBuffer(int length),创建一个值为空容量为length的对象; StringBuffer(String str),用str的值创建一个对象。
String的方法:常用的有,charAt()、compareTo()、concat()、replace()、substring()、toLowCase()、toUpperCase()、endsWhith()、startWhith()、indexOf()、length()、equalsIgnoreCase()、contentEquals()、split()、copyValueOf()、trim()、valueOf()、getBytes()、getChars()等
StringBuffer的方法:常用的有,append()、capacity()、charAt()、delete()、deleteCharAt()、 ensureCapacity()、getChars()、indexOf()、insert()、 lastIndexOf()、length()、replace()、reverse()、 setCharAt()、setLength()、substring()等
解答: ABCDE
注意: "XYZ"是字符串还是String对象呢?用"XYZ".getClass().getName()。看一下就知道了。
示例: w32.java |