51Testing软件测试论坛
标题:
考试题目,帮帮忙啊!!!
[打印本页]
作者:
金针菇
时间:
2006-6-28 22:24
标题:
考试题目,帮帮忙啊!!!
1.写出〈〈 〉〉尖括号内代码的作用(已知原始图片像素大小:宽192*高96)
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
public class TiledCanvas extends GameCanvas {
private Image titledImage;
private Graphics g;
private TiledLayer background;
①<<private byte[][] titledMap = { {1,2,3},
{4,5,6},
{7,8,9},
{7,7,7},
{7,7,7},
{7,7,7}};>>
protected TiledCanvas() {
super(true);
try {
titledImage = Image.createImage("/title1.png");
} catch (Exception e) { }
g = this.getGraphics();
②<<background = new TiledLayer(3,6,titledImage,64,32);>>
for(int i=0;i<6;i++)
for(int j=0;j<3;j++){
③<<background.setCell(j,i,titledMap[j]);>>
}
④<<background.paint(g);
flushGraphics();>>
}
}
答:
①
②
③
④
2.写出〈〈 〉〉尖括号内代码的作用(已知原始图片像素大小:宽96*高192)
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
public class SpriteCanvas extends GameCanvas implements Runnable{
private int drawX = 0;
private int drawY = 0;
private Sprite sprite;
private Image spriteImage;
private Graphics g;
①〈〈private int down_seq[] = {0,1,2}; 〉〉
protected SpriteCanvas() {
super(true);
try{
spriteImage = Image.createImage("/man.png");
}catch(Exception e){}
②〈〈sprite = new Sprite(spriteImage,32,48);
sprite.setFrameSequence(down_seq);〉〉
g = this.getGraphics();
Thread thread = new Thread(this);
thread.start();
}
public void run() {
while(true){
try {
③〈〈Thread.sleep(100);〉〉
} catch (InterruptedException e) {
e.printStackTrace();
}
g.setColor(255,255,255);
g.fillRect(0,0,getWidth(),getHeight());
④〈〈sprite.nextFrame();〉〉
if(drawY + 5 < getHeight()){
drawY = drawY +5;
sprite.setPosition(drawX,drawY);
}
else{
drawY = 0;
sprite.setPosition(drawX,drawY);
}
sprite.paint(g);
flushGraphics();
}
}
}
答:
①
②
③
④
3.简述Comparator类所起的作用,写出程序运行的结果。
import javax.microedition.midlet.*;
import javax.microedition.rms.*;
public class RecordSort extends MIDlet {
private RecordStore rs=null;
static final String REC_STORE="db_1";
public RecordSort() {
openRecStore();
writeRecord("Shanghai");
writeRecord("SiChuan");
writeRecord("ChengDu");
writeRecord("BeiJing");
readRecords();
closeRecStore();//关闭RecordStore
deleteRecStore();//删除RecordStore
}
public void openRecStore(){
try{
//如果RecordStore不存在,就创建新的
rs=RecordStore.openRecordStore(REC_STORE,true);
}catch (Exception e){
db(e.toString());
}
}
public void readRecords(){
try{
if(rs.getNumRecords()>0){
Comparator comp=new Comparator();
RecordEnumeration re=rs.enumerateRecords(null,comp,false);
while(re.hasNextElement()){
String str=new String(re.nextRecord());
System.out.println(str);
System.out.println("-----------------------");
}
}
}catch(Exception e){
db(e.toString());
}
。。。代码略
}
class Comparator implements RecordComparator{
public int compare(byte[] rec1,byte[] rec2){
String str1=new String(rec1);
String str2=new String(rec2);
int result=str1.compareTo(str2);
if(result==0)
return RecordComparator.EQUIVALENT;
else if(result<0)
return RecordComparator.PRECEDES;
else
return RecordComparator.FOLLOWS;
}
}
}
4.阅读代码写出程序运行结果
如果解除三行代码的注释,这三行代码的运行结果是什么?
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class translateOrigin extends MIDlet implements CommandListener {
private Command exitCommand;
private translateOriginCanvas sg;
public translateOrigin() {
exitCommand = new Command("Exit", Command.EXIT, 1);
sg = new translateOriginCanvas();
sg.addCommand(exitCommand);
sg.setCommandListener(this);
Display.getDisplay(this).setCurrent(sg);
}
protected void startApp() { }
protected void pauseApp() { }
protected void destroyApp(boolean arg0) { }
public void commandAction(Command c, Displayable d) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
}
}
class translateOriginCanvas extends Canvas {
protected void paint(Graphics g) {
for (int i = 1; i <= 5; i++) {
g.drawString("String--"+ String.valueOf(i), 0, 0, Graphics.TOP |
Graphics.LEFT);
g.translate(20,20);
}
/*①String s = String.valueOf(g.getTranslateX());
②g.translate(-100,-100);
③g.drawString(s,0,0,Graphics.TOP | Graphics.LEFT);
*/
}
}
作者:
cr19800604
时间:
2006-6-29 11:15
不好意思,这些题目不会做,我要努力了;
后2题可以在运行环境中解决阿
作者:
Chenny
时间:
2006-6-29 11:26
hehe 努力
[
本帖最后由 Chenny 于 2006-6-29 11:27 编辑
]
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2