×
Namespaces

Variants
Actions
(Difference between revisions)

Using eSWT Browser in Java ME

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot update - Fix links)
skalogir (Talk | contribs)
(Skalogir -)
Line 1: Line 1:
{{Archived|timestamp=20120313125655|user=roy.debjit| }}
+
[[Category:Java ME]][[Category:MIDP 2.0]][[Category:Browser]][[Category:ESWT API]][[Category:Code Examples]][[Category:Symbian]]
[[Category:S60 3rd Edition FP2]][[Category:Java ME]][[Category:MIDP 2.0]][[Category:Code Snippet]][[Category:Browser]][[Category:Code Snippet]][[Category:ESWT API]]
+
[[Category:S60 3rd Edition FP2]]
 +
[[Category:S60 5th Edition]]
 +
[[Category:Symbian^3]] [[Category:Symbian Anna]] [[Category:Nokia Belle]]  
  
 +
{{VersionHint}}
 
{{ArticleMetaData <!-- v1.2 -->
 
{{ArticleMetaData <!-- v1.2 -->
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
+
|sourcecode= [[Media:BrowserMIDletSource.zip]]
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
+
|installfile= [[Media:BrowserMIDletBinaries.zip]]
 
|devices= S60 3rd Ed. FP2 SDK
 
|devices= S60 3rd Ed. FP2 SDK
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
+
|sdk= [http://www.developer.nokia.com/info/sw.nokia.com/id/ec866fab-4b76-49f6-b5a5-af0631419e9c/S60_All_in_One_SDKs.html S60 SDK 3rd Edition FP2 v1.1]
|platform= S60 3rd Edition, FP2
+
|platform= S60 3rd Edition, FP2 or later
 
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
 
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
 
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
Line 17: Line 20:
 
|translated-from-title= <!-- Title only -->
 
|translated-from-title= <!-- Title only -->
 
|translated-from-id= <!-- Id of translated revision -->
 
|translated-from-id= <!-- Id of translated revision -->
|review-by= <!-- After re-review: [[User:username]] -->
+
|review-by= [[User:skalogir]]
|review-timestamp= <!-- After re-review: YYYYMMDD -->
+
|review-timestamp= 20120820
|update-by= <!-- After significant update: [[User:username]]-->
+
|update-by= [[User:skalogir]]
|update-timestamp= <!-- After significant update: YYYYMMDD -->
+
|update-timestamp= 20120820
 
|creationdate= 20080520
 
|creationdate= 20080520
 
|author= [[User:Jarmlaht]]
 
|author= [[User:Jarmlaht]]
Line 29: Line 32:
 
    
 
    
 
==Overview==
 
==Overview==
 +
 +
<gallery widths=240px heights=320px>
 +
File:BrowserMIDlet.jpg|A Browser-MIDlet integration
 +
File:BrowserMIDletOptions.jpg|The custom Browser with the Option menu expanded
 +
</gallery>
  
 
This code snippet demonstrates how to use eSWT's Browser class in Java ME. The Browser class instance implements the browser user interface metaphor and it allows the user to visualize and navigate through HTML documents. This example has also "Back", "Forward",  and "Open URL" Commands for navigating to the previous or next session history items and for opening desired html page. The MIDlet uses MobileShell, because it has a possibility to change the status pane size. The following section contains the complete code for compiling and running the example application.
 
This code snippet demonstrates how to use eSWT's Browser class in Java ME. The Browser class instance implements the browser user interface metaphor and it allows the user to visualize and navigate through HTML documents. This example has also "Back", "Forward",  and "Open URL" Commands for navigating to the previous or next session history items and for opening desired html page. The MIDlet uses MobileShell, because it has a possibility to change the status pane size. The following section contains the complete code for compiling and running the example application.
Line 47: Line 55:
 
import org.eclipse.ercp.swt.mobile.QueryDialog;
 
import org.eclipse.ercp.swt.mobile.QueryDialog;
 
import org.eclipse.ercp.swt.mobile.Command;
 
import org.eclipse.ercp.swt.mobile.Command;
 
+
 
+
 
public class BrowserMIDlet extends MIDlet implements SelectionListener, Runnable {
 
public class BrowserMIDlet extends MIDlet implements SelectionListener, Runnable {
 
     private Command exitCommand;
 
     private Command exitCommand;
Line 61: Line 69:
 
     private boolean exiting = false;
 
     private boolean exiting = false;
 
     private int style = 2;  //MobileShell.SMALL_STATUS_PANE
 
     private int style = 2;  //MobileShell.SMALL_STATUS_PANE
     private String url = "http://forumnokia.mobi";
+
     private String url = "http://www.google.com";
   
+
 
     public void startApp() {
 
     public void startApp() {
 
         if(uiThread == null) {
 
         if(uiThread == null) {
Line 69: Line 77:
 
         }         
 
         }         
 
     }
 
     }
 
+
 
     public void pauseApp() {
 
     public void pauseApp() {
 +
    //To do
 
     }
 
     }
 
+
 
     public void destroyApp(boolean unconditional) {
 
     public void destroyApp(boolean unconditional) {
 
         exitEventLoop();
 
         exitEventLoop();
Line 79: Line 88:
 
         }  
 
         }  
 
         catch(InterruptedException e) {
 
         catch(InterruptedException e) {
 +
        //To do
 
         }         
 
         }         
 
     }
 
     }
   
+
 
     void exitEventLoop() {
 
     void exitEventLoop() {
 
         exiting = true;
 
         exiting = true;
 
         Display.getDefault().wake();
 
         Display.getDefault().wake();
 
     }
 
     }
 
+
 
     public void run() {
 
     public void run() {
 
         display = new Display();
 
         display = new Display();
Line 127: Line 137:
 
         notifyDestroyed();  // exit MIDlet
 
         notifyDestroyed();  // exit MIDlet
 
     }
 
     }
 
+
 
     public void widgetSelected(SelectionEvent e) {
 
     public void widgetSelected(SelectionEvent e) {
 
         if (e.widget.equals(exitCommand)) {
 
         if (e.widget.equals(exitCommand)) {
Line 153: Line 163:
 
         }
 
         }
 
     }
 
     }
 
+
 
     public void widgetDefaultSelected(SelectionEvent arg0) {
 
     public void widgetDefaultSelected(SelectionEvent arg0) {
 +
    //To do
 
     }     
 
     }     
 
}
 
}
Line 161: Line 172:
 
==Postconditions==
 
==Postconditions==
  
When a {{Icode|BrowserMIDlet}} is opened, a browser window is shown on the screen. The browser will open the URL http://forumnokia.mobi.
+
When a {{Icode|BrowserMIDlet}} is opened, a browser window is shown on the screen. The browser will open the URL http://www.google.com.
  
 
==See also==
 
==See also==
  
 
* [[ESWT|eSWT]]
 
* [[ESWT|eSWT]]

Revision as of 13:28, 20 August 2012


Contents

Version Hint

Windows Phone: [[Category:Windows Phone]]
[[Category:Windows Phone 7.5]]
[[Category:Windows Phone 8]]

Nokia Asha: [[Category:Nokia Asha]]
[[Category:Nokia Asha Platform 1.0]]

Series 40: [[Category:Series 40]]
[[Category:Series 40 1st Edition]] [[Category:Series 40 2nd Edition]]
[[Category:Series 40 3rd Edition (initial release)]] [[Category:Series 40 3rd Edition FP1]] [[Category:Series 40 3rd Edition FP2]]
[[Category:Series 40 5th Edition (initial release)]] [[Category:Series 40 5th Edition FP1]]
[[Category:Series 40 6th Edition (initial release)]] [[Category:Series 40 6th Edition FP1]] [[Category:Series 40 Developer Platform 1.0]] [[Category:Series 40 Developer Platform 1.1]] [[Category:Series 40 Developer Platform 2.0]]

Symbian: [[Category:Symbian]]
[[Category:S60 1st Edition]] [[Category:S60 2nd Edition (initial release)]] [[Category:S60 2nd Edition FP1]] [[Category:S60 2nd Edition FP2]] [[Category:S60 2nd Edition FP3]]
[[Category:S60 3rd Edition (initial release)]] [[Category:S60 3rd Edition FP1]] [[Category:S60 3rd Edition FP2]]
[[Category:S60 5th Edition]]
[[Category:Symbian^3]] [[Category:Symbian Anna]] [[Category:Nokia Belle]]

Article Metadata
Code ExampleTested with
Devices(s): S60 3rd Ed. FP2 SDK
CompatibilityArticle
Keywords: eSWT, Browser, QueryDialog, MobileShell, MessageBox
Created: jarmlaht (20 May 2008)
Updated: skalogir (20 Aug 2012)
Reviewed: skalogir (20 Aug 2012)
Last edited: skalogir (20 Aug 2012)

Overview

This code snippet demonstrates how to use eSWT's Browser class in Java ME. The Browser class instance implements the browser user interface metaphor and it allows the user to visualize and navigate through HTML documents. This example has also "Back", "Forward", and "Open URL" Commands for navigating to the previous or next session history items and for opening desired html page. The MIDlet uses MobileShell, because it has a possibility to change the status pane size. The following section contains the complete code for compiling and running the example application.

Source code

import javax.microedition.midlet.MIDlet;
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTError;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ercp.swt.mobile.MobileShell;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.browser.Browser;
import org.eclipse.ercp.swt.mobile.QueryDialog;
import org.eclipse.ercp.swt.mobile.Command;
 
 
public class BrowserMIDlet extends MIDlet implements SelectionListener, Runnable {
private Command exitCommand;
private Command backCommand;
private Command openCommand;
private Command forwardCommand;
private Command changeCommand;
private Display display;
private MobileShell shell;
private Thread uiThread;
private Browser browser = null;
private boolean exiting = false;
private int style = 2; //MobileShell.SMALL_STATUS_PANE
private String url = "http://www.google.com";
 
public void startApp() {
if(uiThread == null) {
uiThread = new Thread(this);
uiThread.start();
}
}
 
public void pauseApp() {
//To do
}
 
public void destroyApp(boolean unconditional) {
exitEventLoop();
try {
uiThread.join();
}
catch(InterruptedException e) {
//To do
}
}
 
void exitEventLoop() {
exiting = true;
Display.getDefault().wake();
}
 
public void run() {
display = new Display();
shell = new MobileShell(display, SWT.NONE, style);
shell.setLayout(new FillLayout());
exitCommand = new Command(shell, Command.EXIT, 0);
exitCommand.setText("Exit");
exitCommand.addSelectionListener(this);
backCommand = new Command(shell, Command.BACK, 0);
backCommand.setText("Back");
backCommand.addSelectionListener(this);
forwardCommand = new Command(shell, Command.OK, 0);
forwardCommand.setText("Forward");
forwardCommand.addSelectionListener(this);
openCommand = new Command(shell, Command.OK, 1);
openCommand.setText("Enter URL");
openCommand.addSelectionListener(this);
changeCommand = new Command(shell, Command.OK, 2);
changeCommand.setText("Change status pane");
changeCommand.addSelectionListener(this);
try {
browser = new Browser(shell, SWT.NONE);
} catch (SWTError e) {
MessageBox message = new MessageBox(shell, SWT.NONE);
message.setText("SWTError: " + e.getMessage());
message.open();
}
if (browser != null) {
browser.setUrl(url);
}
shell.open();
while(!exiting) {
if(!display.readAndDispatch()) {
display.sleep();
}
}
browser.dispose(); // dispose objects
shell.dispose();
display.dispose();
notifyDestroyed(); // exit MIDlet
}
 
public void widgetSelected(SelectionEvent e) {
if (e.widget.equals(exitCommand)) {
exitEventLoop();
}
if (e.widget.equals(backCommand)) {
if (browser.isBackEnabled()) browser.back();
}
if (e.widget.equals(forwardCommand)) {
if (browser.isForwardEnabled()) browser.forward();
}
if (e.widget.equals(openCommand)) {
QueryDialog dialog = new QueryDialog(shell, SWT.NONE, QueryDialog.STANDARD);
dialog.setPromptText("Enter URL:", "http://");
url = dialog.open();
if (url != null) {
browser.setUrl(url);
shell.redraw();
} else {}
}
if (e.widget.equals(changeCommand)) {
if (style < 3) style = style + 1;
else if (style == 3) style = 1;
shell.changeTrim(SWT.SHELL_TRIM, style);
}
}
 
public void widgetDefaultSelected(SelectionEvent arg0) {
//To do
}
}

Postconditions

When a BrowserMIDlet is opened, a browser window is shown on the screen. The browser will open the URL http://www.google.com.

See also

140 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×