| |
"The Mighty WAP Strikes Out!"
Vol. 8, Issue 3, p. 56
Listing 1
//mail message variables
String subject = "Subject line of mail message";
String to = "username@company.com";
String cc = "username@company.com";
String text = "This is a draft email I will store and send at a later date";
RecordStore dataStore=null; //define recordstore
try {
//open record store and create if it doesn't exist.
dataStore = RecordStore.openRecordStore("draftMail",true);
//add subject row
dataStore.addRecord(subject.getBytes(),0,subject.getBytes().length);
//add to row
dataStore.addRecord(to.getBytes(),0,to.getBytes().length);
//add cc row
dataStore.addRecord(cc.getBytes(),0,cc.getBytes().length);
//add text row
dataStore.addRecord(text.getBytes(),0,text.getBytes().length);
//close data store
dataStore.closeRecordStore();
//code to retrieve data from store
int rowsPerRecord = 4; //total rows that make up a message
//open data store and create if it doesn't exist.
dataStore = RecordStore.openRecordStore("draftMail",true);
int totalDraftMessages = dataStore.getNumRecords() // rowsPerRecord;
//loop through each full mail message
for (int i=0;i<totalDraftMessages;iI=I+rowsPerRecord++) {
//retrieve the subject line from the dataStore
String subjectLine = new String (dataStore.getRecord(j));
//retrieve the to line from the dataStore
String toLine = new String (dataStore.getRecord(j));
//retrieve the cc line from the dataStore
String ccLine = new String (dataStore.getRecord(j));
//retrieve the text line from the dataStore
String textLine = new String (dataStore.getRecord(j));
}
dataStore.closeRecordStore();
}
catch (Exception ex) {
System.out.println("Exception In myRMS " + ex);
}
Listing 2
public class myCanvas extends Canvas
{
Image backGroundScreen;
private static final int COLOR_BLACK = 0x00000000;
private static final int COLOR_WHITE = 0x00FFFFFF;
private static final int COLOR_MEDIUM_GRAY = 0x00666666;
myMenu mainmenu;
Display display;
//Constructor
public myCanvas()
{
super();
}
public void drawMap(Display display)
{
this.display = display; //reference to current display
int width = super.getWidth(); //get width of devices screen
int height = super.getHeight(); //get height of devices screen
//setup background image so we do not affect the current screen while drawing
backGroundScreen = Image.createImage( width, height );
//get graphics context of screen for draw methods.
Graphics backGroundGraphics = backGroundScreen.getGraphics();
//set color to white and clear current screen.
backGroundGraphics.setColor( COLOR_WHITE );
backGroundGraphics.fillRect( 0, 0, width, height );
//set color to black for normal text
backGroundGraphics.setColor( COLOR_BLACK );
//draw a rectangle around the drawing area
backGroundGraphics.drawRect(1,14,width-4,height-16);
//The following code will draw street segments with the major highway being drawn
//in black and the smaller roads drawn in medium gray
backGroundGraphics.drawString("My Map",0,0,Graphics.TOP|Graphics.LEFT);
this.drawLine(backGroundGraphics, COLOR_BLACK,5,16,11,24);
this.drawLine(backGroundGraphics, COLOR_BLACK, 11,24,16,56);
this.drawLine(backGroundGraphics, COLOR_BLACK, 16,56,64,96);
this.drawLine(backGroundGraphics, COLOR_MEDIUM_GRAY,
15,35,22,23);
this.drawLine(backGroundGraphics, COLOR_MEDIUM_GRAY,
22,23,26,24);
this.drawLine(backGroundGraphics, COLOR_MEDIUM_GRAY,
12,90,60,24);
//set this Canvas as the current displayed screen.
display.setCurrent(this);
}
//Draw a line on the passed in graphics component
public void drawLine(Graphics g, int color, int startX,
int startY, int endX, int endY)
{
int currentColor = g.getColor();
//save current color
g.setColor( color );
//set color to passed in color
g.drawLine( startX, startY, endX, endY);
//draw line
g.setColor( currentColor );
//set color back to original color
}
/**
* paint
*/
public void paint(Graphics g) {
//paint background image on screen
g.drawImage( backGroundScreen, 0, 0, Graphics.TOP | Graphics.LEFT );
}
}
Listing 3
protected void keyPressed(int keyCode) {
if (getKeyName(keyCode).equals("SELECT"))
//if key name is Menu then popup Menu toolbar
{
System.out.println("The Select Key was pressed");
if (mainmenu == null)
{
//create new Menu Component and pass background image so it can draw itself
mainmenu = new myMenu(backGroundScreen);
}
else
{
int selected = mainmenu.getCurrentSelection();
switch (selected) {
case 1: System.out.println("Selected File");
break;
case 2: System.out.println("Selected Edit");
break;
case 3: System.out.println("Selected Exit");
break;
}
mainmenu=null;
this.drawMap(display);
}
repaint(); //tell the Canvas to repaint to show the main menu.
}
else if (getKeyName(keyCode).equals("UP"))
//if key name is Menu then popup Menu toolbar
{
mainmenu.moveSelection(false);
repaint();
}
else if (getKeyName(keyCode).equals("DOWN"))
//if key name is Menu then popup Menu toolbar
{
mainmenu.moveSelection(true);
repaint();
}
}
//Constructor
public myMenu(Image backGroundScreen) {
//get Graphics component from screen
backGroundGraphics = backGroundScreen.getGraphics();
//clear area for menu
backGroundGraphics.setColor( COLOR_WHITE );
backGroundGraphics.fillRect( 9, 12, 30, 70 );
//shade header area light gray
backGroundGraphics.setColor( COLOR_LIGHT_GRAY );
backGroundGraphics.fillRect( 9, 12, 30, 20 );
//set color to black for drawing
backGroundGraphics.setColor( COLOR_BLACK );
//draw rectangle around menu area
backGroundGraphics.drawRect(9,12,30,70);
//draw rectangle around first Selection.
backGroundGraphics.drawRect(9,32,30,14);
//draw menu options.
backGroundGraphics.drawString("Menu",12,16,Graphics.TOP|Graphics.LEFT);
backGroundGraphics.drawString("File",12,32,Graphics.TOP|Graphics.LEFT);
backGroundGraphics.drawString("Edit",12,48,Graphics.TOP|Graphics.LEFT);
backGroundGraphics.drawString("Exit",12,64,Graphics.TOP|Graphics.LEFT);
}
public void moveSelection(boolean goDown) {
//clear current selection rectangle.
System.out.println("Last selection: " + currentSelection);
backGroundGraphics.setColor( COLOR_WHITE );
backGroundGraphics.drawRect(9,(currentSelection*16)+16,30,14 );
backGroundGraphics.setColor( COLOR_BLACK );
//redraw rectangle around menu area.
backGroundGraphics.drawRect(9,12,30,70);
//set current selection
if (goDown)
currentSelection++;
else
currentSelection--;
//make sure selection is within bounds. If not then wrap around.
if (currentSelection<1)
currentSelection=3;
else if (currentSelection>3)
currentSelection=1;
//draw rectangle around current selection.
backGroundGraphics.drawRect(9,(currentSelection*16)+16,30,14 );
}
//return current selection
public int getCurrentSelection() {
return currentSelection;
}
}
|
|