By Marcel Caraciolo http://mobideia.blogspot.com Chapter 06–  MIDP:  User Interface SCMAD Certification  45mm 61mm
Agenda Low level User interface Canvas Graphics CustomItem
MIDP : High User Interface - CustomItem Allow using Canvas features inside a form A custom item will handle user input and render  outputs Like any other item, it’s composed of label +  component. The label is rendered by the device,  while the application will render the component As in Canvas, the device calls paint() method to  render the outputs Use Preferred size and Minimum Size “ Item navigation” may temporarily be delegated to  the component
CustomItem: Abstract methods paint(graphics,width,height): Same behavior from Canvas.paint Component size (width,height) is a parameter getMinContentWidth, getMinContentHeight: Must return the minimum component size getPrefContentWidth(height),getPrefContentHeight(width) Us eful to calculate the best size for the component. When the  width is calculated, the height is passed as parameter and vice- versa (-1 will be sent if it’s not yet defined).
CustomItem: Super class methods repaint,repaint(x,y,w,h), getGameAction: Similar to Canvas methods getInteractionModes: Returns an integer with a bitmask indicating the supported  interaction modes: TRANSVERSE_HORIZONTAL, TRANSVERSE_VERTICAL : if the “navigation” inside the item is allowed. KEY_PRESS,KEY_RELEASE,KEY_REPEAT : Keyboard events  POINTER_PRESS,POINTER_RELEASE,POINTER_DRAG:  Touchscreen events invalidate: Requests a component re-initialization  (size is re-calculated, and  the component is redrawn.) Inherits notifyStateChanged() method from Item, which is used to trigger events on ItemStateListener.
CustomItem: Callback methods sizeChanged(w,h):  The size calculated by minContent and prefContent may not be allowed by the platform. If this is the case, this method will be called. It’s also called when the component size is changed. showNotify , hideNotify:  Notifies when an item is shown or hidden
CustomItem: Callback methods Transverse(dir,viewportWidth,viewportHeight,visRect_inout[]): Notifies that a navigation event happened on an item Parameters: dir : Canvas.UP, DOWN, LEFT, RIGHT or NONE (None: User clicked with a touchscreen) viewportWidth, viewportHeight:  Size of the visible area visRect inout:  In/Out parameter. Array of int[4] with [x, y,w, h], where x, y is the distance from the origin, and w, h are the size  of the rectangle. State may be kept on the component (and  used at paint method). It may be easier to ignore this  parameter Returns true when the navigation happened internally, and false when the focus shall be lost
CustomItem: Callback methods traverseOut():  Indicates that the focus was lost keyPressed(keyCode), keyReleased(keyCode), keyRepeated(keyCode):  Notify keyboard events pointerPressed(x, y), pointerReleased(x, y),  pointerDragged(x, y):  Notify touchscreen events
Low User Interface:  Diagram
Low Low User Interface Based on Canvas, not on Screen You draw on a “canvas”, High Level widgets are not used Portability depends on how do you code your application.  You need to consider device features like screen sizes and  input devices Based on Canvas and GameCanvas: Canvas:  Useful for showing charts and for applications where all the events are triggered by user input (e.g. card games) GameCanvas:  Graphics for real time games, where the events occur according to the running time
Can  Canvas Screen” itself, where the images will be generated Abstract class, application shall extend it. It must  implement the  paint(graphics)  method, which is called  when the screen is rendered May also implement logic to handle user input  Drawing itself is done through a graphics object passed as parameter  to the paint method
Can  Canvas: The Life-Cycle
Can  Canvas.paint(graphics) Called by the system to paint a screen before it’s shown Shall paint all the points on the screen, since the platform will not  do this automatically This graphics instance shall NEVER be used outside the scope of  this method
Can  Canvas: SuperClass methods isDoubleBuffered:  If double buffering is supported hasPointerEvents:  If a touchscreen is available (e.g. PDA’s) hasPointerMotionEvents:  If the touchscreen allows drag  and-drop hasRepeatEvents:  If holding a key has the same effect as  pressing  several times setFullScreenMode(boolean):  Shows a canvas on full screen
Can  Canvas: SuperClass methods repaint() and repaint(x, y, width, height):  Requests the screen to be painted again (paint() will be called). The parameters define the size of the screen that shall be re-painted. When these parameters are informed, the graphics passed to paint method has a clip-region greater or equal to the informed area. This data can be used to  optimization serviceRepaints():  Blocks until all calls to “paint” that are queued  return. May cause deadlocks
Can  Canvas: Callback methods keyPressed(keyCode):  Key was pressed keyRepeated(keyCode):  Key is being hold keyReleased(keyCode):  Key is no longer pressed pointerPressed(x, y):  Pointer was pressed at x, y pointerReleased(x, y):  Pointer is no longer pressed at x, y pointerDragged(x, y):  Pointer is being dragged through x, y showNotify():  Canvas is going to be shown hideNotify():  Canvas is no longer being shown sizeChanged():  Canvas was resized
Can  Canvas: Key Events keyPressed, keyRepeated and keyReleased  methods receive  keyCode parameter, to inform which key was pressed.  Cellphone keys  available are: KEY NUM0 - KEY NUM9  (0 - 9) KEY STAR  (*) KEY POUND  (#) Game keys are also available. Their value is found by  getGameAction(keyCode).  Available game keys are: UP, DOWN, LEFT, RIGHT FIRE, GAME A, GAME B, GAME C, GAME D
Can  Canvas: Key Events A single Game Key can be linked to several keys (e.g. UP may be mapped both to “2 key” and to “up key”) Other keys may be available. To enforce portability, you should only  use default keys A textual description can be found by  getKeyName(keyCode)
Can  Graphics Useful for rendering images (text, images, geometric shapes) on  screen Color model: 24 bits (8 bits for each color). When the  device does not support a requested color, it will use a  similar one (even for gray  scales) Coordinate system with origin (0, 0) on the upper left  corner. X grows to the right and Y grows down. This  coordinate system may  be translated Every Graphics is rectangular and all pixels are square
Can  Graphics: methods drawString(str , x, y, anchor): Draws a string on the specified position Anchor defines a reference point from which a message is placed. Horizontal positioning is made with ( LEFT, HCENTER, RIGHT ) and  vertical with  (TOP, BASELINE, BOTTOM ) drawLine(x1, y1, x2, y2): Draws a line from (x1, y1) to (x2, y2). If (x1, y1)==(x2, y2), a  pixel  is drawn fillTriangle(x1, y1, x2, y2, x3, y3): Fills a triangle
Can  Graphics: Anchors
Can  Graphics: methods setColor(r,g,b), setColor(rgb), setGrayScale(value): Set color via r,g,b (8 bits for each component) with a single integer (0x00RRGGBB) or set a gray scale (8 bits) setStrokeStyle(style): Lines, arcs, and rectangles may be drawn with a solid or a dotted  lines ( SOLID or DOTTED).  Spacing between points is implementation-specific and not-customizable. drawRectangle/fillRectangle(x,y,width,height): Draws or fills a rectangle
Can  Graphics: methods drawArc/fillArc(x,y,h,startAngle,arcAngle): Draws or fills arcs and circles.  Angles are specified in degrees. drawRoundRect/fillRoundRect(x,y,w,h,arcW,arcH): Draws or fills rectangles with round edges setFont(font): Sets the font to be used with Strings drawImage(img,x,y,anchor): Draws a image in a specified position The image may  use transparency (devices must support at least two transparecy levels i.e. full opaque or full transparent) Like String, it uses anchors for positioning.  VCENTER  is used instead of  BASELINE.
Can  Graphics: methods translate(x,y): Translates the reference point (origin). To return to the original reference, you may call g.translate(ax –  g.getTranslateX() , ay –  g.getTranslateY()) setClip(x,y,width,height): Sets a clip area to limit painting (like “framing” the image). Paints outsides of this area are ignored. drawRGB(data[],offset,scanlength,x,y,w,h,procAlpha): Renders an integer array with format:  0xAARRGGBB, where AA stands for transparency. Offset: first index on the array. Scanlength: number of elements that define a “line”.
Can  Graphics: Overview
Example Codes Some examples and MIDlets samples are available for reference and studying  at this link: http://www.dsc.upe.br/~mpc/chapter6.rar The source codes include: CustomItemMIDlet GraphicMIDlet KeyInputMIDlet LowLevelMIDlet
Future Work Next Chapter: MIDP – Util Timers User Interface API Classes MIDP Classes Introduction to MIDP - GameUI
References ALVES F. Eduardo. SCMAD Study Guide,  27/04/2008.  JAKL Andreas, Java Platform, Micro Edition Part  01 slides, 12/2007. Sun Certification Mobile Application Developer  Website:  [http://www.sun.com/training/certification/java/scmad.xml].

More Related Content

DOC
Java applet handouts
PDF
Cinema 4D R20 ESSENTIALS
PDF
Unit-1 basics of computer graphics
PDF
Autocad commands-1
PPTX
Autocad Commands
PDF
Auto cad tutorial
PDF
Computer graphics notes
Java applet handouts
Cinema 4D R20 ESSENTIALS
Unit-1 basics of computer graphics
Autocad commands-1
Autocad Commands
Auto cad tutorial
Computer graphics notes

What's hot (20)

PPTX
COMPUTER GRAPHICS
PDF
PDF
Commands in AutoCAD
PDF
Flash Tutorial
PPT
Chapter 13
PPTX
CIV1900 Matlab - Plotting & Coursework
PPT
MIDP: Form Custom and Image Items
PDF
Computer Graphics
PDF
OsiriX_new_guide_202204.pdf
PDF
Aobe photoshop cs5 keyboard shortcut
DOCX
Graphics file
PDF
Computer graphics notes watermark
PDF
Cg lab cse-v (1) (1)
PDF
The Ring programming language version 1.5.3 book - Part 48 of 184
PDF
The Ring programming language version 1.3 book - Part 38 of 88
PPTX
GRPHICS01 - Introduction to 3D Graphics
PPTX
3 d animation
PPTX
Geogebra 6
PPTX
GeoGebra 3
PPTX
Clipping 22
COMPUTER GRAPHICS
Commands in AutoCAD
Flash Tutorial
Chapter 13
CIV1900 Matlab - Plotting & Coursework
MIDP: Form Custom and Image Items
Computer Graphics
OsiriX_new_guide_202204.pdf
Aobe photoshop cs5 keyboard shortcut
Graphics file
Computer graphics notes watermark
Cg lab cse-v (1) (1)
The Ring programming language version 1.5.3 book - Part 48 of 184
The Ring programming language version 1.3 book - Part 38 of 88
GRPHICS01 - Introduction to 3D Graphics
3 d animation
Geogebra 6
GeoGebra 3
Clipping 22
Ad

Viewers also liked (20)

PPT
Ruhri Lukas The I Phone 1
PPS
Niver Bah - 22.06.07
PDF
Introduction to open - libre Tools and Formats
KEY
2markit
PPT
You Media: Relationships and The Long Tail of Popularity
PPS
Drets d'examen
ODP
Sesion 4 .PRESENTACIÓN
PPT
香港六合彩
ZIP
Diigo Presentation- Revised
PDF
The Connection Culture: A New Source of Competitive Advantage
PPS
Niver Aposan - 2007
PPT
lezing Online netwerken
PPT
080318
PPT
Mark Freeman Ug Challenges Final With Results
PDF
Introduction to chef framework
PPTX
Totara Seminar: Sam Barbee, Learning Pool
PPT
Ict Presentation
PPS
Lec - 05.05.07
PPT
NALC's Presentation at the Public Sector Learning Conference
PPT
Scmad Chapter05
Ruhri Lukas The I Phone 1
Niver Bah - 22.06.07
Introduction to open - libre Tools and Formats
2markit
You Media: Relationships and The Long Tail of Popularity
Drets d'examen
Sesion 4 .PRESENTACIÓN
香港六合彩
Diigo Presentation- Revised
The Connection Culture: A New Source of Competitive Advantage
Niver Aposan - 2007
lezing Online netwerken
080318
Mark Freeman Ug Challenges Final With Results
Introduction to chef framework
Totara Seminar: Sam Barbee, Learning Pool
Ict Presentation
Lec - 05.05.07
NALC's Presentation at the Public Sector Learning Conference
Scmad Chapter05
Ad

Similar to Scmad Chapter06 (20)

PPT
Session8 J2ME Low Level User Interface
PPTX
Java ME - 03 - Low Level Graphics E
PDF
Creating Games for Asha - platform
PPTX
Game Development for Nokia Asha Devices with Java ME #2
PPT
Scmad Chapter07
DOCX
An Introduction to Computer Science with Java .docx
PPTX
Java ME - 05 - Game API
PDF
JavaFX 1.0 SDK Aquarium Paris
PPTX
Graphics on the Go
PDF
Developing games for Series 40 full-touch UI
PPT
Implementation
PDF
Facets Of Fragmentation by Mark Murphy
PDF
Google kick ass-game_programming_with_gwt
PDF
Introduction to 2D Game Development on Nokia Series 40 Asha Phones
PDF
Designing and coding Series 40 Java apps for high performance
PDF
Games 3 dl4-example
PPT
13slide graphics
PPTX
Developing Multi Platform Games using PlayN and TriplePlay Framework
PDF
W3C HTML5 KIG-The complete guide to building html5 games
PDF
Power of canvas
Session8 J2ME Low Level User Interface
Java ME - 03 - Low Level Graphics E
Creating Games for Asha - platform
Game Development for Nokia Asha Devices with Java ME #2
Scmad Chapter07
An Introduction to Computer Science with Java .docx
Java ME - 05 - Game API
JavaFX 1.0 SDK Aquarium Paris
Graphics on the Go
Developing games for Series 40 full-touch UI
Implementation
Facets Of Fragmentation by Mark Murphy
Google kick ass-game_programming_with_gwt
Introduction to 2D Game Development on Nokia Series 40 Asha Phones
Designing and coding Series 40 Java apps for high performance
Games 3 dl4-example
13slide graphics
Developing Multi Platform Games using PlayN and TriplePlay Framework
W3C HTML5 KIG-The complete guide to building html5 games
Power of canvas

More from Marcel Caraciolo (20)

PDF
Como interpretar seu próprio genoma com Python
PDF
Joblib: Lightweight pipelining for parallel jobs (v2)
PDF
Construindo softwares de bioinformática para análises clínicas : Desafios e...
PDF
Como Python ajudou a automatizar o nosso laboratório v.2
PDF
Como Python pode ajudar na automação do seu laboratório
PDF
Python on Science ? Yes, We can.
PDF
Oficina Python: Hackeando a Web com Python 3
PDF
Recommender Systems with Ruby (adding machine learning, statistics, etc)
PDF
Opensource - Como começar e dá dinheiro ?
PDF
Big Data com Python
PDF
Benchy, python framework for performance benchmarking of Python Scripts
PDF
Python e 10 motivos por que devo conhece-la ?
PDF
GeoMapper, Python Script for Visualizing Data on Social Networks with Geo-loc...
PDF
Benchy: Lightweight framework for Performance Benchmarks
PDF
Construindo Sistemas de Recomendação com Python
PDF
Python, A pílula Azul da programação
PDF
Construindo Soluções Científicas com Big Data & MapReduce
PDF
Como Python está mudando a forma de aprendizagem à distância no Brasil
PDF
Novas Tendências para a Educação a Distância: Como reinventar a educação ?
PDF
Aula WebCrawlers com Regex - PyCursos
Como interpretar seu próprio genoma com Python
Joblib: Lightweight pipelining for parallel jobs (v2)
Construindo softwares de bioinformática para análises clínicas : Desafios e...
Como Python ajudou a automatizar o nosso laboratório v.2
Como Python pode ajudar na automação do seu laboratório
Python on Science ? Yes, We can.
Oficina Python: Hackeando a Web com Python 3
Recommender Systems with Ruby (adding machine learning, statistics, etc)
Opensource - Como começar e dá dinheiro ?
Big Data com Python
Benchy, python framework for performance benchmarking of Python Scripts
Python e 10 motivos por que devo conhece-la ?
GeoMapper, Python Script for Visualizing Data on Social Networks with Geo-loc...
Benchy: Lightweight framework for Performance Benchmarks
Construindo Sistemas de Recomendação com Python
Python, A pílula Azul da programação
Construindo Soluções Científicas com Big Data & MapReduce
Como Python está mudando a forma de aprendizagem à distância no Brasil
Novas Tendências para a Educação a Distância: Como reinventar a educação ?
Aula WebCrawlers com Regex - PyCursos

Recently uploaded (20)

DOCX
Hand book of Entrepreneurship 4 Chapters.docx
DOCX
Center Enamel A Strategic Partner for the Modernization of Georgia's Chemical...
PDF
ANALYZING THE OPPORTUNITIES OF DIGITAL MARKETING IN BANGLADESH TO PROVIDE AN ...
PPTX
Project Management_ SMART Projects Class.pptx
PDF
#1 Safe and Secure Verified Cash App Accounts for Purchase.pdf
PPTX
chapter 2 entrepreneurship full lecture ppt
PDF
Solaris Resources Presentation - Corporate August 2025.pdf
PDF
Introduction to Generative Engine Optimization (GEO)
PPTX
basic introduction to research chapter 1.pptx
PDF
NISM Series V-A MFD Workbook v December 2024.khhhjtgvwevoypdnew one must use ...
PDF
income tax laws notes important pakistan
PPTX
IITM - FINAL Option - 01 - 12.08.25.pptx
PDF
NEW - FEES STRUCTURES (01-july-2024).pdf
PDF
Susan Semmelmann: Enriching the Lives of others through her Talents and Bless...
PPTX
Board-Reporting-Package-by-Umbrex-5-23-23.pptx
PPTX
TRAINNING, DEVELOPMENT AND APPRAISAL.pptx
PDF
ICv2 White Paper - Gen Con Trade Day 2025
PDF
Satish NS: Fostering Innovation and Sustainability: Haier India’s Customer-Ce...
PDF
Daniels 2024 Inclusive, Sustainable Development
PPTX
operations management : demand supply ch
Hand book of Entrepreneurship 4 Chapters.docx
Center Enamel A Strategic Partner for the Modernization of Georgia's Chemical...
ANALYZING THE OPPORTUNITIES OF DIGITAL MARKETING IN BANGLADESH TO PROVIDE AN ...
Project Management_ SMART Projects Class.pptx
#1 Safe and Secure Verified Cash App Accounts for Purchase.pdf
chapter 2 entrepreneurship full lecture ppt
Solaris Resources Presentation - Corporate August 2025.pdf
Introduction to Generative Engine Optimization (GEO)
basic introduction to research chapter 1.pptx
NISM Series V-A MFD Workbook v December 2024.khhhjtgvwevoypdnew one must use ...
income tax laws notes important pakistan
IITM - FINAL Option - 01 - 12.08.25.pptx
NEW - FEES STRUCTURES (01-july-2024).pdf
Susan Semmelmann: Enriching the Lives of others through her Talents and Bless...
Board-Reporting-Package-by-Umbrex-5-23-23.pptx
TRAINNING, DEVELOPMENT AND APPRAISAL.pptx
ICv2 White Paper - Gen Con Trade Day 2025
Satish NS: Fostering Innovation and Sustainability: Haier India’s Customer-Ce...
Daniels 2024 Inclusive, Sustainable Development
operations management : demand supply ch

Scmad Chapter06

  • 1. By Marcel Caraciolo http://mobideia.blogspot.com Chapter 06– MIDP: User Interface SCMAD Certification 45mm 61mm
  • 2. Agenda Low level User interface Canvas Graphics CustomItem
  • 3. MIDP : High User Interface - CustomItem Allow using Canvas features inside a form A custom item will handle user input and render outputs Like any other item, it’s composed of label + component. The label is rendered by the device, while the application will render the component As in Canvas, the device calls paint() method to render the outputs Use Preferred size and Minimum Size “ Item navigation” may temporarily be delegated to the component
  • 4. CustomItem: Abstract methods paint(graphics,width,height): Same behavior from Canvas.paint Component size (width,height) is a parameter getMinContentWidth, getMinContentHeight: Must return the minimum component size getPrefContentWidth(height),getPrefContentHeight(width) Us eful to calculate the best size for the component. When the width is calculated, the height is passed as parameter and vice- versa (-1 will be sent if it’s not yet defined).
  • 5. CustomItem: Super class methods repaint,repaint(x,y,w,h), getGameAction: Similar to Canvas methods getInteractionModes: Returns an integer with a bitmask indicating the supported interaction modes: TRANSVERSE_HORIZONTAL, TRANSVERSE_VERTICAL : if the “navigation” inside the item is allowed. KEY_PRESS,KEY_RELEASE,KEY_REPEAT : Keyboard events POINTER_PRESS,POINTER_RELEASE,POINTER_DRAG: Touchscreen events invalidate: Requests a component re-initialization (size is re-calculated, and the component is redrawn.) Inherits notifyStateChanged() method from Item, which is used to trigger events on ItemStateListener.
  • 6. CustomItem: Callback methods sizeChanged(w,h): The size calculated by minContent and prefContent may not be allowed by the platform. If this is the case, this method will be called. It’s also called when the component size is changed. showNotify , hideNotify: Notifies when an item is shown or hidden
  • 7. CustomItem: Callback methods Transverse(dir,viewportWidth,viewportHeight,visRect_inout[]): Notifies that a navigation event happened on an item Parameters: dir : Canvas.UP, DOWN, LEFT, RIGHT or NONE (None: User clicked with a touchscreen) viewportWidth, viewportHeight: Size of the visible area visRect inout: In/Out parameter. Array of int[4] with [x, y,w, h], where x, y is the distance from the origin, and w, h are the size of the rectangle. State may be kept on the component (and used at paint method). It may be easier to ignore this parameter Returns true when the navigation happened internally, and false when the focus shall be lost
  • 8. CustomItem: Callback methods traverseOut(): Indicates that the focus was lost keyPressed(keyCode), keyReleased(keyCode), keyRepeated(keyCode): Notify keyboard events pointerPressed(x, y), pointerReleased(x, y), pointerDragged(x, y): Notify touchscreen events
  • 10. Low Low User Interface Based on Canvas, not on Screen You draw on a “canvas”, High Level widgets are not used Portability depends on how do you code your application. You need to consider device features like screen sizes and input devices Based on Canvas and GameCanvas: Canvas: Useful for showing charts and for applications where all the events are triggered by user input (e.g. card games) GameCanvas: Graphics for real time games, where the events occur according to the running time
  • 11. Can Canvas Screen” itself, where the images will be generated Abstract class, application shall extend it. It must implement the paint(graphics) method, which is called when the screen is rendered May also implement logic to handle user input Drawing itself is done through a graphics object passed as parameter to the paint method
  • 12. Can Canvas: The Life-Cycle
  • 13. Can Canvas.paint(graphics) Called by the system to paint a screen before it’s shown Shall paint all the points on the screen, since the platform will not do this automatically This graphics instance shall NEVER be used outside the scope of this method
  • 14. Can Canvas: SuperClass methods isDoubleBuffered: If double buffering is supported hasPointerEvents: If a touchscreen is available (e.g. PDA’s) hasPointerMotionEvents: If the touchscreen allows drag and-drop hasRepeatEvents: If holding a key has the same effect as pressing several times setFullScreenMode(boolean): Shows a canvas on full screen
  • 15. Can Canvas: SuperClass methods repaint() and repaint(x, y, width, height): Requests the screen to be painted again (paint() will be called). The parameters define the size of the screen that shall be re-painted. When these parameters are informed, the graphics passed to paint method has a clip-region greater or equal to the informed area. This data can be used to optimization serviceRepaints(): Blocks until all calls to “paint” that are queued return. May cause deadlocks
  • 16. Can Canvas: Callback methods keyPressed(keyCode): Key was pressed keyRepeated(keyCode): Key is being hold keyReleased(keyCode): Key is no longer pressed pointerPressed(x, y): Pointer was pressed at x, y pointerReleased(x, y): Pointer is no longer pressed at x, y pointerDragged(x, y): Pointer is being dragged through x, y showNotify(): Canvas is going to be shown hideNotify(): Canvas is no longer being shown sizeChanged(): Canvas was resized
  • 17. Can Canvas: Key Events keyPressed, keyRepeated and keyReleased methods receive keyCode parameter, to inform which key was pressed. Cellphone keys available are: KEY NUM0 - KEY NUM9 (0 - 9) KEY STAR (*) KEY POUND (#) Game keys are also available. Their value is found by getGameAction(keyCode). Available game keys are: UP, DOWN, LEFT, RIGHT FIRE, GAME A, GAME B, GAME C, GAME D
  • 18. Can Canvas: Key Events A single Game Key can be linked to several keys (e.g. UP may be mapped both to “2 key” and to “up key”) Other keys may be available. To enforce portability, you should only use default keys A textual description can be found by getKeyName(keyCode)
  • 19. Can Graphics Useful for rendering images (text, images, geometric shapes) on screen Color model: 24 bits (8 bits for each color). When the device does not support a requested color, it will use a similar one (even for gray scales) Coordinate system with origin (0, 0) on the upper left corner. X grows to the right and Y grows down. This coordinate system may be translated Every Graphics is rectangular and all pixels are square
  • 20. Can Graphics: methods drawString(str , x, y, anchor): Draws a string on the specified position Anchor defines a reference point from which a message is placed. Horizontal positioning is made with ( LEFT, HCENTER, RIGHT ) and vertical with (TOP, BASELINE, BOTTOM ) drawLine(x1, y1, x2, y2): Draws a line from (x1, y1) to (x2, y2). If (x1, y1)==(x2, y2), a pixel is drawn fillTriangle(x1, y1, x2, y2, x3, y3): Fills a triangle
  • 21. Can Graphics: Anchors
  • 22. Can Graphics: methods setColor(r,g,b), setColor(rgb), setGrayScale(value): Set color via r,g,b (8 bits for each component) with a single integer (0x00RRGGBB) or set a gray scale (8 bits) setStrokeStyle(style): Lines, arcs, and rectangles may be drawn with a solid or a dotted lines ( SOLID or DOTTED). Spacing between points is implementation-specific and not-customizable. drawRectangle/fillRectangle(x,y,width,height): Draws or fills a rectangle
  • 23. Can Graphics: methods drawArc/fillArc(x,y,h,startAngle,arcAngle): Draws or fills arcs and circles. Angles are specified in degrees. drawRoundRect/fillRoundRect(x,y,w,h,arcW,arcH): Draws or fills rectangles with round edges setFont(font): Sets the font to be used with Strings drawImage(img,x,y,anchor): Draws a image in a specified position The image may use transparency (devices must support at least two transparecy levels i.e. full opaque or full transparent) Like String, it uses anchors for positioning. VCENTER is used instead of BASELINE.
  • 24. Can Graphics: methods translate(x,y): Translates the reference point (origin). To return to the original reference, you may call g.translate(ax – g.getTranslateX() , ay – g.getTranslateY()) setClip(x,y,width,height): Sets a clip area to limit painting (like “framing” the image). Paints outsides of this area are ignored. drawRGB(data[],offset,scanlength,x,y,w,h,procAlpha): Renders an integer array with format: 0xAARRGGBB, where AA stands for transparency. Offset: first index on the array. Scanlength: number of elements that define a “line”.
  • 25. Can Graphics: Overview
  • 26. Example Codes Some examples and MIDlets samples are available for reference and studying at this link: http://www.dsc.upe.br/~mpc/chapter6.rar The source codes include: CustomItemMIDlet GraphicMIDlet KeyInputMIDlet LowLevelMIDlet
  • 27. Future Work Next Chapter: MIDP – Util Timers User Interface API Classes MIDP Classes Introduction to MIDP - GameUI
  • 28. References ALVES F. Eduardo. SCMAD Study Guide, 27/04/2008. JAKL Andreas, Java Platform, Micro Edition Part 01 slides, 12/2007. Sun Certification Mobile Application Developer Website: [http://www.sun.com/training/certification/java/scmad.xml].