Java- LWUIT N Amanquah.

Slides:



Advertisements
Similar presentations
1 Graphical User Interface (GUI) Applications Abstract Windowing Toolkit (AWT) Events Handling Applets.
Advertisements

Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
MIDP Mobile Information Device Profile Johnny Yau CIS 642 Prof. Insup Lee.
CS18000: Problem Solving and Object-Oriented Programming.
Graphic User Interfaces Layout Managers Event Handling.
June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 1 Lecture 9 Object Oriented Programming in Java Advanced Topics Abstract Windowing.
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
CS3157 Java UI Recitation. Material Covered: Overview of AWT components, Event Handling, creating applets, and sample UI. Not covered in recitation: Drawing,
Chapter 7 GUI design. So far this semester Have programmed in a stop and wait mode Program displays dialog box and waits for user to respond This was.
Developing J2ME Applications Mobile and Wireless Networks.
Io package as Java’s basic I/O system continue’d.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 12 Using the KToolbar Rob Pooley
Java Programming Chapter 10 Graphical User Interfaces.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Combo Box, Check Boxes, and Radio Buttons. Radio Buttons User can click radio buttons, just like other buttons BUT Radio buttons are mutually exclusive.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
1 Event Driven Programming wirh Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
DUE Hello World on the Android Platform.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 12 lcdui Rob Pooley
Graphical User Interface CSI 1101 N. El Kadri. Plan - agenda Graphical components Model-View-Controller Observer/Observable.
עקרונות תכנות מונחה עצמים תרגול 4 - GUI. Outline  Introduction to GUI  Swing  Basic components  Event handling.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
3461A Readings from the Swing Tutorial. 3461A Overview  The follow is the Table of Contents from the trail “Creating a GUI with JFC/Swing” in the “The.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 13 lcdui and OXO Rob Pooley
1 Outline 1 Introduction 2 Overview of Swing Components 3 JLabel 4 Event Handling 5 TextFields 6 How Event Handling Works 7 JButton 8 JCheckBox and JRadioButton.
Chapter 12 1 TOPIC 13B l Buttons and Action Listeners Window Interfaces Using Swing Objects.
Layout Managers Arranges and lays out the GUI components on a container.
Java Applets: GUI Components, Events, Etc. Ralph Westfall June, 2010.
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
GUI Programming using NetBeans. RHS – SOC 2 GUI construction We have previously talked about elements in a (simple) GUI –Frames, Panes and Dialogs –Text.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
CS324e - Elements of Graphics and Visualization Java GUIs - Event Handling.
CS-1020 Dr. Mark L. Hornick 1 Event-Driven Programming.
SEEM3460 Tutorial GUI in Java. Some Basic GUI Terms Component (Control in some languages) the basic GUI unit something visible something that user can.
Introduction to GUI in 1 Graphical User Interface 2 Nouf Almunyif.
Introduction to Java Chapter 9 - Graphical User Interfaces and Applets1 Chapter 9 Graphical User Interfaces and Applets.
Ajmer Singh PGT(IP) JAVA IDE Programming - I. Ajmer Singh PGT(IP) GUI (Graphical User Interface) It is an interface that uses a graphic entities along.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
1 Event Driven Programs with a Graphical User Interface Rick Mercer.
Graphical User Interfaces (GUI). PART ONE About GUI’s.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
1 Introduction to J2ME Outline MIDP Building J2ME Apps- Tool J2ME Wireless Toolkit Demo MIDlet Programming -- MIDlet Transition States -- Midlet Skeleton.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Applets. 9/04/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L12: Applets Slide 2 Applets Usually.
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
CIS 270—Application Development II Chapter 11—GUI Components: Part I.
GUIs & Event-Driven Programming Chapter 11 Review.
AWT Vs SWING. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in most Java textbooks Adequate for many applications Uses.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 7 Event-Driven Programming and Basic GUI Objects.
A Quick Java Swing Tutorial
GUIs and Events Rick Mercer.
CSC 205 Programming II Lecture 5 AWT - I.
Java- I/O, SMS etc N Amanquah.
Lecture 09 Applets.
Java Swing.
Review: Java GUI Programming
Graphical User Interface (pronounced "gooey")
Using Procedures and Exception Handling
Ellen Walker Hiram College
Chap 7. Building Java Graphical User Interfaces
Graphical User Interfaces -- Introduction
Timer class and inner classes
The structure of Interactive Software
Advanced Programming in Java
Constructors, GUI’s(Using Swing) and ActionListner
Presentation transcript:

Java- LWUIT N Amanquah

Lab work Build an application that does the following: Make use of netbeans: Fetch data from the user (the user’s preferences) Send it by sms to another number. Store the data you have collected in a record store so that it can be retrieved the next time the user runs the program. One menu item should allow the user to enter the values afresh, or to fetch the saved values.

LWUIT LightWeight User Interface Toolkit (LWUIT) [loo-it] Cf Limited Capability Device User Interface (LCDUI) API Swing inspired provide a consistent, compelling look and feel Supports cool screen transitions eg fade, flip, slide, also cube Themes for look and feel Supported on >=MIDP 2.0 devices

Lwuit class hierarchy Resource editor for visual design Add Lwuit.jar to resources for the project

Hello world import javax.microedition.midlet.*; import com.sun.lwuit.*; //note the imports import com.sun.lwuit.events.*; public class Midlet extends MIDlet implements ActionListener { //not CommandListener Display.init(this); //init the display Form f = new Form("Hello, LWUIT!"); f.show(); Command exitCommand = new Command("Exit"); f.addCommand(exitCommand); f.setCommandListener(this); } public void pauseApp() {} public void destroyApp(boolean unconditional) {} public void actionPerformed(ActionEvent ae) { //not commandAction notifyDestroyed();

Always call the init method. It instantiates LWUITImplementation

Forms To add elements to forms: f.addComponent(formElement); ButtonGroup is used to manage groups of exclusive radio buttons Layouts like in swing: border, flow, Note that textFields do not have captions as in LCDUI

Labels and buttons Label l = new Label(image); l.setAlignment(Component.CENTER); l.setText(“The Caption"); l.setTextPosition(Component.BOTTOM); Button b=new Button(“Caption") //behaves like swing. “Button” is not “Command”, Commands make menus Buttons show up as buttons, are clickable

Radio buttons & check boxes Form f = new Form("More Buttons"); RadioButton rb; ButtonGroup group = new ButtonGroup(); rb = new RadioButton(“radio1"); group.add(rb); f.addComponent(rb); rb = new RadioButton(“radio2"); //for check box: CheckBox cb; cb = new CheckBox(“chk bx1"); f.addComponent(cb); …

Lists & combo boxes Use a list model List list = new List(); list.addItem("item1"); list.addItem("item2"); f.addComponent(list); ComboBox comboBox = new ComboBox(list.getModel()); f.addComponent(comboBox);

Other components TextArea Calendar TabbedPane MediaComponent –to display rich media content

Layouts Layouts include: BorderLayout FlowLayout BoxLayout GridLayout GroupLayout f.setLayout(new BoxLayout(BoxLayout.Y_AXIS)); f.addComponent(BorderLayout.WEST, c)

Containers Dialogs: c. addComponent(new Button(“aButton")); Container c = new Container(new BoxLayout(BoxLayout.X_AXIS)); //add stuff: c. addComponent(new Button(“aButton")); Dialogs: new Dialog().show("Please confirm", “The message ", "OK", "Cancel")) Many show methods Is modal (generally) Usually returns true if OK button pressed. (Check version of fxn called in API)

Transitions Incoming & outgoing f.setTransitionOutAnimator( Transition) f.setTransitionInAnimator( Transition) Transition createSlide(int type, boolean forward, int duration) \ also: Transition createFade() 3-D animations possible on devices that have Mobile 3D Graphics API. Eg createFlyIn, createCube , createRotation Eg f.setTransitionOutAnimator(CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL, false, 1000)); //false= left to right transition //1000= num of milliseconds for transiton f.setTransitionOutAnimator(CommonTransitions.createFade(1000));

Events Implement ActionListener Pass instance of ActionListener to the objects addActionListener() method Eg btn.addActionListenter(this) Provide a body for public void actionPerformed(ActionEvent ae) Determine which object created event by calling ae.getCommand() //within the actionPerformed fxn Within events, it is useful to call f.layoutContainer() on the form to make it repaint any adjustments made to elements of a form

Events Display class in LWUIT manages a single main thread (Event Dispatch Thread) Implement one callback/listener interfaces, register it with LWUIT to listen to all events Most use actionListener Others include DataChangedListener -when a ListModel changes. for a list or combo box. SelectionListener -when the current selection of a ListModel changes. FocusListener -when a component gains or loses focus. StyleListener -when changes in a component's style occur

Event listener eg //creating a listener private class StudentListActionListener implements ActionListener { public void actionPerformed(ActionEvent evt) { //selectedStudent = (Student) studentList.getSelectedItem(); if (evt.getSource().equals(studentList)) { displayStudent(); } else if (evt.getSource().equals(newButton)) { selectedStudent = null; newDob = 0; } else if (evt.getSource().equals(removeButton)) { if (new Dialog().show("Please confirm", "OK to remove " + selectedStudent, "OK", "Cancel")) { StudentDao.removeStudent(selectedStudent); displayStudents(); } //code to add the listener to the widgets StudentListActionListener listActionListener = new StudentListActionListener(); newButton.addActionListener(listActionListener); removeButton.addActionListener(listActionListener); studentList.addActionListener(listActionListener);

Logging The Log class and static p methods permits writing to the log, eg Log.p(“Message to log”); Four log levels: Debug, Info, Error, and Warning. Call Log.showLog() to display a form with log

Lists: LWUIT vs LCDUI Lists LCDUI List are Strings and images, adding a collection of records to the list for display is difficult difficult to associate the selected choice to element in the collection A LWUIT can handle an array or Vector of Objects To get selected object, call on the getSelectedItem()

Lists Eg a: LCDUI list: List list = new List("list", Choice.IMPLICIT); list.setCommandListener(this); Vector students = StudentDao.getStudents(); for (int i = 0; i < students.size(); i++) { list.append(students.elementAt(i).toString(), null); } b: LWUIT list: List list = new List(students); Ref:http://www.devx.com/wireless/Article/38461/1954

Styles and Themes Styles for individual components Get an individual element’s style eg Style s= lbl.getStyle() Set styles eg s.setBgTransparency(0); S. setBgColor (0xff00ff) See style object in API

Eg: Set style of each element Display.init(this); Form form = new Form("Test Style"); TextArea text = new TextArea("Test of style"); Style textStyle = text.getStyle(); textStyle.setBgSelectionColor(0xffffff); textStyle.setFgSelectionColor(0x000000); textStyle.setFont(Font.createSystemFont(Font.FACE_MONOSPACE, Font.STYLE_UNDERLINED, Font.SIZE_SMALL)); Button b = new Button("Test Button"); Style buttonStyle = b.getStyle(); buttonStyle.setBgColor(0x3333ff); buttonStyle.setFgColor(0xffff33); buttonStyle.setFont(Font.createSystemFont(Font.FACE_PROPORTIONAL, Font.STYLE_ITALIC + Font.STYLE_BOLD, Font.SIZE_LARGE)); form.addComponent(text); form.addComponent(b); form.show(); //other methods include: lbl.getStyle().setBgTransparency(0);

Themes To load a theme: Themes for look and feel of app Use the Resource Editor to create a theme. Save as .res Look in the utils folder for the resource editor To load a theme: Do call Display.init() first! try {     Resources res = Resources.open(“/res/aTheme.res”);     UIManager.getInstance().setThemeProps(res.getTheme(“Test Theme”));      } catch (java.io.IOException ioe) {     ioe.printStackTrace(); }

Other J2ME UI frameworks http://wiki.forum.nokia.com/index.php/Java_ME_UI_Frameworks http://j2me.ngphone.com/opensource/ui.htm http://javabyexample.wisdomplug.com/component/content/article/44/73.html Examples include: Apime J2MEPolish J4ME kUIx MWT Synclast etc etc

Lab Build a hello world application with LWUIT and transfer it to a phone. Re-create the DVLA project using LWUIT. Note that all events will remain the same. Add as much pizzazz to your application

References http://www.devx.com/wireless/Article/38461/1954 http://java.sun.com/developer/technicalArticles/javame/lwuit_intro/