📄 preferences.java
字号:
// J2ME Compass
// Copyright (C) 2007 Dana Peters
// http://www.qcontinuum.org/compass
package org.qcontinuum.compass;
import java.io.*;
import javax.microedition.rms.*;
public class Preferences {
public short ScreenTop;
public boolean ScreenDown;
public boolean Hour24;
public int DayColour, NightColour;
private Location mLocation;
private Location mDestination;
public Preferences() {
load();
}
public Location getLocation() {
return mLocation;
}
public void setLocation(Location location) {
mLocation = location;
}
public Location getDestination() {
return mDestination;
}
public void setDestination(Location location) {
mDestination = location;
}
public void save() {
RecordStore recordStore;
DataOutputStream outputStream;
try {
recordStore = RecordStore.openRecordStore("preferences", true);
} catch (RecordStoreException rsc) {
return;
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
outputStream = new DataOutputStream(baos);
try {
outputStream.writeBoolean(ScreenDown);
outputStream.writeShort(ScreenTop);
outputStream.writeBoolean(Hour24);
outputStream.writeInt(DayColour);
outputStream.writeInt(NightColour);
outputStream.writeBoolean(mLocation != null);
if (mLocation != null)
mLocation.save(outputStream);
outputStream.writeBoolean(mDestination != null);
if (mDestination != null)
mDestination.save(outputStream);
byte[] bytes = baos.toByteArray();
if (recordStore.getNumRecords() == 0)
recordStore.addRecord(bytes, 0, bytes.length);
else
recordStore.setRecord(1, bytes, 0, bytes.length);
} catch (Exception exception) {
} finally {
try {outputStream.close();} catch (Exception ex) {}
try {recordStore.closeRecordStore();} catch (Exception ex) {}
}
}
private void load() {
RecordStore recordStore = null;
DataInputStream inputStream = null;
try {
recordStore = RecordStore.openRecordStore("preferences", false);
byte[] bytes = recordStore.getRecord(1);
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
inputStream = new DataInputStream(bais);
ScreenDown = inputStream.readBoolean();
ScreenTop = inputStream.readShort();
Hour24 = inputStream.readBoolean();
DayColour = inputStream.readInt();
NightColour = inputStream.readInt();
if (inputStream.readBoolean())
mLocation = new Location(inputStream);
else
mLocation = null;
if (inputStream.readBoolean())
mDestination = new Location(inputStream);
else
mDestination = null;
} catch (Exception ex) {
ScreenDown = false;
ScreenTop = 0;
Hour24 = false;
DayColour = 0x0080ff;
NightColour = 0x808080;
mLocation = null;
mDestination = null;
} finally {
try {inputStream.close();} catch (Exception ex) {}
try {recordStore.closeRecordStore();} catch (Exception ex) {}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -