锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
import javax.microedition.rms.InvalidRecordIDException;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
import javax.microedition.rms.RecordStoreFullException;
import javax.microedition.rms.RecordStoreNotFoundException;
import javax.microedition.rms.RecordStoreNotOpenException;
public class RecordStoreUtil {
public RecordStore openARecondStore(String rsname){
RecordStore rs=null;
if(rsname.length()>32) return null;
try{
rs=RecordStore.openRecordStore(rsname,true);
}catch(RecordStoreFullException notFoundException){
}catch(RecordStoreNotFoundException notFoundException){
}catch(RecordStoreException notFoundException){
}finally{
return rs;
}
}
public RecordStore openARecordStoreExisted(String rsname){
RecordStore rs=null;
if(rsname.length()>32)return null;
try{
rs=RecordStore.openRecordStore(rsname,false);
}catch(RecordStoreFullException notFoundException){
}catch(RecordStoreNotFoundException notFoundException){
}catch(RecordStoreException notFoundException){
}finally{
return rs;
}
}
//鍒犻櫎
public static boolean delRecordStore(String rsname){
//
if(rsname.length()>32)return false;
//
try{
RecordStore.deleteRecordStore(rsname);
}catch(Exception e){
return false;
}
return true;
}
//娣誨姞
public static int writeString(RecordStore rs,String myString){
byte[] b=myString.getBytes();
int id=-1;
try{
id=rs.addRecord(b, 0, b.length);
}catch(Exception e){
//
}
return id;
}
//鑾峰彇
public static String getString(RecordStore rs,int id){
try {
byte[] b = rs.getRecord(id);
return (new String(b));
} catch (RecordStoreNotOpenException ex) {
ex.printStackTrace();
} catch (InvalidRecordIDException ex) {
ex.printStackTrace();
} catch (RecordStoreException ex) {
ex.printStackTrace();
}
return null;
}
//淇敼
public static void setString(RecordStore rs,int id,String newString){
byte[] b=newString.getBytes();
try {
rs.setRecord(id, b, 0, b.length);
} catch (Exception ex) {
}
}
//娣誨姞璇佷功鏁版嵁璁板綍
public static int writeInt(RecordStore rs,int myInt){
int id=-1;
String myString=(new Integer(myInt)).toString();
id=writeString(rs,myString);
return id;
}
//鑾峰彇
public static int getInt(RecordStore rs,int id){
int result=Integer.MAX_VALUE;
String s=getString(rs,id);
try{
result=Integer.parseInt(s);
}catch(Exception e){
}
return result;
}
//淇敼
public static void setInt(RecordStore rs,int newInt){
String myString=(new Integer(newInt)).toString();
}
}
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class GraphicsTest extends MIDlet{
private Display display;
public GraphicsTest() {
display=Display.getDisplay(this);
}
protected void destroyApp(boolean unconditional) {
}
protected void pauseApp() {
}
protected void startApp(){
MyCanvas mc=new MyCanvas();
display.setCurrent(mc);
}
}
class MyCanvas extends Canvas {
public void paint(Graphics g){
int width=getWidth();
int height=getHeight();
String a[]={"闈欏鎬?,"鏉庣櫧","搴婂墠鏄庢湀鍏?,"鐤戞槸鍦頒笂闇?,"涓懼ご鏈涙槑鏈?,"浣庡ご鎬濇晠涔?};
g.setColor(0);
g.fillRect(0, 0, width, height);
g.setColor(0Xffff00);
Font font=g.getFont();
font=Font.getFont(Font.FACE_PROPORTIONAL,Font.STYLE_UNDERLINED,Font.SIZE_LARGE);
g.setFont(font);
for(int i=0;i<a.length;i++){
g.drawString(a[i], 0, i*20,Graphics.LEFT|Graphics.BASELINE );
}
}
}
//--------------------------------------------------------------------------------------------
鍒╃敤縐誨姩鍘熺偣鍧愭爣鍔ㄨ搗鏉ヤ箣鍚庣殑闈欏鎬?br />
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class GraphicsTest extends MIDlet{
private Display display;
public GraphicsTest() {
display=Display.getDisplay(this);
}
protected void destroyApp(boolean unconditional) {
}
protected void pauseApp() {
}
protected void startApp(){
MyCanvas mc=new MyCanvas();
display.setCurrent(mc);
}
}
class MyCanvas extends Canvas {
int aa=300;
MyCanvas(){
Walk w = new Walk();
w.start();
}
public void paint(Graphics g){
int width=getWidth();
int height=getHeight();
String a[]={"闈欏鎬?,"鏉庣櫧","搴婂墠鏄庢湀鍏?,"鐤戞槸鍦頒笂闇?,"涓懼ご鏈涙槑鏈?,"浣庡ご鎬濇晠涔?};
g.setColor(0);
g.fillRect(0, 0, width, height);
g.setColor(0Xffff00);
g.translate(80,aa);
Font font=g.getFont();
font=Font.getFont(Font.FACE_PROPORTIONAL,Font.FACE_SYSTEM,Font.SIZE_LARGE);
g.setFont(font);
for(int i=0;i<a.length;i++){
g.drawString(a[i], 0, i*20,20);
}
}
class Walk extends Thread{
public void run(){
while(aa>80){
aa--;
repaint();
try{
sleep(50);
}catch(Exception ee){}
}
}
}
}
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class GraphicsTest extends MIDlet{
private Display display;
public GraphicsTest() {
display=Display.getDisplay(this);
}
protected void destroyApp(boolean unconditional) {
}
protected void pauseApp() {
}
protected void startApp(){
MyCanvas mc=new MyCanvas();
display.setCurrent(mc);
}
}
class MyCanvas extends Canvas {
public void paint(Graphics g){
int width=getWidth();
int height=getHeight();
g.setColor(0);
g.fillRect(0, 0, width, height);
int a=width/5;
int b=height/5;
g.setColor(0Xffff00);
for(int i=1;i<=4;i++){
g.drawLine(a,0 ,a,height);
g.drawLine( 0,b, width,b);
a=a+width/5;
b=b+height/5;
} g.drawArc(0, 0, width, height, 0, 360);
}
}
public class SimpleCanvas extends MIDlet{
private Display display;
public SimpleCanvas() {
display=Display.getDisplay(this);
}
protected void destroyApp(boolean unconditional) {
}
protected void pauseApp() {
}
protected void startApp(){
MyCanvas mc=new MyCanvas();
display.setCurrent(mc);
}
}
class MyCanvas extends Canvas {
public void paint(Graphics g){
g.setColor(0,0,0);
g.fillRect(0,0,getWidth(),getHeight());
g.setColor(255, 255,255);
g.drawString("浣犲ソ,嫻嬭瘯", 100, 100, 0);
}
}