SlideShare ist ein Scribd-Unternehmen logo
1 von 19
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

Weitere ähnliche Inhalte

Was ist angesagt?

Simple API for XML
Simple API for XMLSimple API for XML
Simple API for XMLguest2556de
 
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 aspectosManuel Menezes de Sequeira
 
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 languagesRafael Winterhalter
 
Java- GUI- Mazenet solution
Java- GUI- Mazenet solutionJava- GUI- Mazenet solution
Java- GUI- Mazenet solutionMazenetsolution
 
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 testingCOMAQA.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 reloadingAnton Arhipov
 
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
 

Was ist angesagt? (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
 

Ähnlich wie 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
 
Java Programming for Designers
Java Programming for DesignersJava Programming for Designers
Java Programming for DesignersR. Sosa
 
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 KotlinRapidValue
 
Struts 2 + Spring
Struts 2 + SpringStruts 2 + Spring
Struts 2 + SpringBryan Hsueh
 
Top 3 SWT Exceptions
Top 3 SWT ExceptionsTop 3 SWT Exceptions
Top 3 SWT ExceptionsLakshmi Priya
 
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 Tutorialantiw
 

Ähnlich wie 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
 

Kürzlich hochgeladen

(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate AgentsRyan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate AgentsRyan Mahoney
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 

Kürzlich hochgeladen (20)

(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate AgentsRyan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 

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(); } }