Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-28-2008, 04:29 PM
Member
 
Join Date: Jun 2008
Posts: 15
pradeep1_mca@yahoo.com is on a distinguished road
Printing Tree Structure using Swings
hi friends i am pradeep. i want to print a text file as a tree using swings .i wrote a code for that and i am getting only one node after the root node .so i am sending the code here .plz help me anybody .
here is the code :

import java.io.*;
import java.util.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import javax.swing.JScrollBar;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.event.*;
import javax.swing.JTree;
import javax.swing.JButton;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.event.TreeSelectionListener;

class Hierarchy extends JFrame
{
public static void main(String args[])
{
JFrame frame = new JFrame("DefaultMutableTreeNode Example");
JButton b=new JButton("search");
//JButton exit=new JButton("Exit");
JTextField t1,textField;
JTree tree=new JTree();
Container container = frame.getContentPane();
JTextArea textArea=new JTextArea();
JScrollBar hbar = new JScrollBar(JScrollBar.HORIZONTAL, 30, 20, 0, 500);
JScrollBar vbar = new JScrollBar(JScrollBar.VERTICAL, 30, 40, 0, 400);

t1=new JTextField(15);
textField = new JTextField();

JPanel panel=new JPanel();
panel.add(t1);
panel.add(b);
panel.add(textArea);
//panel.add(exit);
frame.add(panel);
frame.add(hbar, BorderLayout.SOUTH);
frame.add(vbar, BorderLayout.EAST);
//frame.add(jsp);
//frame.add(textArea);
container.add(panel,BorderLayout.NORTH);


try {
String item_no;
String input = "";
File fin=new File("C:\\Pradeep\\u.txt");
FileReader fr=new FileReader(fin);
BufferedReader br = new BufferedReader(fr);

DefaultMutableTreeNode parent;
DefaultMutableTreeNode node1 = null;
DefaultMutableTreeNode node2 = null;
DefaultMutableTreeNode node3 = null;
DefaultMutableTreeNode node4 = null;

parent = new DefaultMutableTreeNode("UNSPSC");

while((input = br.readLine()) != null)
{
StringTokenizer st = new StringTokenizer(input," ");
System.out.println(" String "+ input);
item_no = st.nextToken();
System.out.println(" item_no -> " + item_no);

if(item_no.substring(2).equals("000000"))
{
node1 = new DefaultMutableTreeNode(input);
System.out.println(" 1 root node"+ input);
parent.add(node1);
tree = new JTree(parent);
frame.add(tree);

}
else if(item_no.substring(4).equals("0000"))
{
node2 = new DefaultMutableTreeNode(input);
System.out.println(" 2 root node" + input);
node1.add(node2);
tree = new JTree(node1);
frame.add(tree);
}

else if(item_no.substring(6).equals("00"))
{
node3 = new DefaultMutableTreeNode(input);
System.out.println(" 3 root node"+ input);
node2.add(node3);
tree = new JTree(node2);
frame.add(tree);
}
else
{
node4 = new DefaultMutableTreeNode(input);
System.out.println(" 4 root node"+ input);
node3.add(node4);
tree = new JTree(node3);
frame.add(tree);
}
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
splitPane.setLeftComponent(tree);
splitPane.setRightComponent(textField);
container.add(splitPane, BorderLayout.SOUTH);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.getRootPane().setWindowDecorationStyle(JRoot Pane.PLAIN_DIALOG);
frame.add(splitPane);
frame.setSize(700,700);
frame.setVisible(true);
}
}catch(IOException e) { System.out.println(e);}
}
}


so kindly please help me in this problem .i hope i ll get replay .
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-28-2008, 05:53 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Norm is on a distinguished road
Quote:
i am getting only one node after the root node
Can you post the output from program? And add some coments on what you expected.
What does the input file look like? How is it to be processed by the program?
There are NO comments in the program so I can't understand what it is YOU are trying to do.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 08-29-2008, 07:36 AM
Member
 
Join Date: Jun 2008
Posts: 15
pradeep1_mca@yahoo.com is on a distinguished road
Quote:
Originally Posted by pradeep1_mca@yahoo.com View Post
hi friends i am pradeep. i want to print a text file as a tree using swings .i wrote a code for that and i am getting only one node after the root node .so i am sending the code here .plz help me anybody .
here is the code :

import java.io.*;
import java.util.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import javax.swing.JScrollBar;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.event.*;
import javax.swing.JTree;
import javax.swing.JButton;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.event.TreeSelectionListener;

class Hierarchy extends JFrame
{
public static void main(String args[])
{
JFrame frame = new JFrame("DefaultMutableTreeNode Example");
JButton b=new JButton("search");
//JButton exit=new JButton("Exit");
JTextField t1,textField;
JTree tree=new JTree();
Container container = frame.getContentPane();
JTextArea textArea=new JTextArea();
JScrollBar hbar = new JScrollBar(JScrollBar.HORIZONTAL, 30, 20, 0, 500);
JScrollBar vbar = new JScrollBar(JScrollBar.VERTICAL, 30, 40, 0, 400);

t1=new JTextField(15);
textField = new JTextField();

JPanel panel=new JPanel();
panel.add(t1);
panel.add(b);
panel.add(textArea);
//panel.add(exit);
frame.add(panel);
frame.add(hbar, BorderLayout.SOUTH);
frame.add(vbar, BorderLayout.EAST);
//frame.add(jsp);
//frame.add(textArea);
container.add(panel,BorderLayout.NORTH);


try {
String item_no;
String input = "";
File fin=new File("C:\\Pradeep\\u.txt");
FileReader fr=new FileReader(fin);
BufferedReader br = new BufferedReader(fr);

DefaultMutableTreeNode parent;
DefaultMutableTreeNode node1 = null;
DefaultMutableTreeNode node2 = null;
DefaultMutableTreeNode node3 = null;
DefaultMutableTreeNode node4 = null;

parent = new DefaultMutableTreeNode("UNSPSC");

while((input = br.readLine()) != null)
{
StringTokenizer st = new StringTokenizer(input," ");
System.out.println(" String "+ input);
item_no = st.nextToken();
System.out.println(" item_no -> " + item_no);

if(item_no.substring(2).equals("000000"))
{
node1 = new DefaultMutableTreeNode(input);
System.out.println(" 1 root node"+ input);
parent.add(node1);
tree = new JTree(parent);
frame.add(tree);

}
else if(item_no.substring(4).equals("0000"))
{
node2 = new DefaultMutableTreeNode(input);
System.out.println(" 2 root node" + input);
node1.add(node2);
tree = new JTree(node1);
frame.add(tree);
}

else if(item_no.substring(6).equals("00"))
{
node3 = new DefaultMutableTreeNode(input);
System.out.println(" 3 root node"+ input);
node2.add(node3);
tree = new JTree(node2);
frame.add(tree);
}
else
{
node4 = new DefaultMutableTreeNode(input);
System.out.println(" 4 root node"+ input);
node3.add(node4);
tree = new JTree(node3);
frame.add(tree);
}
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
splitPane.setLeftComponent(tree);
splitPane.setRightComponent(textField);
container.add(splitPane, BorderLayout.SOUTH);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.getRootPane().setWindowDecorationStyle(JRoot Pane.PLAIN_DIALOG);
frame.add(splitPane);
frame.setSize(700,700);
frame.setVisible(true);
}
}catch(IOException e) { System.out.println(e);}
}
}


so kindly please help me in this problem .i hope i ll get replay .
OUT PUT OF THE ABOVE PROGRAM WHAT I GETTING IS :
UNSPSC
10000000 lIVE PLANT AND ANIMAL MATERIAL .
10100000 LIVE ANIMALS
LIKE THIS IT SHOULD DISPALY TOTAL DATA FROM TEXT FILE UPTO
400000000
I ADDED CODES LIKE 1000000 TO 40000000
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 08-29-2008, 04:00 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Norm is on a distinguished road
Quote:
What does the input file look like?
How is it to be processed by the program?
I don't understand your comments at the end of your post mean.
Some of it is output from the program and some of it was typed in by you. All in UPPERCASE???

Please show a simple sample input file and then the results from your program with reading that file and then show what you want the output to look like.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 08-30-2008, 07:43 AM
Member
 
Join Date: Jun 2008
Posts: 15
pradeep1_mca@yahoo.com is on a distinguished road
Searching a word from a text file .
hi senior member . requirements for my task as follows :
1.print the tree structure .i got it .
2.i have to take TextField and Button .
3.if i enter any word in TextField and click the Button named as search .then it should search from the text file and print the exact matching from the tree
in a TextArea .

Text File ex: u.txt
so this is my requirement and i am unable to send the output.
still ur not understand what i posting to u.plz do one thing .

i want a program for searching using swings .means
i want to enter one word into tetxtfield and click the search button .
then it should search and print the values in textarea.so u take anyone text file and save it as .txt .
then u can write the code to get data from that text file using Button named search .

i hope u ll understand this .i am waiting for ur replay .

if u can not understand this ,plz ignore this mail .

bye
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 08-30-2008, 03:54 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Norm is on a distinguished road
Ok, good luck.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
New to Java, Creating screens with swings on Mac OS X mo_mughrabi New To Java 0 05-26-2008 03:17 PM
java swings emperoraj AWT / Swing 0 03-26-2008 01:50 PM
Drawing charts using swings ravindarjobs New To Java 13 11-03-2007 07:19 AM
Use if then else structure, help paul New To Java 1 08-07-2007 07:00 AM
Tree structure using JAVA trill Advanced Java 1 08-02-2007 04:50 PM


All times are GMT +3. The time now is 12:32 PM.


VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org