programmation j2me - kamel aloui · public class midlet_1 extends midlet implements commandlistener...

Post on 09-Feb-2020

3 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Programmation JProgrammation J22MEME

1

Activité 1Activité 1

2

ActivitéActivité 11

3

ActivitéActivité 11

4

ActivitéActivité 22

5

Activité 2Activité 2

6

Activité 2Activité 2

7

Activité 2Activité 2

8

Activité 3Activité 3

9

ActivitéActivité 33

10

Activité 3Activité 3

11

ActivitéActivité 33

12

Activité 1import javax.microedition.midlet.*;import javax.microedition.lcdui.*;

public class Midlet_2 extends MIDlet implements CommandListener {// The exit commandprivate Command exitCommand;// The display for this MIDletprivate Display display;// create a tickerprivate Ticker hi = new Ticker("J2ME is cool");

public Midlet_2() {display = Display.getDisplay(this);exitCommand = new Command("Exit", Command.SCREEN, 2);

}

public void startApp() {TextBox t = new TextBox("Hello MIDlet", "Wireless Internet", 256, 0);t.addCommand(exitCommand);t.setCommandListener(this);t.setTicker(hi); // set the tickerdisplay.setCurrent(t);

}public void pauseApp() { }public void destroyApp(boolean unconditional) { }public void commandAction(Command c, Displayable s) {if (c == exitCommand) {destroyApp(false);notifyDestroyed();

}}

}

13

Activité 2import javax.microedition.midlet.*;import javax.microedition.lcdui.*;

public class Midlet_1 extends MIDlet implements CommandListener{private Display display; // Reference to Display object for this MIDletprivate Form fmMain; // The main Formprivate TextBox tbAction; // Textbox to show when user selects upload/downloadprivate Command cmExit; // Exit the MIDletprivate Command cmBack; // Go "back" to the main formprivate Command cmUload; // "upload" data - no real action doneprivate Command cmDload; // "download" data - no real action done

public Midlet_1(){

display = Display.getDisplay(this);cmExit = new Command("Exit", Command.EXIT, 1);cmBack = new Command("Back", Command.BACK, 1);cmUload = new Command("Upload", Command.SCREEN, 2);cmDload = new Command("Download", Command.SCREEN, 3);// Create the Form, add Commands, listen for eventsfmMain = new Form("Core J2ME");fmMain.addCommand(cmExit);fmMain.addCommand(cmUload);fmMain.addCommand(cmDload);fmMain.setCommandListener(this);// Create a Textbox, add Command, listen for eventstbAction = new TextBox("Process Data", "Upload/download data ", 25, 0);tbAction.addCommand(cmBack);tbAction.setCommandListener(this);

}// Called by application manager to start the MIDlet.public void startApp(){

display.setCurrent(fmMain);}// A required methodpublic void pauseApp(){ }// A required methodpublic void destroyApp(boolean unconditional){ }// Process eventspublic void commandAction(Command c, Displayable s){

if (c == cmExit){

destroyApp(false);notifyDestroyed();

}else if (c == cmUload || c == cmDload)

display.setCurrent(tbAction);else if (c == cmBack)

display.setCurrent(fmMain);}

}

14

Activité 3import javax.microedition.midlet.*;import javax.microedition.lcdui.*;

public class Midlet extends MIDlet implements ItemStateListener, CommandListener{private Display display; // Reference to Display object for this MIDletprivate Form fmMain; // The main Formprivate Command cmExit; // A Command to exit the MIDletprivate DateField dfDate; // Display the date

public Midlet(){

display = Display.getDisplay(this);// Create the date and populate with current datedfDate = new DateField("Date is:", DateField.DATE);dfDate.setDate(new java.util.Date());cmExit = new Command("Exit", Command.EXIT, 1);// Create the Form, add Command and DateField// listen for events from Command and DateFieldfmMain = new Form("Core J2ME");fmMain.addCommand(cmExit);fmMain.append(dfDate);fmMain.setCommandListener(this); // Capture Command events (cmExit)fmMain.setItemStateListener(this); // Capture Item events (dfDate)

}// Called by application manager to start the MIDlet.public void startApp(){

display.setCurrent(fmMain);}

public void pauseApp(){ }

public void destroyApp(boolean unconditional){ }

public void commandAction(Command c, Displayable s){

if (c == cmExit){

destroyApp(false);notifyDestroyed();

}}

public void itemStateChanged(Item item){

System.out.println("Inside itemStateChanged()");dfDate.setLabel("New Date: ");

}}

15

top related