Results 1 to 6 of 6
- 08-28-2008, 02:29 PM #1
Member
- Join Date
- Jun 2008
- Posts
- 15
- Rep Power
- 0
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 .:p:):eek:
- 08-28-2008, 03:53 PM #2
Can you post the output from program? And add some coments on what you expected.i am getting only one node after the root node
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.
- 08-29-2008, 05:36 AM #3
Member
- Join Date
- Jun 2008
- Posts
- 15
- Rep Power
- 0
- 08-29-2008, 02:00 PM #4
I don't understand your comments at the end of your post mean.What does the input file look like?
How is it to be processed by the program?
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.
- 08-30-2008, 05:43 AM #5
Member
- Join Date
- Jun 2008
- Posts
- 15
- Rep Power
- 0
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
- 08-30-2008, 01:54 PM #6
Similar Threads
-
Tree structure using JAVA
By trill in forum Advanced JavaReplies: 2Last Post: 05-27-2010, 11:02 AM -
Drawing charts using swings
By ravindarjobs in forum New To JavaReplies: 19Last Post: 07-21-2009, 11:03 PM -
New to Java, Creating screens with swings on Mac OS X
By mo_mughrabi in forum New To JavaReplies: 0Last Post: 05-26-2008, 01:17 PM -
java swings
By emperoraj in forum AWT / SwingReplies: 0Last Post: 03-26-2008, 11:50 AM -
Use if then else structure, help
By paul in forum New To JavaReplies: 1Last Post: 08-07-2007, 05:00 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks