473,462 Members | 1,462 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 derivedclassname() 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 derivedclassname();

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
Nov 16 '09 #1
3 11769
mrjohn
32
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.
Expand|Select|Wrap|Line Numbers
  1. public int[] getMyData()
  2. {
  3.      return arrayNameHere;
  4. }
  5. //Or for a single value
  6. public int getMyData(int index)
  7. {
  8.     if(index >= 0 && index < myData.length)
  9.         return myData[index];
  10.     else
  11.         System.out.println("ERROR");
  12.         return 0;
  13. }
  14.  
Nov 17 '09 #2
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
Nov 17 '09 #3
mrjohn
32
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.
Nov 17 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Allan Horwitz | last post by:
I am trying to draw a rectangle onto a pane. My program will compile and run but the rectangle does not seem to get drawn. When the program is run the program frame opens up, but I cannot see a...
11
by: srinivas | last post by:
Hi all, I have one requirement.Is there any way to create a line graph using javascript.If it is please send me the sample code.But the thing is it should work in all browsers. Thanks,...
1
by: cnixuser | last post by:
Hello, I am currently attempting to implement a simple actionlistener for a button in a JFrame that was created via "drag and drop" with the Netbeans 5.0 IDE, the code that I am using to implement...
4
by: hastalavista | last post by:
HI I'm very new to C# and I've got a big project to do in C# for uni until july. I've been trying do draw lines in C# (arrows to be precise). I can draw them allright but once I minimize the...
7
by: =?iso-8859-1?Q?Vicente_Garc=EDa?= | last post by:
Hi, I need to programmatically draw a graph (his nodes and his edges) from dynamic XML file. The graph is very complex and I don't know how I could do this task. Any ideas please? Microsoft...
2
by: sriniwas | last post by:
Hi Frnd's, m using prefuse visulation,it's have one display class and this class have one saveImage(outPutStream, String jpg,double size);. now graph is converting ia jpg image properly.now my...
7
by: HxRLxY | last post by:
I am trying to write a simple program which will allow users to view pictures. I am loading an image as an icon, then assigning that ImageIcon to an Image object. Then i get the graphics context of...
2
myusernotyours
by: myusernotyours | last post by:
Hi All, Am working on a Java application in which I have to use the JNI to Interface with some native code for both windows and unix. Am using netbeans IDE with the C/C++ pack installed. Am also...
2
by: ValValVal | last post by:
Hi all. Please help me out I am stuck with this question. I have NetBeans 6.1 and i created JFrame . Then I got this cool graphical editor so I could add buttons and other stuff to my JFrame....
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.