📄 myplay.java~197~
字号:
package AddressBook;
import javax.microedition.lcdui.*;
//import javax.microedition.lcdui.game.*;
import java.util.*;
import javax.microedition.rms.*;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2008</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class Myplay extends Canvas implements Runnable {
private Image image;
private Random r;
RecordStore rs; //声明记录存储
int nextreid=0;
String word_str=null; //声明单词变量
String mean_str=null; //声明单词意思变量
String str=null; //声明填词的单词变量
int x=0;
int y=0;
int chengji=0;
char wd='a';
char[] a;
int ram;
String word_show=""; //声明显示单词变量
public Myplay() {
try {
jbInit();
rs=RecordStore.openRecordStore("word",true);
System.out.print("打开记录");
nextreid=rs.getNextRecordID();
System.out.println(nextreid);
Thread t=new Thread(this);
t.start();
close();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
// Set up this Displayable to listen to command events
// add the Exit command
addCommand(new Command("Exit", Command.EXIT, 1));
}
protected void paint(Graphics g) {
/** @todo Add paint codes */
g.setColor(250,250,250);
int x1=this.getWidth();
int y1=this.getHeight();
g.fillRect(0,0,x1,y1);
try{
image=Image.createImage("//image/aa.jpg");
g.drawImage(image,0,0,g.LEFT|g.TOP);
g.setColor(0,0,0);
// g.setStrokeStyle(10);
g.drawRect(5+x,199+y,30,21);
g.setColor(255,0,0);
g.drawString(String.valueOf(chengji),100,50,g.LEFT|g.TOP);
g.drawString(word_show,200,180,g.LEFT|g.TOP);
g.drawString(mean_str,180,50,g.LEFT|g.TOP);
}catch(Exception e){}
}
public void keyPressed(int key){ //判断按键按下
System.out.println(this.getKeyName(key)+"键被按下");
int keycode=this.getGameAction(key);
System.out.println(keycode);
switch(keycode){
case Canvas.UP:y-=22;wd-=7;System.out.println(wd);repaint(); break;
case Canvas.DOWN:y+=22;wd+=7;System.out.println(wd);repaint();break;
case Canvas.LEFT:x-=33;wd-=1;System.out.println(wd);repaint();break;
case Canvas.RIGHT:x+=33;wd+=1;System.out.println(wd);repaint();break;
case Canvas.FIRE:if(wd==a[ram]){chengji+=10;repaint();x=0;y=0;wd='a';word_show="";repaint();repaint(); break;}
else {chengji-=10;repaint();break;}
}
}
public void keyReleased(int key){ //判断按键放开
System.out.print(this.getKeyName(key)+"键被放开");
}
public void run(){
while(true){
r=new Random();
int ra=r.nextInt(nextreid);
System.out.println(nextreid);
System.out.println(ra);
System.out.println("你好啊");
try{
String str1=new String(rs.getRecord(ra));
word_str=str1.substring(0,str1.indexOf("#"));
System.out.print(word_str);
mean_str=str1.substring(str1.indexOf("#")+1,str1.indexOf("?"));
System.out.print(mean_str);
int l=word_str.length();
a=word_str.toCharArray();
Random rr=new Random();
ram=rr.nextInt(l);
for(int i=0;i<l;i++){
if(i==ram) {
word_show+='?';
}
else
word_show+=a[i];
}
}
catch(Exception e) {
e.printStackTrace();
}
repaint();
serviceRepaints();
try{
Thread.sleep(10000);}catch(Exception e){}
}
}
public void close()throws RecordStoreNotOpenException,RecordStoreException{
rs.closeRecordStore();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -