Đây là một hình thức J2ME ví dụ đơn giản, có nghĩa là sẽ hiển thị ngày giờ hiện tại trên màn hình. Như cốt lõi Java J2ME quá sử dụng gói java.util cùng để hiển thị ngày hiện tại cũng như thời điểm hiện tại trên màn hình.Trong MIDlet này, chúng tôi đã thiết lập ngày hiện tại và thời gian như ngày giờ.Đó là lý do tại sao nó sẽ hiển thị cho bạn ngày hiện tại và thời gian, mỗi khi bạn chạy các ứng dụng.
Đầu ra của ứng dụng sẽ như thế nào như dưới đây đưa ra hình ảnh ..
Đầu tiên của tất cả trong hình ảnh này bạn có thể thấy rằng chúng tôi đã tạo ra một hình thức gọi là Date & Time và thiết lập thời gian hiện tại và ngày như Item.
Mã nguồn của DateAndTime.java
import java.util.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class DateAndTime extends MIDlet implements CommandListener {
Display disp;
Date d;
Calendar c = Calendar.getInstance () ;
String time;
DateField currentDate;
Command start, exit;
Form form;
int index;
public DateAndTime (){
form =new Form ("Data and Time") ;
d =new Date () ;
start =new Command ("start", Command.SCREEN,1) ;
exit =new Command ("Exit", Command.EXIT,0) ;
currentDate =new DateField ("", DateField.DATE_TIME ) ;
currentDate.setDate ( d ) ;
}
public void startApp (){
form.append ("CURRENT TIME IS: ") ;
index = form.append ( currentDate ) ;
form.addCommand ( start ) ;
form.addCommand ( exit ) ;
form.setCommandListener (this) ;
disp = Display.getDisplay (this) ;
disp.setCurrent ( form ) ;
}
public void pauseApp (){}
public void destroyApp (boolean uncond ){}
public void commandAction ( Command cmd, Displayable s ){
if( cmd == exit ){
notifyDestroyed () ;
}else if( cmd == start ){
d =new Date () ;
c.setTime ( d ) ;
time = c.get (Calendar.HOUR_OF_DAY ) +":"+c.get ( Calendar.MINUTE )
+":"+ c.get ( Calendar.SECOND ) ;
form.append (""+ time ) ;
form.append ("\n") ;
}
}
}
Source:
DateAndTime.zip (689 B)