Anda di halaman 1dari 9

U1 - Ruaj te dhenat ne Preferences File

import java.util.*;
import javax.microedition.io.*;
import javax.microedition.io.file.*;
import java.io.*;
public class FileBasedPreferences implements Runnable {
private String mDirector!ame;
private static final String file"R#Root $ %file&'''%;
private static final String file(xt $ %.pfs%;
private )as*table m)as*table;
private boolean mSaving $ false;
private String mFileRoot $ null;
public FileBasedPreferences+String dir!ame,
t*ro-s ./(xception {
mDirector!ame $ dir!ame;
m)as*table $ ne- )as*table+,;
(numeration em $ FileSstemRegistr.listRoots+,;
'' 0a1e t*e first root available for simplicit.
if +em.*as2ore(lements+,,
mFileRoot $ file"R#Root 3 em.next(lement+,;
if +mFileRoot 4$ null,
load+,;
else
t*ro- ne- ./(xception+%!o file sstem available%,;
5
public String get+String 1e, {
return +String,m)as*table.get+1e,;
5
public void put+String 1e6 String value, {
if +value $$ null, value $ %%;
m)as*table.put+1e6 value,;
5
private void load+, t*ro-s ./(xception {
File7onnection fc $ null;
Data.nputStream dis $ null;
StringBuffer file"R# $ ne- StringBuffer+mFileRoot,;
file"R#.append+mDirector!ame,;
file"R#.append+file(xt,;
tr {
fc $ +File7onnection, 7onnector.open+
file"R#.toString+,6 7onnector.R(8D,;
if +fc $$ null,
return;
if +4fc.exists+,, {
return;
5
dis $ fc.openData.nputStream+,;
String cur.nput;
-*ile + +cur.nput $ dis.read"0F+,, 4$ null , {
int index $ cur.nput.index/f+9:9,;
String name $ cur.nput.substring+;6 index,;
String value $ cur.nput.substring+index 3 <,;
put+name6 value,;
5
5 catc* +(xception ex, {
'' (nd of file detected t*e *ard -a.
5
finall {
if +dis 4$ null, dis.close+,;
if +fc 4$ null, fc.close+,;
5
5
public void save+, {
0*read t $ ne- 0*read+t*is,;
t.start+,;
5
public void run+, {
mSaving $ true;
tr {
savePref+,;
5 catc* +./(xception ex, {
5
mSaving $ false;
5
public boolean isSaving+, {
return mSaving;
5
public void savePref+, t*ro-s ./(xception {
File7onnection fc $ null;
Data/utputStream dos $ null;
tr {
'' .f exists alread6 first delete file6 a little clums.
StringBuffer file"R# $ ne- StringBuffer+mFileRoot,;
file"R#.append+mDirector!ame,;
file"R#.append+file(xt,;
fc $ +File7onnection, 7onnector.open+ file"R#.toString+,6
7onnector.R(8D=>R.0(,;
if +fc.exists+,, {
fc.delete+,;
fc.close+,;
fc $ +File7onnection, 7onnector.open+ file"R#.toString+,6
7onnector.R(8D=>R.0(,;
5
fc.create+,;
dos $ ne- Data/utputStream+fc.open/utputStream+,,;
'' !o- save t*e preferences records.
(numeration 1es $ m)as*table.1es+,;
-*ile +1es.*as2ore(lements+,, {
String 1e $ +String,1es.next(lement+,;
String value $ get+1e,;
String pref $ 1e 3 %:% 3 value;
dos.-rite"0F+pref,;
5
5
finall {
if +dos 4$ null, {
dos.flus*+,;
dos.close+,;
5
if +fc 4$ null, fc.close+,;
5
5
5
''********************************************
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.rms.RecordStore(xception;
import java.io.*;
public class F72.Dlet
extends 2.Dlet
implements 7ommand#istener {
private static final String 1"ser $ %user%;
private static final String 1Pass-ord $ %pass-ord%;
private FileBasedPreferences mPreferences;
private Form mForm;
private 0extField m"serField6 mPass-ordField;
private 7ommand m(xit7ommand6 mSave7ommand;
public F72.Dlet+, {
tr {
verifFile7onnectionSupport+,;
mPreferences $ ne- FileBasedPreferences+%preferences%,;
5
catc* +./(xception ex, {
mForm $ ne- Form+%(xception%,;
mForm.append+ne- String.tem+null6 ex.toString+,,,;
m(xit7ommand $ ne- 7ommand+%(xit%6 7ommand.(?.06 ;,;
mForm.add7ommand+m(xit7ommand,;
mForm.set7ommand#istener+t*is,;
return;
5
mForm $ ne- Form+%#ogin%,;
m"serField $ ne- 0extField+%!ame%6
mPreferences.get+1"ser,6 @A6 ;,;
mPass-ordField $ ne- 0extField+%Pass-ord%6
mPreferences.get+1Pass-ord,6 @A6 ;,;
mForm.append+m"serField,;
mForm.append+mPass-ordField,;
m(xit7ommand $ne- 7ommand+%(xit%6 7ommand.(?.06 ;,;
mSave7ommand $ ne- 7ommand+%Save%6 %Save Pass-ord%6 7ommand.S7R((!6 ;,;
mForm.add7ommand+m(xit7ommand,;
mForm.add7ommand+mSave7ommand,;
mForm.set7ommand#istener+t*is,;
5
public void start8pp+, {
Displa.getDispla+t*is,.set7urrent+mForm,;
5
public void pause8pp+, {5
public void savePrefs+, {
'' Save t*e user name and pass-ord.
mPreferences.put+1"ser6 m"serField.getString+,,;
mPreferences.put+1Pass-ord6 mPass-ordField.getString+,,;
mPreferences.save+,;
5
public void destro8pp+boolean flg, {
5
public void command8ction+7ommand c6 Displaable s, {
if +c $$ m(xit7ommand, {
if +mPreferences $$ null, {
destro8pp+true,;
notifDestroed+,;
5
else if + 4mPreferences.isSaving+,, {
destro8pp+true,;
notifDestroed+,;
5
5
else if +c $$ mSave7ommand,
savePrefs+,;
5
public void verifFile7onnectionSupport+, t*ro-s ./(xception {
String version $ %%;
version $ Sstem.getPropert+%microedition.io.file.File7onnection.version%,;
if +version 4$ null, {
if +4version.eBuals+%<.;%,,
t*ro- ne- ./(xception+%Pac1age is not version <.;.%,;
5
else
t*ro- ne- ./(xception+%File connection optional pac1age is not available.%,;
5
5
U2 - Shembulli Login
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class MidletLogin extends MIDlet implements CommandListener {
javax.microedition.lcdui.TextField mserField;
javax.microedition.lcdui.TextField m!ass"ordField;
private Command m#$Command % ne" Command&'#$'( Command.#$( )*;
private Command m+xitCommand % ne" Command&'+xit'( Command.+,IT( )*;
private Command m-ac.Command % ne" Command&'-ac.'( Command.-/C$(
)*;
Form 0orm % ne" Form&'Login Form'*;
public void start/pp&* {
0orm.setCommandListener&t1is*;
mserField % ne" TextField&'sername'( null( 234( TextField./56*;
0orm.append&mserField*;
m!ass"ordField % ne" TextField&'!ass"ord'( null( 234( TextField.!/778#9D*;
0orm.append&m!ass"ordField*;
0orm.addCommand&m#$Command*;
0orm.addCommand&m+xitCommand*;
Displa:.getDispla:&t1is*.setCurrent&0orm*;
;
public void pause/pp&* {
;
public void destro:/pp&boolean unconditional* {
;
public void command/ction&Command c( Displa:able s* {
i0 &c.getCommandT:pe&* %% Command.+,IT*
{
destro:/pp&true*;
noti0:Destro:ed&*;
;
else i0 &c %% m#$Command*
{
i0 &mserField.get7tring&*.e<uals&'admin='* >>
m!ass"ordField.get7tring&*.e<uals&'passadmin'**
{
Form 1elloForm % ne" Form&'?ello'*;
1elloForm.setCommandListener&t1is*;
1elloForm.append&'!ers1endetje ' @ mserField.get7tring&**;
1elloForm.addCommand&m+xitCommand*;
Displa:.getDispla:&t1is*.setCurrent&1elloForm*;
;
else
{
/lert a % ne" /lert&'Aabim'( 'sername ose pass"ord es1te s1.ruar
gabim. 71t:p -ac. per tu ri.t1:er ne e.ranin e logimit.'( null( null*;
a.setTimeout&/lert.F#9+B+9*;
Displa:.getDispla:&t1is*.setCurrent&a*;
a.addCommand&m+xitCommand*;
a.addCommand&m-ac.Command*;
;
;
else i0 &c %% m-ac.Command*
{
Displa:.getDispla:&t1is*.setCurrent&0orm*;
;
;
;
U3 - Fusha e shahut
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class 71a1uMidlet extends MIDlet implements CommandListener{
71a1uItem item;
public void start/pp&* {
Form 0orm % ne" Form&'71a1u'*;
item % ne" 71a1uItem&'71a1uItem'*;
0orm.append&item*;
Command c % ne" Command&'+xit'( Command.+,IT( )*;
Command rCommand % ne" Command&'9ed'( Command.7C9++5( =*;
Command gCommand % ne" Command&'Areen'( Command.7C9++5( 2*;
Command bCommand % ne" Command&'-lue'( Command.7C9++5( C*;
0orm.addCommand&c*;
0orm.addCommand&rCommand*;
0orm.addCommand&gCommand*;
0orm.addCommand&bCommand*;
0orm.setCommandListener&t1is*;
Displa:.getDispla:&t1is*.setCurrent&0orm*;
;
public void pause/pp&* {
;
public void destro:/pp&boolean unconditional* {
;
public void command/ction&Command c( Displa:able s* {
i0 &c.getCommandT:pe&* %% Command.+,IT*
noti0:Destro:ed&*;
else i0 &c.getLabel&* %% '9ed'*
item.set9A-&233( )( )*;
else i0 &c.getLabel&* %% 'Areen'*
item.set9A-&)( 233( )*;
else i0 &c.getLabel&* %% '-lue'*
item.set9A-&)( )( 233*;
;
;
import javax.microedition.lcdui.*;
public class 71a1uItem extends CustomItem {
private int red( green( blue;
public 71a1uItem&7tring title* { super&title*; ;
DD CustomItem abstract met1ods.
public int getMinContent8idt1&* { return =)); ;
public int getMinContent?eig1t&* { return 4); ;
public int get!re0Content8idt1&int "idt1* {
return getMinContent8idt1&*;
;
public int get!re0Content?eig1t&int 1eig1t* {
return getMinContent?eig1t&*;
;
public void set9A-&int r( int g( int b*{
t1is.red % r;
t1is.green % g;
t1is.blue % b;
repaint&*;
;
public void paint&Arap1ics g( int "( int 1* {
DDg.dra"9ect&)( )( " E =( 1 E =*;
g.setColor&t1is.red( t1is.green( t1is.blue*;
int x % );
int : % );
int d % 1DF;
0or&int i % ); i G F; i@@*
{
x % );
0or&int j % ); j G F; j@@*
{
i0 &&i @ j* H 2 %% )*
g.Ill9ect&x( :( d( d*;
g.dra"9ect&x( :( d( d*;
x @% d;
;
: @%d;
;
;
;

Anda mungkin juga menyukai