📄 alarmmodel.java
字号:
/*
* AlarmModel.java
*
* Created on 2005年11月9日, 下午4:58
*
* To change this template, choose Tools | Options and locate the template under
* the Source Creation and Management node. Right-click the template and choose
* Open. You can then make changes to the template in the Source Editor.
*/
package com.j2medev.ch7.push;
import java.io.IOException;
import java.io.InputStream;
import java.util.Calendar;
import java.util.Date;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
/**
*
* @author Administrator
*/
public class AlarmModel {
private RecordStore rs = null;
private Player player = null;
/** Creates a new instance of AlarmModel */
public AlarmModel() {
try{
rs = RecordStore.openRecordStore("alarm",true);
}catch(RecordStoreException ex){
ex.printStackTrace();
}
}
public void writeDate(Date date){
String s = AlarmModel.getString(date);
try{
int num = rs.getNumRecords();
if(num == 0){
rs.addRecord(s.getBytes(), 0, s.getBytes().length);
}else{
rs.setRecord(1, s.getBytes(), 0, s.getBytes().length);
}
}catch(RecordStoreException ex){
ex.printStackTrace();
}
}
public String readDate(){
String date = null;
try{
int num = rs.getNumRecords();
if(num == 0){
return date;
}else{
byte[] data = rs.getRecord(1);
return new String(data);
}
}catch(RecordStoreException ex){
return null;
}
}
public void closeRecordStore(){
if(rs != null){
try{
rs.closeRecordStore();
}catch(RecordStoreException ex){
}
}
}
public void playSound(){
InputStream is = this.getClass().getResourceAsStream("/pattern.mid");
if(is != null){
try{
player = Manager.createPlayer(is, "audio/midi");
player.setLoopCount(-1);
player.start();
}catch(IOException ex){
ex.printStackTrace();
}
catch(MediaException mex){
mex.printStackTrace();
}
}
}
public void stopSound(){
if(player != null){
try{
player.stop();
player = null;
}catch(MediaException me){
}
}
}
public static String getString(Date d){
Calendar calendar = Calendar.getInstance();
calendar.setTime(d);
String s = ""+calendar.get(Calendar.YEAR)+calendar.get(Calendar.MONTH)+
calendar.get(Calendar.DAY_OF_MONTH)+calendar.get(Calendar.HOUR_OF_DAY)+
calendar.get(Calendar.MINUTE);
return s;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -