Your SlideShare is downloading. ×
0
Java me lab2-slides (gui programming)
Java me lab2-slides (gui programming)
Java me lab2-slides (gui programming)
Java me lab2-slides (gui programming)
Java me lab2-slides (gui programming)
Java me lab2-slides (gui programming)
Java me lab2-slides (gui programming)
Java me lab2-slides (gui programming)
Java me lab2-slides (gui programming)
Java me lab2-slides (gui programming)
Java me lab2-slides (gui programming)
Java me lab2-slides (gui programming)
Java me lab2-slides (gui programming)
Java me lab2-slides (gui programming)
Java me lab2-slides (gui programming)
Java me lab2-slides (gui programming)
Java me lab2-slides (gui programming)
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Java me lab2-slides (gui programming)

687

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
687
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
4
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Lab 4 (Lab 2 on Java ME)Java ME GUI Programming Pervasive Computing Lab Prepared by: Tuan Nguyen
  • 2. MIDP User interface High level Screen Alert Form List TextBox Low level Canvas Graphics
  • 3. FormPicture from: http://www.javaworld.com/javaworld/jw-05-2005/images/jw-0516-midp1.jpg
  • 4. Let’s Example Mobile Restaurant App  Allow a user to order a meal remotely using a mobile phone. This is a list (List class)
  • 5. List – a class of ScreenString[] mainCourseOffers={"Steak","Lamb","Chicken"};...//create the listlstMainCourse = new List("Select main course:", Choice.MULTIPLE, mainCourseOffers);//display the list on the screenDisplay.getDisplay(this).setCurrent(lstMainCourse);
  • 6. Add a Command button to the list//Create a commandcmdNext = new Command("Next", Command.OK, 1);//Add a command “Next” to the Main Course listlstMainCourse.addCommand(cmdNext);//let lstMainCourse listen to the user’s commandslstMainCourse.setCommandListener(this);
  • 7. Result The “Next” command does nothing now. Let’s add another list called “Dessert List”. When the user selects the Next command, the Dessert List will be displayed on the screen. The “Next” command button
  • 8. Create the Dessert listString[] dessertOffers = {"Ice Cream", "Chocolate Cake", "Orange Juice"};...//create the Dessert listlstDessert=new List("Select dessert:",Choice.MULTIPLE, dessertOffers);//but not display the dessert list until the user selects the “Next” command.
  • 9. Implement CommandListener classpublic class Restaurant extends MIDlet implements CommandListener...//process commandspublic void commandAction(Command command, Displayable displayable){ String label = command.getLabel(); if(label.equals("Next")){ Display.getDisplay(this).setCurrent(lstDessert); }}...
  • 10. Add an Order Summary screen Allow the user see what s/he’s ordering. How? 1. Create the empty Order Summary screen (e.g., a form). 2. Add a command “Proceed” to the Dessert list that navigates to the Order Summary screen. 3. Add code in the commandAction method to process the “Proceed” command.
  • 11. Get the state of all elements of a list//retrieve selected main coursesboolean[] selectedMainCourses = new boolean[lstMainCourse.size()];lstMainCourse.getSelectedFlags(selectedMainCourses);String strMainCourse = "";for(int i=0; i<lstMainCourse.size(); i++){ if(selectedMainCourses[i]) strMainCourse += mainCourseOffers[i] + ", ";}//retrieve selected dessertboolean[] selectedDessert = new boolean[lstDessert.size()];lstDessert.getSelectedFlags(selectedDessert);String strDessert = "";for(int i=0; i<lstDessert.size(); i++){ if(selectedDessert[i]) strDessert += dessertOffers[i] + ", ";}//update the Order Summary form according to the selected main courses...sItemMainCourse.setText(strMainCourse);sItemDessert.setText(strDessert);Display.getDisplay(this).setCurrent(frmOrderSummary);
  • 12. Exercise:Improve Mobile Restaurant AppFind the completed code for this app on the subject web site.
  • 13. HotelBooking Application  Purpose: a customer wants to book a room at Saville Hotel  The UI can be like thisItems areForm, Gauge, Spacer, ImageItem, TextField, DateField, StringItem, ChoiceGroup
  • 14. Graphics
  • 15. javax.microedition.lcdui.Canvasclass MyCanvas extends Canvas { public void paint(Graphics g) { // create a 20x20 black square in the centre g.setColor(0xFF0000); // make sure it is red g.fillRect(getWidth()/2–10, getHeight()/2–10, 20, 20); g.setColor(0x0000FF); // make sure it is blue g.drawString("Hello World", getWidth()/2, getHeight()/2 - 10, Graphics.HCENTER | Graphics.BASELINE); }}
  • 16. References Vikram Goyal , J2ME Tutorial, http://today.java.net/pub/a/today/2005/02/09/j2me1.html, 02/09/2005 Michael Juntao Yuan & Kevin Sharp, JavaWorld.com, www.javaworld.com/javaworld/jw-05-2005/jw-0516-midp.html, 05/16/2005 http://developer.symbian.com/main/oslibrary/java_papers/midp.jsp http://developers.sun.com/mobility/apis/articles/wsa/ Eric Giguere, Databases and MIDP, Part 1: Understanding the Record Management System, http://developers.sun.com/mobility/midp/articles/databaserms, 2004 http://www.java2s.com/Code/Java/J2ME/Persistencestoringandshowin ggamescores.htm http://today.java.net/pub/a/today/2005/05/03/midletUI.html?page=4
  • 17. Time for practice

×