当前位置: 编程技术>移动开发
本页文章导读:
▪SimpleDateFormat的惯用方法 SimpleDateFormat的常用方法
/** parse()可以 把String型的字符串转换成特定格式的date类型 */
public static void main(String[] args) {
String dStr = "2001.12.12-08.23.21";
Date d = null;
SimpleDateFormat sdf = new SimpleDateF.........
▪ Java中施用Lua脚本语言2 Java中使用Lua脚本语言2
实现一个怪物的创建,把lua里的设定当作初始状态传给monstor,名字为sample monstor,防御10,攻击10,生命1001.先导入lib--luajava-1.1.jarimport org.keplerproject.luajava.LuaState;
import o.........
▪ 一些API的运用 一些API的使用
Paint paint = new Paint();
// setColor 须在 setAlpha 方法之前设置,原因请参见 Android API
paint.setColor(Color.GRAY);
// 值越大越不透明
paint.setAlpha(255);
//取得屏幕分辨率
DisplayMetrics.........
[1]SimpleDateFormat的惯用方法
来源: 互联网 发布时间: 2014-02-18
SimpleDateFormat的常用方法
继续俺的java基础学习....:)
/** parse()可以 把String型的字符串转换成特定格式的date类型 */
public static void main(String[] args) {
String dStr = "2001.12.12-08.23.21";
Date d = null;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd-HH.mm.ss");
try {
d = sdf.parse(dStr);
} catch (ParseException pe) {
System.out.println(pe.getMessage());
}
System.out.println(d);
System.out.println(d.getTime());
SimpleDateFormat myFmt = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
SimpleDateFormat myFmt1 = new SimpleDateFormat("yy/MM/dd HH:mm");
SimpleDateFormat myFmt2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat myFmt3 = new SimpleDateFormat(
"yyyy年MM月dd日 HH时mm分ss秒 E ");
SimpleDateFormat myFmt4 = new SimpleDateFormat(
"一年中的第 D 天 一年中第w个星期 一月中第W个星期 在一天中k时 z时区");
Date now = new Date();
System.out.println(myFmt.format(now));
System.out.println(myFmt1.format(now));
System.out.println(myFmt2.format(now));
System.out.println(myFmt3.format(now));
System.out.println(myFmt4.format(now));
System.out.println(now.toString());
}
继续俺的java基础学习....:)
[2] Java中施用Lua脚本语言2
来源: 互联网 发布时间: 2014-02-18
Java中使用Lua脚本语言2
实现一个怪物的创建,把lua里的设定当作初始状态传给monstor,名字为sample monstor,防御10,攻击10,生命100
1.先导入lib--luajava-1.1.jar
monstor.lua---
但总是抛出这个错误:
PANIC: unprotected error in call to Lua API (Invalid method call. No such method.)
不知为何,以后用到的时候再research.
已经查出来,原来在Monster类中少了个方法:
public void setRace(String race) {
this.race = race;
}
怪不得会找不到,
要在一lua文件a.lua里导入其他的lua文件b.lua,用require "b"
如果要从lua中运算后得到返回参数,则需要做一下修改:在lua文件中改成:
在Load.java中的run改成如下:
实现一个怪物的创建,把lua里的设定当作初始状态传给monstor,名字为sample monstor,防御10,攻击10,生命100
1.先导入lib--luajava-1.1.jar
import org.keplerproject.luajava.LuaState;
import org.keplerproject.luajava.LuaStateFactory;
public class Load{
LuaState luaState;
/**
* Constructor
* @param fileName File name with Lua .
*/
Load(final String fileName) {
this.luaState = LuaStateFactory.newLuaState();
this.luaState.openLibs();
this.luaState.LdoFile(fileName);
}
/**
* Ends the use of Lua environment.
*/
void close() {
this.luaState.close();
}
/**
* Call a Lua inside the Lua to insert
* data into a Java object passed as parameter
* @param Name Name of Lua .
* @param obj A Java object.
*/
void run(String Name, Object obj) {
this.luaState.getGlobal(Name);
this.luaState.pushJavaObject(obj);
this.luaState.call(1,0);
}
}public class Monster{
/* Info */
protected String race;
protected int defense;
protected int attack;
protected int life;
/* */
private Load ;
public Monster(String race) {
/* Loads Lua for this race.*/
this. = new Load(race+".lua");
/*Call Lua create .*/
.run("create", this);
}
public void setRace(String race) {
this.race = race;
}
public String getRace() {
return race;
}
public int getDefense() {
return this.defense;
}
public void setDefense(int defense) {
this.defense = defense;
}
public int getLife() {
return this.life;
}
public void setLife(int life) {
this.life = life;
}
public void setAttack(int attack) {
this.attack = attack;
}
public int getAttack() {
return this.attack;
}
}monstor.lua---
function create(monster)
monster:setRace("Sample Monster")
monster:setDefense(10)
monster:setAttack(10)
monster:setLife(100)
end但总是抛出这个错误:
PANIC: unprotected error in call to Lua API (Invalid method call. No such method.)
不知为何,以后用到的时候再research.
已经查出来,原来在Monster类中少了个方法:
public void setRace(String race) {
this.race = race;
}
怪不得会找不到,
要在一lua文件a.lua里导入其他的lua文件b.lua,用require "b"
如果要从lua中运算后得到返回参数,则需要做一下修改:在lua文件中改成:
function create(monster)
monster:setRace("Sample Monster")
monster:setDefense(10)
monster:setAttack(10)
monster:setLife(100)
return monster
end在Load.java中的run改成如下:
void run(String Name, Object obj) {
this.luaState.getGlobal(Name);
this.luaState.pushJavaObject(obj);
this.luaState.call(1, 1);// 一个参数,0个返回
try {
Object object =luaState.getObjectFromUserdata(1);
} catch (LuaException e) {
e.printStackTrace();
}
}
1 楼
相似的悲哀
2011-12-28
麻烦问下,我想从lua中的table中取值(Table中再嵌套Table),应该怎么做呢,用流还是用luajava中的方法,好纠结啊,希望大神可以给菜鸟指点指点 谢谢
[3] 一些API的运用
来源: 互联网 发布时间: 2014-02-18
一些API的使用
Paint paint = new Paint(); // setColor 须在 setAlpha 方法之前设置,原因请参见 Android API paint.setColor(Color.GRAY); // 值越大越不透明 paint.setAlpha(255);
//取得屏幕分辨率 DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm);
// 去掉标题栏 requestWindowFeature(Window.FEATURE_NO_TITLE);
// 设置为全屏 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
// 如何一个 service 被调用很多次,即 onStartCommand() 响应过很多个请求, // 那么会相应的产生很多个 startId,比如:1,2,3 三个 // 那么,stopSelfResult(int startId) 只会在参数为 3 的时候才会真正地停止这个服务 // 另外,stopSelf() 是stopSelfResult()的老版本,推荐使用新版本 boolean result = stopSelfResult(msg.arg1);
/**
* Show a notification while this service is running.
*/
private void showNotification() {
// In this sample, we'll use the same text for the ticker and the expanded notification
CharSequence text = getText(R.string.local_service_started);
// Set the icon, scrolling text and timestamp
Notification notification = new Notification(R.drawable.stat_sample, text,
System.currentTimeMillis());
// The PendingIntent to launch our activity if the user selects this notification
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, LocalServiceActivities.Controller.class), 0);
// Set the info for the views that show in the notification panel.
notification.setLatestEventInfo(this, getText(R.string.local_service_label),
text, contentIntent);
// Send the notification.
// We use a layout id because it is a unique number. We use it later to cancel.
mNM.notify(R.string.local_service_started, notification);
}
最新技术文章: