CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: bubble level

  1. #1
    Join Date
    Jul 2004
    Posts
    8

    Question bubble level

    Hi, all

    I need to do a small graph like a bubble level in my Applet.

    Given 3 values, X, Y, Z Accelerations, the bubble should be drawn there in the target panel of the graph, Just like a bubble level, or inclination indicator.

    I checked JFreeChart, as well as com.objectplanet.chart.ext.GaugeChart, neither seems to do this.

    Any suggestions?


    Thanks,
    Jerry

  2. #2
    Join Date
    Jul 2004
    Posts
    8

    Re: bubble level

    got the solution:

    just extend the JLabel and override the protected void paintComponent(Graphics g).

    In this customized control, I can draw 2 circles (same center, different radius) in the paintComponent function.

    and the position of the "bubble" can be determined by the x, y, z parameters, which can be set by a public function.




    class BubbleLevel extends JLabel{

    private int x,y,z;


    public synchronized void SetBubblePosition(int a, int b, int c){...}

    protected void paintComponent(Graphics g)
    { // draw 2 circles, and the bubble based on x, y, z }


    }


    Then in the code:

    BubbleLevel bl = new BubbleLevel();

    bl.SetBubblePosition(x, y , z);
    bl.repaint();

  3. #3
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: bubble level

    Thanks for posting your solution.

    If you aren't using any of the features of JLabel you may be better off extending JPanel.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured