how to draw graph in netbeans JFrame using data from program.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vipin sharma
    New Member
    • Jul 2009
    • 16

    how to draw graph in netbeans JFrame using data from program.

    hello all,
    i am using netbeans ide for development. I want to display a graph on screen. After some search on google i found that we can create a graph by following steps:
    1. extending a class with JPanel and overriding its paintcomponent( ) method.
    2. now create a panel using palette and open its properties.
    3. in property window go to code section and write new derivedclassnam e() in Custom creation code.

    This is working very fine. but my problem is that for drawing graph i need certain data(arrays) from my code. using above method i m not able to pass any argument in any new created method because netbeans uses auto generation code like this:
    JPanel jp = new derivedclassnam e();

    therefore my object is not able to use any new function given in derived class.

    An alternative solution which i feel is that writing layout(null) after initComponents( ) statement and then adding my derived panel to particular area on jform. but when i run program using this concept i dont see that graph on screen. it looks like panel is not added to jform.

    I have done lot of my coding work on netbeans and cant step back to manual code wrting now for this project. pls help me in solving this problem.

    regards
    vipin sharma
  • mrjohn
    New Member
    • May 2009
    • 31

    #2
    As a disclaimer, I don't use netbeans. However, can't you just create some getter methods for your arrays in the class that they're in? Then you can use those setters to get the data from any class in the same directory.

    i.e.
    [code="java"]public int[] getMyData()
    {
    return arrayNameHere;
    }
    //Or for a single value
    public int getMyData(int index)
    {
    if(index >= 0 && index < myData.length)
    return myData[index];
    else
    System.out.prin tln("ERROR");
    return 0;
    }
    [/code]

    Comment

    • vipin sharma
      New Member
      • Jul 2009
      • 16

      #3
      hi john

      Thanks for reply. New method of derived class works only when they are accessed with derived class object, however if we use base class object to store derived class object then we wont be able to use new methods.

      My problem got solved. I was not taking into account that netbeans by default uses free design as layout manager. So i derived a class using JPanel, override its paintcomponent method. I changed layout manager to flowlayout of parent panel and add derived class to it.

      This is first time i made a big project ( atleast for me) in java. I thought netbeans would make work easier by using drag and drop for gui. But my experience was not so good. Now I am looking for different ide, can you suggest me any other ide which you think is better?

      once again thank you very much for helping me.

      with regards
      vipin sharma

      Comment

      • mrjohn
        New Member
        • May 2009
        • 31

        #4
        I use Eclipse, myself. It's both free and very helpful. It doesn't have the drag 'n drop GUI making capabilities (Like the Microsoft Visual XXXX series), so you have to write them manually, but it is still a quite excellent program.

        Comment

        Working...