【问题标题】:Blackberry - custom BubbleChartField黑莓 - 自定义 BubbleChartField
【发布时间】:2009-07-27 06:33:42
【问题描述】:

我需要开发一个应该显示气泡图的黑莓应用程序。
为此如何实现自定义控件?
谢谢。

【问题讨论】:

    标签: user-interface blackberry charts custom-controls


    【解决方案1】:

    更新这里是 KB How To - Create graph fields

    您的问题应该更加具体和完整...
    好吧,只是为了给你指明方向:

    public class BubbleChart extends Field {
    
        int mWidth = Display.getWidth();
        int mHeight = Display.getHeight();
    
        int[] mXpos = null;
        int[] mYpos = null;
        int[] mRad = null;
        int[] mColor = null;
    
        public BubbleChart(int[] xPos, int[] yPos, int[] rad, int[] colors) {
            this(xPos, yPos, rad);
            mColor = colors;
        }
    
        public BubbleChart(int[] xPos, int[] yPos, int[] rad) {
            mXpos = xPos;
            mYpos = yPos;
            mRad = rad;
        }
    
        public int getPreferredWidth() {
            return mWidth;
        }
    
        public int getPreferredHeight() {
            return mHeight;
        }
    
        protected void layout(int width, int height) {
            setExtent(getPreferredWidth(), getPreferredHeight());
        }
    
       protected void paint( Graphics graphics )
       {
           for( int i = 0, cnt = mXpos.length; i < cnt; i++ )
           {
               if( null != mColor )
                   graphics.setColor( mColor[ i ] );
               else
                   graphics.setColor( Color.WHITE );
               drawFilledCircle( graphics, mXpos[ i ], mYpos[ i ], mRad[ i ] );
               graphics.setColor( Color.BLACK );
               drawCircle( graphics, mXpos[ i ], mYpos[ i ], mRad[ i ] );
           }
       }
    
       private void drawFilledCircle( Graphics g, int x, int y, int r )
       {
           g.fillEllipse( x, y, x + r, y, x, y + r, 0, 360 );
       }
    
       private void drawCircle( Graphics g, int x, int y, int r )
       {
           g.drawEllipse( x, y, x + r, y, x, y + r, 0, 360 );
       }
    }
    

    在应用中的某处:

    class Scr extends MainScreen {
        public Scr() {
            int[] x = { 20, 100, 150 };
            int[] y = { 20, 100, 150 };
            int[] r = { 10, 50, 80 };
            int[] c = { Color.RED, Color.GREEN, Color.YELLOW };
            add(new BubbleChart(x, y, r, c));
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2010-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多