没有访问权限
时间:2008-06-19 14:27:07
来源:论坛整理 作者: 编辑:chinaitzhe
1、BiorhythmCanvas.java
import java.io.*;
import java.util.Date;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
public final class BiorhythmMIDlet extends MIDlet
implements CommandListener //,ItemStateListener
{
public BiorhythmMIDlet()
{
super();
canvas = new BiorhythmCanvas();
canvas.addCommand(exitCmd);
canvas.addCommand(showBirthCmd);
canvas.setCommandListener(this);
form = new BiorhythmForm("生日");
form.addCommand(birthOKCmd);
form.addCommand(birthCancelCmd);
form.setCommandListener(this);
}
public void startApp()
{
readDate();
if( date == null)
{
Display.getDisplay(this).setCurrent(form);
}
else
{
canvas.setBirthday(date);
Display.getDisplay(this).setCurrent(canvas);
}
}
public void pauseApp()
{
}
public void destroyApp(boolean flag)
{
}
public void commandAction(Command c,Displayable d)
{
if (c== exitCmd)
{
notifyDestroyed();
}
else if ( c == showBirthCmd )
{
form.setDate(date);
Display.getDisplay(this).setCurrent(form);
}
else if ( c== birthOKCmd)
{
date = form.getDate();
if (date == null) return;
canvas.setBirthday(date);
saveDate();
Display.getDisplay(this).setCurrent(canvas);
}
else if (c == birthCancelCmd)
{
Display.getDisplay(this).setCurrent(canvas);
}
}
private void saveDate()
{
byte abyte0[];
if (date == null)
return;
abyte0 = null;
try
{
ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
DataOutputStream dataoutputstream = new DataOutputStream(bytearrayoutputstream);
dataoutputstream.writeLong(date.getTime());
abyte0 = bytearrayoutputstream.toByteArray();
dataoutputstream.close();
}
catch (IOException ioexception)
{
System.err.println(ioexception);
}
if (abyte0 == null)
return;
try{
RecordStore recordstore = RecordStore.openRecordStore("Biorhythm",true);
if (recordstore == null)
return;
int cnt = recordstore.getNumRecords();
if ( cnt == 0)
{
recordstore.addRecord(abyte0,0,abyte0.length);
}
else
{
recordstore.setRecord(1,abyte0,0,abyte0.length);
}
recordstore.closeRecordStore();
} catch (RecordStoreException recordstoreexception)
{
System.err.println(recordstoreexception);
}
}
private void readDate()
{
byte abyte0[] = null;
try
{
RecordStore recordstore = RecordStore.openRecordStore("Biorhythm",false);
if (recordstore.getNumRecords() !=0)
abyte0 = recordstore.getRecord(1);
recordstore.closeRecordStore();
}
catch (RecordStoreException recordstoreexception)
{
System.err.println(recordstoreexception);
}
if (abyte0 !=null)
try
{
DataInputStream datainputstream = new DataInputStream(new ByteArrayInputStream(abyte0));
date = new Date (datainputstream.readLong());
datainputstream.close();
}
catch(IOException ioexception)
{
System.err.println(ioexception);
}
}
private Date date;
private BiorhythmCanvas canvas;
private BiorhythmForm form;
private Command exitCmd = new Command("Exit",Command.EXIT,1);
private Command showBirthCmd = new Command("Birth",Command.SCREEN,2);
private Command birthOKCmd = new Command("OK",Command.EXIT,1);
private Command birthCancelCmd = new Command("Cancel",Command.SCREEN,1);
}
网友回复:因为内容太长,就贴这儿了
2、BiorhythmForm.java
import java.util.Calendar;
import java.util.Date;
import javax.microedition.lcdui.*;
class BiorhythmForm extends Form
{
public BiorhythmForm(String str)
{
super(str);
y = new TextField("年"," ", 4, TextField.NUMERIC);
m = new TextField("月"," ", 2, TextField.NUMERIC);
d = new TextField("日"," ", 2, TextField.NUMERIC);
append(y);
append(m);
append(d);
}
public void setDate(Date date)
{
if(date != null);
{
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
y.setString(Integer.toString(calendar.get(Calendar.YEAR)));
m.setString(Integer.toString(calendar.get(Calendar.MONTH) 1));
d.setString(Integer.toString(calendar.get(Calendar.DATE)));
}
}
public Date getDate()
{
try{
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR,Integer.parseInt(y.getString()));
calendar.set(Calendar.MONTH,Integer.parseInt(m.getString()) - 1);
calendar.set(Calendar.DATE,Integer.parseInt(d.getString()));
return calendar.getTime();
}catch (Exception e )
{
return null;
}
}
protected TextField y;
protected TextField m;
protected TextField d;
}
3、BiorhythmMIDlet.java
import java.io.*;
import java.util.Date;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
public final class BiorhythmMIDlet extends MIDlet
implements CommandListener //,ItemStateListener
{
public BiorhythmMIDlet()
{
super();
canvas = new BiorhythmCanvas();
canvas.addCommand(exitCmd);
canvas.addCommand(showBirthCmd);
canvas.setCommandListener(this);
form = new BiorhythmForm("生日");
form.addCommand(birthOKCmd);
form.addCommand(birthCancelCmd);
form.setCommandListener(this);
}
public void startApp()
{
readDate();
if( date == null)
{
Display.getDisplay(this).setCurrent(form);
}
else
{
canvas.setBirthday(date);
Display.getDisplay(this).setCurrent(canvas);
}
}
public void pauseApp()
{
}
public void destroyApp(boolean flag)
{
}
public void commandAction(Command c,Displayable d)
{
if (c== exitCmd)
{
notifyDestroyed();
}
else if ( c == showBirthCmd )
{
form.setDate(date);
Display.getDisplay(this).setCurrent(form);
}
else if ( c== birthOKCmd)
{
date = form.getDate();
if (date == null) return;
canvas.setBirthday(date);
saveDate();
Display.getDisplay(this).setCurrent(canvas);
}
else if (c == birthCancelCmd)
{
Display.getDisplay(this).setCurrent(canvas);
}
}
private void saveDate()
{
byte abyte0[];
if (date == null)
return;
abyte0 = null;
try
{
ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
DataOutputStream dataoutputstream = new DataOutputStream(bytearrayoutputstream);
dataoutputstream.writeLong(date.getTime());
abyte0 = bytearrayoutputstream.toByteArray();
dataoutputstream.close();
}
catch (IOException ioexception)
{
System.err.println(ioexception);
}
if (abyte0 == null)
return;
try{
RecordStore recordstore = RecordStore.openRecordStore("Biorhythm",true);
if (recordstore == null)
return;
int cnt = recordstore.getNumRecords();
if ( cnt == 0)
{
recordstore.addRecord(abyte0,0,abyte0.length);
}
else
{
recordstore.setRecord(1,abyte0,0,abyte0.length);
}
recordstore.closeRecordStore();
} catch (RecordStoreException recordstoreexception)
{
System.err.println(recordstoreexception);
}
}
private void readDate()
{
byte abyte0[] = null;
try
{
RecordStore recordstore = RecordStore.openRecordStore("Biorhythm",false);
if (recordstore.getNumRecords() !=0)
abyte0 = recordstore.getRecord(1);
recordstore.closeRecordStore();
}
catch (RecordStoreException recordstoreexception)
{
System.err.println(recordstoreexception);
}
if (abyte0 !=null)
try
{
DataInputStream datainputstream = new DataInputStream(new ByteArrayInputStream(abyte0));
date = new Date (datainputstream.readLong());
datainputstream.close();
}
catch(IOException ioexception)
{
System.err.println(ioexception);
}
}
private Date date;
private BiorhythmCanvas canvas;
private BiorhythmForm form;
private Command exitCmd = new Command("Exit",Command.EXIT,1);
private Command showBirthCmd = new Command("Birth",Command.SCREEN,2);
private Command birthOKCmd = new Command("OK",Command.EXIT,1);
private Command birthCancelCmd = new Command("Cancel",Command.SCREEN,1);
}
网友回复:第一个类的代码贴错啦
网友回复:不好意思啊!
1、BiorhythmCanvas.java
import java.util.Date;
import javax.microedition.lcdui.*;
class BiorhythmCanvas extends Canvas
{
Date today = new Date();
Date birthday = new Date ( today.getTime() -100*msperday );
Date leftday = new Date ( today .getTime() -days/2*msperday);
public static int days = 22;
public static long msperday = 24L*60*60*1000L;
public void setBirthday ( Date birthday )
{
this.birthday = birthday;
if( birthday !=null )
repaint();
}
public void paint(Graphics g)
{
if( birthday == null ) return;
int kx = getWidth() /days;
int h = getHeight() /2;
g.setGrayScale(255);
g.fillRect(0,0,getWidth(),getHeight());
g.setGrayScale(0);
g.drawLine(0,h,getWidth(),h);
int todayX = (int) (((today.getTime() - leftday.getTime())/msperday)*kx);
g.drawLine(todayX, 0, todayX ,h*2);
for( int i=0; i <=days;i )
{
g.drawLine( i*kx,h,i*kx,h 3 );
}
Font font = Font.getDefaultFont();
g.setColor( 0xFF0000);
g.drawString("生理",todayX 3, 3,
Graphics.TOP ¦Graphics.LEFT);
drawCurve(phy,g);
g.setColor( 0x007700);
g.drawString("情绪",todayX 3, 3 font.getHeight(),
Graphics.TOP ¦Graphics.LEFT);
drawCurve(emt,g);
g.setColor( 0x0000FF);
g.drawString("智力",todayX 3, 3 2*font.getHeight(),
Graphics.TOP ¦Graphics.LEFT);
drawCurve(intell,g);
}
public void keyPressed(int keyCode)
{
if(keyCode == KEY_NUM4 ¦ ¦ getGameAction(keyCode) == LEFT)
{
leftday = new Date ( leftday.getTime() - msperday );
repaint();
}
else if (keyCode == KEY_NUM6 ¦ ¦ getGameAction(keyCode) == RIGHT)
{
leftday = new Date ( leftday.getTime() msperday );
repaint();
}
}
private void drawCurve(short [] data,Graphics g)
{
int kx = getWidth()/days;
int h = getHeight()/2;
int diff = (int)((leftday.getTime() - birthday .getTime())/msperday);
for(int i=0; i <=days; i )
{
long val1 = data [(diff i) % data.length];
long val2= data [(diff i 1) % data.length];
g.drawLine(
i * kx,(int)(h-val1*h/1000),
(i 1)*kx,(int)(h-val2*h/1000)
);
}
}
private static final short phy[] = {
0,270,520,731,888,979,998,942,817,631,
398,136,-136,-398,-631,-817,-942,-998,-979,-888,-731,-520,-270
};
private static final short emt[] = {
0,223,434,623,782,901,975,1000,975,901,782,623,434,223,0,-223,-434,-623,-782,-901,
-975,-1000,-975,-901,-782,-623,-434,-223
};
private static final short intell[] = {
0,189,372,541,690,815,910,972,999,990,
945,866,756,618,458,282,95,-95,-282,-458,
-618,-756,-866,-945,-990,-999,-972,-910,-815,-690,
-541,-372,-189
};
}
网友回复:报错提示呢?
网友回复:Unable to create MIDlet BiorhmCanvas
java.lang.lllegalAccessExcepyion
网友回复:我朋友帮我贴的。我补充下,编译没有问题,运行就有报错,谢谢指点。
报错提示:
Unable to create MIDlet BiorhymCanvas
java.lang.lllegalAccessException
at com.sun.midp.midlet.MIDletState.creatMIDlet( 34)
at com.sun.midp.midlet.Selector.run( 22)
网友回复:你的MIDlet类设置错了,BiorhythmMIDlet这个类才是你的MIDlet类
网友回复:您能说得具体点吗?具体怎么改?谢谢指点!
网友回复:
我重新新建一个了工程,类名改为BiorhymMIDlet,运行还是报错,
报错提示:
Unable to create MIDlet BiorhymCanvas
java.lang.lllegalArgumentException .望指教!
网友回复:JAD文件里面的MIDlets应用是BiorhythmMIDlet,不是BiorhymCanvas
网友回复:MIDlet设错了,所以它生成不了你的MIDlet
就像你设了一个没有main方法的类做为主类,那程序当然就运行不起来了
网友回复:运行还是报错
报错提示:
Unable to create MIDlet BiorhymMIDletjava.lang.lllegalArgumentException .
网友回复:Display.getDisplay(this).setCurrent(canvas); 不知道是不是这个原因,你最好维持一个Display dis=Display.getDisplay(this);这样至少也习惯些,之后你直接用dis).setCurrent(canvas); 你可以试下
网友回复:还有你看一下MIDLet中那个参数是不是设错了.
网友回复:最近忙别的了,好久没管这个了。谢谢各位答复!我试试看。
网友回复:我试着改了下,运行还是报错啊
报错提示:
Unable to create MIDlet BiorhymMIDletjava.lang.lllegalArgumentException .
关键字:没有,访问,权限,
下一篇:下面没有链接了











文章评论
共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面