×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    4

    Smile Please Help me show this with midlet

    Salam

    i can`t display it,
    i dont know how can i enter display in it .
    please help me ...

    Thanks & Ya Zahra
    Code:
    package ya_mahdi;
    
    import javax.microedition.lcdui.Canvas;
    import javax.microedition.lcdui.CustomItem;
    import javax.microedition.lcdui.Display;
    import javax.microedition.lcdui.Font;
    import javax.microedition.lcdui.Graphics;
    
    
    public class MKStyle extends CustomItem {
     
       private final Display  display;
       final String[] entries;
       private final String shortestEntry;
       private final String longestEntry;
       private final int numberOfVisibleItems;
       private Font font;
       private int linePadding = 2;
       private boolean inTraversal;
       private int focusedIndex = -1;
       private int topIndex;
       private int lineHeight;
       private int highlightedBackgroundColor;
       private int backgroundColor;
       private int highlightedForegroundColor;
       private int foregroundColor;
       private boolean isInitialized;
     
    
       public MKStyle(String label,String[] entries, int numberOfVisibleItems,Display display)
       {
          //#style customListStyle, default 
          super( label );
          this.display = display;
          this.entries = entries;
          this.numberOfVisibleItems = numberOfVisibleItems;
          String longest = null;
          String shortest = null;
          int shortestLength = -1;
          int longestLength = -1;
          for (int i = 0; i < entries.length; i++) {
             String entry = entries[i];
             int length = entry.length();
             if (length < shortestLength || shortest == null) {
                shortest = entry;
                shortestLength = length;
             }
             if (length > longestLength ) {
                longest = entry;
                longestLength = length;
             }
          }
          this.longestEntry = longest;
          this.shortestEntry = shortest;
       }
       
       private void init() {
          this.isInitialized = true;
          if ( this.font == null ) {
             this.font = Font.getDefaultFont();
          }
          this.lineHeight = this.font.getHeight() + this.linePadding;
          if (this.backgroundColor == this.highlightedBackgroundColor) {
             // the colors haven't been set so far:
             //#if .midp2
                this.highlightedBackgroundColor = 
                    this.display.getColor( Display.COLOR_HIGHLIGHTED_BACKGROUND );
                this.backgroundColor = 
                    this.display.getColor( Display.COLOR_BACKGROUND );
                this.highlightedForegroundColor = 
                    this.display.getColor( Display.COLOR_HIGHLIGHTED_FOREGROUND );
                this.foregroundColor = 
                    this.display.getColor( Display.COLOR_FOREGROUND );
             //#else
                this.highlightedBackgroundColor = 0;
                this.backgroundColor = 0xFFFFFF;
                this.highlightedForegroundColor = 0xFFFFFF;
                this.foregroundColor = 0;
             //#endif
          }
       }
    
    
       public int getMinContentHeight(){
          if ( !this.isInitialized ) {
             init();
          }
          return this.lineHeight;
       }
    
       public int getMinContentWidth(){
          if ( !this.isInitialized ) {
             init();
          }
          return this.font.stringWidth( this.shortestEntry );
       }
    
       public int getPrefContentHeight( int width ){
          if ( !this.isInitialized ) {
             init();
          }
          return this.lineHeight * this.numberOfVisibleItems;
       }
    
       public int getPrefContentWidth( int height ){
          if ( !this.isInitialized ) {
             init();
          }
          return this.font.stringWidth( this.longestEntry );
       }
    
       public int getFocusedIndex(){
          return this.focusedIndex;
       }
    
       private void showFocusedEntry(){
          if( this.focusedIndex < this.topIndex ){
             this.topIndex = this.focusedIndex;
          } else if( this.focusedIndex - this.topIndex + 1 
            > this.numberOfVisibleItems )
          {
             this.topIndex = this.focusedIndex - this.numberOfVisibleItems + 1;
          }
       }
    
       protected void paint( Graphics g, int width, int height ){
          int numberOfLines = height / this.lineHeight;
          int lastLineIndex = this.topIndex + numberOfLines;
          if (lastLineIndex > this.entries.length) {
             lastLineIndex = this.entries.length;
          }
          int y = 0;
          g.setFont( this.font );
          for (int i = this.topIndex; i < lastLineIndex; i++ ) {
             String entry = this.entries[i];
             boolean isSel = ( i == this.focusedIndex );
             g.setColor( isSel ? 
             this.highlightedBackgroundColor : this.backgroundColor );
             g.fillRect( 0, y, width, this.lineHeight );
             g.setColor( isSel ? 
             this.highlightedForegroundColor : this.foregroundColor );
             g.drawString( entry, 0, y + this.linePadding/2, Graphics.TOP | Graphics.LEFT );
             y += this.lineHeight;
          }
    
          if( y < height ){
             g.setColor( this.backgroundColor );
             g.fillRect( 0, y, width, height - y );
          }
       }
    
       public boolean traverse( int direction, int viewportWidth, 
                        int viewportHeight, int[] visRectInOut )
       {
          if ( !this.inTraversal ){
             // this user entered the ListItem
             this.inTraversal = true;
             if ( this.focusedIndex == -1  ){
                if ( direction == Canvas.UP || direction == Canvas.LEFT ){
                   if ( this.topIndex + this.numberOfVisibleItems 
                      < this.entries.length) 
                   {
                       this.focusedIndex = 
                          this.topIndex + this.numberOfVisibleItems;
                       } else {
                          this.focusedIndex = this.entries.length - 1;
                       }
                    } else {
                       this.focusedIndex = 0;                   
                    }
                    showFocusedEntry();
                    repaint();
                    notifyStateChanged();
                 }
             visRectInOut[0] = 0;
             visRectInOut[1] = 0;
             visRectInOut[2] = viewportWidth;
             visRectInOut[3] = viewportHeight;
             return true;
          }
    
    
          if ( direction == Canvas.DOWN ) {
             if( this.focusedIndex < this.entries.length - 1 ){
                    this.focusedIndex++;
             } else {
                return false;
             }
          } else if ( direction == Canvas.UP ) {
             if( this.focusedIndex > 0 ){
                this.focusedIndex--;
             } else {
                return false;
             }
          } else if ( direction != NONE ) {
             return false;
          }
    
          showFocusedEntry();
          repaint();
          visRectInOut[0] = 0;
          visRectInOut[1] = (this.focusedIndex - this.topIndex) 
                          * this.lineHeight;
          visRectInOut[2] = viewportWidth;
          visRectInOut[3] = this.lineHeight;
    
          notifyStateChanged();
          return true;
       }
    
       public void traverseOut(){
          this.inTraversal = false;
       }
    
       protected void pointerPressed(int x, int y) {
          int row = y / this.lineHeight + this.topIndex;
          if (row != this.focusedIndex) {
             this.focusedIndex =  row;
             showFocusedEntry();
          }
       }
    }
    Some Body Is Watching Me !!!
    <<< GOD >>>

  2. #2
    Nokia Developer Expert
    Join Date
    Jun 2005
    Posts
    923

    Re: Please Help me show this with midlet

    Code:
    Form f = new Form("Title");
    Item style = new MKStyle();
    f.append(style);
    Display.getDisplay(midlet).setCurrent(f);
    []s
    Daniel

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    4

    Re: Please Help me show this with midlet

    Salam Dear Daniel

    Very Thanks and good luck!!!

    Ya Ali
    Some Body Is Watching Me !!!
    <<< GOD >>>

Similar Threads

  1. calling midlet from midlet throws SecurityException on 6600
    By brianpegan in forum Mobile Java General
    Replies: 3
    Last Post: 2010-10-25, 05:31
  2. 技术文档:MIDP 2.0安全机制 与 MIDlet 数字签名
    By wotrust in forum [Archived] Other Programming Discussion 关于其他编程技术的讨论
    Replies: 0
    Last Post: 2006-12-30, 07:42
  3. Show my midlet instead of 'Calling [phoneno]'
    By faxj2000 in forum Mobile Java General
    Replies: 3
    Last Post: 2006-07-26, 19:35
  4. 'Response Unknown' when downloading midlet
    By Weevil in forum Mobile Java General
    Replies: 3
    Last Post: 2004-05-30, 17:01
  5. How to create two instances of midlet
    By marquito99 in forum Mobile Java General
    Replies: 0
    Last Post: 2004-04-30, 01:33

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×