SlideShare a Scribd company logo
JAVA ME LWUIT, STORAGE & CONNECTIONS Fafadia-Tech PrasanjitDey prasanjit@fafadia-tech.com
LWUIT The Lightweight User Interface Toolkit (LWUIT) is a versatile and compact API for creating attractive application user interfaces for mobile devices LWUIT provides sophisticated Swing-like capabilities without the tremendous power and complexity of Swing LWUIT offers a basic set of components, flexible layouts, style and theming, animated screen transitions, and a simple and useful event-handling mechanism LWUIT is developed by Sun Microsystems and is inspired by Swing
Key Features Layouts Manager Pluggable Look and Feel & Themes Fonts Touch Screen Animations & Transitions 3D and SVG Graphics Integration Tools Bi-directional text support
Simple Lwuit Program import javax.microedition.midlet.*; import com.sun.lwuit.*; // imports LWUIT import com.sun.lwuit.layouts.BorderLayout; import com.sun.lwuit.plaf.UIManager; import com.sun.lwuit.util.Resources; import java.io.IOException; public class Hello extends MIDlet implements ActionListener { 	public void startApp() { Display.init(this); // initializes the display       try { 	// using a theme here             Resources r = Resources.open("/res/ThemeJava1.res"); UIManager.getInstance().setThemeProps(r.getTheme("ThemeJava1")); 	}      catch (IOExceptionioe) {     	  // Do something here.      }
Continued 	Form f = new Form("Hello, LWUIT!"); f.addComponent("Center",new Label("Prasanjit's j2me 	apps ")); f.show(); // display the form     Command exitCommand = new Command("Exit"); f.addCommand(exitCommand); f.setCommandListener(this);     } 	public void pauseApp() { } 	public void destroyApp(boolean unconditional) {} 	public void actionPerformed(ActionEventae) { notifyDestroyed();     } }
Output Download the LWUIT zip from http://sun.java.com/javame/technology/lwuit and add it to your project /resources directory, also add all your themes, images and other resources in a folder, zip it and add to your project/resources directory.
Simple Layout Example import javax.microedition.midlet.*; import com.sun.lwuit.layouts.BoxLayout; import com.sun.lwuit.plaf.UIManager; import com.sun.lwuit.util.Resources; import com.sun.lwuit.events.ActionListener; import com.sun.lwuit.events.ActionEvent; import java.io.IOException; public class Layouts extends MIDlet implements ActionListener { 	Form form;     	Command exit;     	public void startApp() { Display.init(this);     	try {     		Resources r = Resources.open("/res1/ThemeJava2.res"); UIManager.getInstance().setThemeProps(r.getTheme("ThemeJava2")); 	} catch(IOExceptionioe) { System.out.println(ioe);     } 	form = new Form("Layouts ");
Continued 	// adding 5 buttons on the form along with a command 	Container buttonBar = new Container(new BoxLayout(BoxLayout.X_AXIS)); buttonBar.addComponent(new Button("Add")); buttonBar.addComponent(new Button("Remove")); buttonBar.addComponent(new Button("Edit")); buttonBar.addComponent(new Button("Send")); buttonBar.addComponent(new Button("Exit"));     	exit = new Command("Exit"); form.addComponent(buttonBar); // buttonBar is a container for other buttons form.addCommand(exit); form.setCommandListener(this); form.show();  	public void pauseApp() {}     	public void destroyApp(boolean unconditional) {}     	public void actionPerformed(ActionEventae) { notifyDestroyed();     } }
Simple Event Handling import javax.microedition.midlet.*; import java.io.IOException; import com.sun.lwuit.*; import com.sun.lwuit.events.*; import com.sun.lwuit.plaf.UIManager; import com.sun.lwuit.util.Resources; public class EventHandling extends MIDlet implements ActionListener {     Form form; int c = 1000;     Label l1;     Button b1,b2;     public void startApp() { Display.init(this); 	    try {        	Resources r = Resources.open("/res1/ThemeJava2.res"); UIManager.getInstance().setThemeProps(r.getTheme("ThemeJava2")); 	} catch(IOExceptionioe) { System.out.println(ioe);     }
Continued 	Form = new Form("Event handling");     	l1 = new Label(" ");     	b1 = new Button("Change label to add "); form.addComponent(b1); form.addComponent(l1); form.show();     	b1.addActionListener(this); }     public void pauseApp() {     }     public void destroyApp(boolean unconditional) {     }     public void actionPerformed(ActionEventae)     { c++;             l1.setText("" +c); form.layoutContainer();     } }
Storage Record Management System or rms is used to provide the storage capabilities in Java ME It stores records in binary format inside the Record Stores Data is not lost even if the device is switched off rms provides various methods for storing and retrieving records: openRecordStore() closeRecordStore() deleteRecordStore() getRecord() enumerateRecords()
rms Example import java.io.*; import javax.microedition.midlet.*; import javax.microedition.rms.*; // imports all rms resources public class rmsDemo extends MIDlet { intsize_available, id; RecordStorers; 	public rmsDemo() { openStore(); // open recordstore addRecord(); // adds record into recordstore getRecord(); // gets all rcords closeStore(); // closes the recordstore 	} 	public void startApp() {} 	public void pauseApp() {} 	public void destroyApp(boolean unconditional) {} 	public void openStore() { 	try { rs=RecordStore.openRecordStore("names",true); size_available=rs.getSizeAvailable(); System.out.println("Start"); System.out.println("Available size is " +size_available); 	}
Continued 	catch(Exception e) {	 System.out.println(e); 	} 	} 	public void closeStore() { 	try { rs.closeRecordStore(); 	} catch(Exception e) {	 System.out.println(e); 	} 	} 	public void addRecord() { 	try { 		String record="java ME persistent storage"; 		byte data[]=record.getBytes(); // converts into bytes of data 		id=rs.addRecord(data,0,data.length); 	} catch(Exception e) {	 System.out.println(e); 	} }
Continued 	public void getRecord() { 	try { 		byte getData[]= rs.getRecord(id); // gets the record System.out.print("Records in byte format: "); 		for(int j=0;j<getData.length;j++) 		{ System.out.print(getData[j]); System.out.print(" "); 		} System.out.println(); System.out.print("Records in string format: "); 		for(inti=0;i<getData.length;i++) 		{ System.out.print(new String(new byte[]{getData[i]})); 		} System.out.println(); System.out.println("Done with it"); 	} catch(Exception e) {	 System.out.println(e); 	}  	} }
Connections All the important classes and methods for connecting the to the wireless network are included in the javax.microedition.io.* package The connections types are provided by the InputStream and the OutputStream interfaces These interfaces adds the ability to input and output data over the network There are three important level of connections available  Socket Datagram HTTP connection
Http Example In this program, we create a form and add a command to it. On clicking the command, the data from the url is displayed on the device. Here is the actual thread to display the data on the device. public void commandAction(Command c, Displayable d)	{ 		if(c==exit) { destroyApp(true); notifyDestroyed(); 		} else {	 		new Thread(new Runnable() { 				public void run() { 				try { HttpConnectionconn = null; 					String url = "http://www.burrp.com/robots.txt"; InputStream is = null; 					try {
Continued conn = (HttpConnection)Connector.open(url); conn.setRequestMethod(HttpConnection.GET); conn.setRequestProperty("User-Agent","Profile/MIDP-2.1 Confirguration/CLDC-1.1"); intrespCode = conn.getResponseCode(); 	if (respCode == conn.HTTP_OK)  { StringBuffersb = new StringBuffer(); 		is = conn.openDataInputStream(); intchr; 		while ((chr = is.read()) != -1) sb.append((char) chr);						form.append("Here is the records from www.burrp.com: " + sb.toString()); 	} else { System.out.println("Error in opening HTTP Connection. Error#" + respCode); 	} 	} 	catch(Exception e) { System.out.println(e); 	}
Continued 	finally { 	try { 		if(is!= null) is.close(); 		if(conn != null) conn.close(); 	} 	catch(Exception e) { System.out.println(e); 	} 	} 	} 	catch(Exception e) {	 System.out.println(e); 	} 	} 	} 	).start(); } }
Thank You

More Related Content

What's hot

Java practical
Java practicalJava practical
Java practical
william otto
 
Modern Java Development
Modern Java DevelopmentModern Java Development
Modern Java Development
Angel Conde Manjon
 
Backendless apps
Backendless appsBackendless apps
Backendless apps
Matteo Bonifazi
 
Android - Saving data
Android - Saving dataAndroid - Saving data
Android - Saving data
Matteo Bonifazi
 
Java: GUI
Java: GUIJava: GUI
Java: GUI
Tareq Hasan
 
Simple API for XML
Simple API for XMLSimple API for XML
Simple API for XML
guest2556de
 
Graphical User Components Part 1
Graphical User Components Part 1Graphical User Components Part 1
Graphical User Components Part 1
Andy Juan Sarango Veliz
 
Introdução à programação orientada para aspectos
Introdução à programação orientada para aspectosIntrodução à programação orientada para aspectos
Introdução à programação orientada para aspectos
Manuel Menezes de Sequeira
 
Java swing
Java swingJava swing
Java swing
Arati Gadgil
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commandsleminhvuong
 
Code generation for alternative languages
Code generation for alternative languagesCode generation for alternative languages
Code generation for alternative languages
Rafael Winterhalter
 
Java- GUI- Mazenet solution
Java- GUI- Mazenet solutionJava- GUI- Mazenet solution
Java- GUI- Mazenet solution
Mazenetsolution
 
JDI 2.0. Not only UI testing
JDI 2.0. Not only UI testingJDI 2.0. Not only UI testing
JDI 2.0. Not only UI testing
COMAQA.BY
 
JEEConf 2017 - The hitchhiker’s guide to Java class reloading
JEEConf 2017 - The hitchhiker’s guide to Java class reloadingJEEConf 2017 - The hitchhiker’s guide to Java class reloading
JEEConf 2017 - The hitchhiker’s guide to Java class reloading
Anton Arhipov
 
Oracle 10g
Oracle 10gOracle 10g
Oracle 10g
Svetlin Nakov
 
Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011Anton Arhipov
 
Amazon Cognito使って認証したい?それならSpring Security使いましょう!
Amazon Cognito使って認証したい?それならSpring Security使いましょう!Amazon Cognito使って認証したい?それならSpring Security使いましょう!
Amazon Cognito使って認証したい?それならSpring Security使いましょう!
Ryosuke Uchitate
 
Swing
SwingSwing

What's hot (20)

Java practical
Java practicalJava practical
Java practical
 
Modern Java Development
Modern Java DevelopmentModern Java Development
Modern Java Development
 
Backendless apps
Backendless appsBackendless apps
Backendless apps
 
Android - Saving data
Android - Saving dataAndroid - Saving data
Android - Saving data
 
Java: GUI
Java: GUIJava: GUI
Java: GUI
 
Simple API for XML
Simple API for XMLSimple API for XML
Simple API for XML
 
Graphical User Components Part 1
Graphical User Components Part 1Graphical User Components Part 1
Graphical User Components Part 1
 
Introdução à programação orientada para aspectos
Introdução à programação orientada para aspectosIntrodução à programação orientada para aspectos
Introdução à programação orientada para aspectos
 
Java swing
Java swingJava swing
Java swing
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commands
 
Code generation for alternative languages
Code generation for alternative languagesCode generation for alternative languages
Code generation for alternative languages
 
Java swing
Java swingJava swing
Java swing
 
Java- GUI- Mazenet solution
Java- GUI- Mazenet solutionJava- GUI- Mazenet solution
Java- GUI- Mazenet solution
 
JDI 2.0. Not only UI testing
JDI 2.0. Not only UI testingJDI 2.0. Not only UI testing
JDI 2.0. Not only UI testing
 
JEEConf 2017 - The hitchhiker’s guide to Java class reloading
JEEConf 2017 - The hitchhiker’s guide to Java class reloadingJEEConf 2017 - The hitchhiker’s guide to Java class reloading
JEEConf 2017 - The hitchhiker’s guide to Java class reloading
 
Oracle 10g
Oracle 10gOracle 10g
Oracle 10g
 
Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011
 
Amazon Cognito使って認証したい?それならSpring Security使いましょう!
Amazon Cognito使って認証したい?それならSpring Security使いましょう!Amazon Cognito使って認証したい?それならSpring Security使いましょう!
Amazon Cognito使って認証したい?それならSpring Security使いましょう!
 
04b swing tutorial
04b swing tutorial04b swing tutorial
04b swing tutorial
 
Swing
SwingSwing
Swing
 

Similar to J2ME Lwuit, Storage & Connections (Ft Prasanjit Dey)

Quick Intro to Android Development
Quick Intro to Android DevelopmentQuick Intro to Android Development
Quick Intro to Android DevelopmentJussi Pohjolainen
 
Introduction To Google Android (Ft Rohan Bomle)
Introduction To Google Android (Ft Rohan Bomle)Introduction To Google Android (Ft Rohan Bomle)
Introduction To Google Android (Ft Rohan Bomle)
Fafadia Tech
 
F# And Silverlight
F# And SilverlightF# And Silverlight
F# And Silverlight
Talbott Crowell
 
Java Programming for Designers
Java Programming for DesignersJava Programming for Designers
Java Programming for Designers
R. Sosa
 
L11cs2110sp13
L11cs2110sp13L11cs2110sp13
L11cs2110sp13
karan saini
 
Guide to Generate Extent Report in Kotlin
Guide to Generate Extent Report in KotlinGuide to Generate Extent Report in Kotlin
Guide to Generate Extent Report in Kotlin
RapidValue
 
Android best practices
Android best practicesAndroid best practices
Android best practices
Jose Manuel Ortega Candel
 
Dojo and Adobe AIR
Dojo and Adobe AIRDojo and Adobe AIR
Dojo and Adobe AIR
Nikolai Onken
 
Struts 2 + Spring
Struts 2 + SpringStruts 2 + Spring
Struts 2 + Spring
Bryan Hsueh
 
Top 3 SWT Exceptions
Top 3 SWT ExceptionsTop 3 SWT Exceptions
Top 3 SWT ExceptionsLakshmi Priya
 
The java rogramming swing _tutorial for beinners(java programming language)
The java rogramming swing _tutorial for beinners(java programming language)The java rogramming swing _tutorial for beinners(java programming language)
The java rogramming swing _tutorial for beinners(java programming language)
Daroko blog(www.professionalbloggertricks.com)
 
The java swing_tutorial
The java swing_tutorialThe java swing_tutorial
The java swing_tutorialsumitjoshi01
 
What do you mean it needs to be Java based? How jython saved the day.
What do you mean it needs to be Java based? How jython saved the day.What do you mean it needs to be Java based? How jython saved the day.
What do you mean it needs to be Java based? How jython saved the day.
Mark Rees
 
How to become an Android dev starting from iOS (and vice versa)
How to become an Android dev starting from iOS (and vice versa)How to become an Android dev starting from iOS (and vice versa)
How to become an Android dev starting from iOS (and vice versa)
Giuseppe Filograno
 
From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)
Jose Manuel Pereira Garcia
 
Open Cv 2005 Q4 Tutorial
Open Cv 2005 Q4 TutorialOpen Cv 2005 Q4 Tutorial
Open Cv 2005 Q4 Tutorial
antiw
 
Package org dev
Package org devPackage org dev
Package org dev
jaya lakshmi
 
YUI 3
YUI 3YUI 3
YUI 3
Dav Glass
 

Similar to J2ME Lwuit, Storage & Connections (Ft Prasanjit Dey) (20)

Quick Intro to Android Development
Quick Intro to Android DevelopmentQuick Intro to Android Development
Quick Intro to Android Development
 
Introduction To Google Android (Ft Rohan Bomle)
Introduction To Google Android (Ft Rohan Bomle)Introduction To Google Android (Ft Rohan Bomle)
Introduction To Google Android (Ft Rohan Bomle)
 
F# And Silverlight
F# And SilverlightF# And Silverlight
F# And Silverlight
 
Java Programming for Designers
Java Programming for DesignersJava Programming for Designers
Java Programming for Designers
 
L11cs2110sp13
L11cs2110sp13L11cs2110sp13
L11cs2110sp13
 
Google Web Toolkit
Google Web ToolkitGoogle Web Toolkit
Google Web Toolkit
 
Guide to Generate Extent Report in Kotlin
Guide to Generate Extent Report in KotlinGuide to Generate Extent Report in Kotlin
Guide to Generate Extent Report in Kotlin
 
Android best practices
Android best practicesAndroid best practices
Android best practices
 
Dojo and Adobe AIR
Dojo and Adobe AIRDojo and Adobe AIR
Dojo and Adobe AIR
 
Struts 2 + Spring
Struts 2 + SpringStruts 2 + Spring
Struts 2 + Spring
 
Top 3 SWT Exceptions
Top 3 SWT ExceptionsTop 3 SWT Exceptions
Top 3 SWT Exceptions
 
The java rogramming swing _tutorial for beinners(java programming language)
The java rogramming swing _tutorial for beinners(java programming language)The java rogramming swing _tutorial for beinners(java programming language)
The java rogramming swing _tutorial for beinners(java programming language)
 
The java swing_tutorial
The java swing_tutorialThe java swing_tutorial
The java swing_tutorial
 
What do you mean it needs to be Java based? How jython saved the day.
What do you mean it needs to be Java based? How jython saved the day.What do you mean it needs to be Java based? How jython saved the day.
What do you mean it needs to be Java based? How jython saved the day.
 
How to become an Android dev starting from iOS (and vice versa)
How to become an Android dev starting from iOS (and vice versa)How to become an Android dev starting from iOS (and vice versa)
How to become an Android dev starting from iOS (and vice versa)
 
From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)
 
Open Cv 2005 Q4 Tutorial
Open Cv 2005 Q4 TutorialOpen Cv 2005 Q4 Tutorial
Open Cv 2005 Q4 Tutorial
 
package org dev
package org devpackage org dev
package org dev
 
Package org dev
Package org devPackage org dev
Package org dev
 
YUI 3
YUI 3YUI 3
YUI 3
 

Recently uploaded

How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 

Recently uploaded (20)

How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 

J2ME Lwuit, Storage & Connections (Ft Prasanjit Dey)

  • 1. JAVA ME LWUIT, STORAGE & CONNECTIONS Fafadia-Tech PrasanjitDey prasanjit@fafadia-tech.com
  • 2. LWUIT The Lightweight User Interface Toolkit (LWUIT) is a versatile and compact API for creating attractive application user interfaces for mobile devices LWUIT provides sophisticated Swing-like capabilities without the tremendous power and complexity of Swing LWUIT offers a basic set of components, flexible layouts, style and theming, animated screen transitions, and a simple and useful event-handling mechanism LWUIT is developed by Sun Microsystems and is inspired by Swing
  • 3. Key Features Layouts Manager Pluggable Look and Feel & Themes Fonts Touch Screen Animations & Transitions 3D and SVG Graphics Integration Tools Bi-directional text support
  • 4. Simple Lwuit Program import javax.microedition.midlet.*; import com.sun.lwuit.*; // imports LWUIT import com.sun.lwuit.layouts.BorderLayout; import com.sun.lwuit.plaf.UIManager; import com.sun.lwuit.util.Resources; import java.io.IOException; public class Hello extends MIDlet implements ActionListener { public void startApp() { Display.init(this); // initializes the display try { // using a theme here Resources r = Resources.open("/res/ThemeJava1.res"); UIManager.getInstance().setThemeProps(r.getTheme("ThemeJava1")); } catch (IOExceptionioe) { // Do something here. }
  • 5. Continued Form f = new Form("Hello, LWUIT!"); f.addComponent("Center",new Label("Prasanjit's j2me apps ")); f.show(); // display the form Command exitCommand = new Command("Exit"); f.addCommand(exitCommand); f.setCommandListener(this); } public void pauseApp() { } public void destroyApp(boolean unconditional) {} public void actionPerformed(ActionEventae) { notifyDestroyed(); } }
  • 6. Output Download the LWUIT zip from http://sun.java.com/javame/technology/lwuit and add it to your project /resources directory, also add all your themes, images and other resources in a folder, zip it and add to your project/resources directory.
  • 7. Simple Layout Example import javax.microedition.midlet.*; import com.sun.lwuit.layouts.BoxLayout; import com.sun.lwuit.plaf.UIManager; import com.sun.lwuit.util.Resources; import com.sun.lwuit.events.ActionListener; import com.sun.lwuit.events.ActionEvent; import java.io.IOException; public class Layouts extends MIDlet implements ActionListener { Form form; Command exit; public void startApp() { Display.init(this); try { Resources r = Resources.open("/res1/ThemeJava2.res"); UIManager.getInstance().setThemeProps(r.getTheme("ThemeJava2")); } catch(IOExceptionioe) { System.out.println(ioe); } form = new Form("Layouts ");
  • 8. Continued // adding 5 buttons on the form along with a command Container buttonBar = new Container(new BoxLayout(BoxLayout.X_AXIS)); buttonBar.addComponent(new Button("Add")); buttonBar.addComponent(new Button("Remove")); buttonBar.addComponent(new Button("Edit")); buttonBar.addComponent(new Button("Send")); buttonBar.addComponent(new Button("Exit")); exit = new Command("Exit"); form.addComponent(buttonBar); // buttonBar is a container for other buttons form.addCommand(exit); form.setCommandListener(this); form.show(); public void pauseApp() {} public void destroyApp(boolean unconditional) {} public void actionPerformed(ActionEventae) { notifyDestroyed(); } }
  • 9. Simple Event Handling import javax.microedition.midlet.*; import java.io.IOException; import com.sun.lwuit.*; import com.sun.lwuit.events.*; import com.sun.lwuit.plaf.UIManager; import com.sun.lwuit.util.Resources; public class EventHandling extends MIDlet implements ActionListener { Form form; int c = 1000; Label l1; Button b1,b2; public void startApp() { Display.init(this); try { Resources r = Resources.open("/res1/ThemeJava2.res"); UIManager.getInstance().setThemeProps(r.getTheme("ThemeJava2")); } catch(IOExceptionioe) { System.out.println(ioe); }
  • 10. Continued Form = new Form("Event handling"); l1 = new Label(" "); b1 = new Button("Change label to add "); form.addComponent(b1); form.addComponent(l1); form.show(); b1.addActionListener(this); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } public void actionPerformed(ActionEventae) { c++; l1.setText("" +c); form.layoutContainer(); } }
  • 11. Storage Record Management System or rms is used to provide the storage capabilities in Java ME It stores records in binary format inside the Record Stores Data is not lost even if the device is switched off rms provides various methods for storing and retrieving records: openRecordStore() closeRecordStore() deleteRecordStore() getRecord() enumerateRecords()
  • 12. rms Example import java.io.*; import javax.microedition.midlet.*; import javax.microedition.rms.*; // imports all rms resources public class rmsDemo extends MIDlet { intsize_available, id; RecordStorers; public rmsDemo() { openStore(); // open recordstore addRecord(); // adds record into recordstore getRecord(); // gets all rcords closeStore(); // closes the recordstore } public void startApp() {} public void pauseApp() {} public void destroyApp(boolean unconditional) {} public void openStore() { try { rs=RecordStore.openRecordStore("names",true); size_available=rs.getSizeAvailable(); System.out.println("Start"); System.out.println("Available size is " +size_available); }
  • 13. Continued catch(Exception e) { System.out.println(e); } } public void closeStore() { try { rs.closeRecordStore(); } catch(Exception e) { System.out.println(e); } } public void addRecord() { try { String record="java ME persistent storage"; byte data[]=record.getBytes(); // converts into bytes of data id=rs.addRecord(data,0,data.length); } catch(Exception e) { System.out.println(e); } }
  • 14. Continued public void getRecord() { try { byte getData[]= rs.getRecord(id); // gets the record System.out.print("Records in byte format: "); for(int j=0;j<getData.length;j++) { System.out.print(getData[j]); System.out.print(" "); } System.out.println(); System.out.print("Records in string format: "); for(inti=0;i<getData.length;i++) { System.out.print(new String(new byte[]{getData[i]})); } System.out.println(); System.out.println("Done with it"); } catch(Exception e) { System.out.println(e); } } }
  • 15. Connections All the important classes and methods for connecting the to the wireless network are included in the javax.microedition.io.* package The connections types are provided by the InputStream and the OutputStream interfaces These interfaces adds the ability to input and output data over the network There are three important level of connections available Socket Datagram HTTP connection
  • 16. Http Example In this program, we create a form and add a command to it. On clicking the command, the data from the url is displayed on the device. Here is the actual thread to display the data on the device. public void commandAction(Command c, Displayable d) { if(c==exit) { destroyApp(true); notifyDestroyed(); } else { new Thread(new Runnable() { public void run() { try { HttpConnectionconn = null; String url = "http://www.burrp.com/robots.txt"; InputStream is = null; try {
  • 17. Continued conn = (HttpConnection)Connector.open(url); conn.setRequestMethod(HttpConnection.GET); conn.setRequestProperty("User-Agent","Profile/MIDP-2.1 Confirguration/CLDC-1.1"); intrespCode = conn.getResponseCode(); if (respCode == conn.HTTP_OK) { StringBuffersb = new StringBuffer(); is = conn.openDataInputStream(); intchr; while ((chr = is.read()) != -1) sb.append((char) chr); form.append("Here is the records from www.burrp.com: " + sb.toString()); } else { System.out.println("Error in opening HTTP Connection. Error#" + respCode); } } catch(Exception e) { System.out.println(e); }
  • 18. Continued finally { try { if(is!= null) is.close(); if(conn != null) conn.close(); } catch(Exception e) { System.out.println(e); } } } catch(Exception e) { System.out.println(e); } } } ).start(); } }