By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,572 Members | 959 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,572 IT Pros & Developers. It's quick & easy.

how to retrive the xml values to JFrame fields

P: 6
please help me
in my forum i have labels and textareas .iwant to add textarea components dyanamically when i am clicking the button.please help me

Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import javax.swing.*;
  3. import javax.swing.event.*;
  4. import java.awt.event.*;
  5. import java.io.*;
  6. import java.applet.*;
  7.  
  8. public class Add1 extends JApplet implements ActionListener 
  9. {
  10.         Container c;
  11. private    int y=4,x=8,j=1,i=1,count=1;
  12.         String st[]={" ","Key features:","Definition:","Classification:","Synonyms:","Epidemiology:","Etiology:","Genetics:","Clinical:","Lab:","Radiology:","Macroscopy:","Histopathology:","Cytology:","Immunohistochemistry:","Immunofluorescence:","note:","Name","Comment", "Electron microscopy:","Prognosis:","Clinical Differential diagnosis:","Pathologic Differential diagnosis:","Radiologic Differential diagnosis:"};
  13.         JFrame f=new JFrame();
  14.         JPanel p=new JPanel();
  15.         JLabel l,l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,l11;
  16.         JTextArea ta,ta1;
  17.         JScrollPane spj,sp,sp2;
  18.         JButton b1;
  19.  
  20. public void init()
  21. {
  22.     Container c=getContentPane();
  23.         c.setLayout(new BorderLayout());
  24.         p=new JPanel();
  25.         p.setBorder(new javax.swing.border.CompoundBorder(
  26.                 new javax.swing.border.TitledBorder(new javax.swing.border.EmptyBorder(0, 0, 0, 0),
  27.             "CoEdit collaboration software & service by Contexta", javax.swing.border.TitledBorder.CENTER,
  28.                     javax.swing.border.TitledBorder.BOTTOM, new java.awt.Font("Dialog", java.awt.Font.BOLD, 18),
  29.                     java.awt.Color.black), p.getBorder())); p.addPropertyChangeListener(new java.beans.PropertyChangeListener(){public void propertyChange(java.beans.PropertyChangeEvent e){if("border".equals(e.getPropertyName()))throw new RuntimeException();}});
  30.         p.setForeground(Color.lightGray);
  31.         p.setLayout(new GridBagLayout());
  32.  
  33.         ((GridBagLayout)p.getLayout()).columnWidths = new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  34.             ((GridBagLayout)p.getLayout()).rowHeights = new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  35.             ((GridBagLayout)p.getLayout()).columnWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};
  36.             ((GridBagLayout)p.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};
  37.  
  38.  
  39.  
  40.             //---------------Key features-----------------------
  41.                     l=new JLabel(st[1]);
  42.                     l.setForeground(Color.darkGray);
  43.                     l.setFont(new Font("Tahoma", Font.PLAIN, 14));
  44.                     p.add(l, new GridBagConstraints(2,y=y+3,1, 1, 0.0, 0.0,
  45.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  46.                 new Insets(50, 50, 5, 5), 0, 0));
  47.  
  48.                     for(;count>=1;count--)
  49.                             {
  50.                 ta = new JTextArea();
  51.                 sp=new JScrollPane();
  52.                 sp.setViewportView(ta);
  53.                    p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
  54.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  55.                 new Insets(5,50, 5, 5), 700,30));
  56.                             repaint();
  57.                     }        
  58.  
  59.  
  60.               //--------------------JButton--------------------------------------    
  61.  
  62.              b1 = new JButton("add");
  63.                p.add(b1, new GridBagConstraints(20,10,1, 1, 0.0, 0.0,
  64.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  65.                 new Insets(0, 0, 5, 5), 0, 0));
  66.  
  67.                 b1.addActionListener(this);
  68.  
  69.             //-----------------------Definition--------------------------        
  70.                     l1=new JLabel(st[2]);
  71.                     l1.setForeground(Color.darkGray);
  72.                     l1.setFont(new Font("Tahoma", Font.PLAIN, 14));
  73.                     p.add(l1, new GridBagConstraints(2,x=x+3,1, 1, 0.0, 0.0,
  74.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  75.                 new Insets(50, 50, 5, 5), 0, 0));
  76.  
  77.                     for(int count=1;count>=1;count--)
  78.                             {
  79.                 ta = new JTextArea();
  80.                 sp=new JScrollPane();
  81.                 sp.setViewportView(ta);
  82.                    p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
  83.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  84.                 new Insets(5,50, 5, 5), 700,30));
  85.                             repaint();
  86.                     }
  87.                 //---------------    Classification-----------------------        
  88.                     l2=new JLabel(st[3]);
  89.                     l2.setForeground(Color.darkGray);
  90.                     l2.setFont(new Font("Tahoma", Font.PLAIN, 14));
  91.                     p.add(l2, new GridBagConstraints(2,x=x+3,1, 1, 0.0, 0.0,
  92.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  93.                 new Insets(50, 50, 5, 5), 0, 0));
  94.  
  95.                     for(int count=5;count>=1;count--)
  96.                             {
  97.                 ta = new JTextArea();
  98.                 sp=new JScrollPane();
  99.                 sp.setViewportView(ta);
  100.                    p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
  101.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  102.                 new Insets(5,50, 5, 5), 700,30));
  103.                             repaint();
  104.                     }
  105.             //----------------------Synonyms----------------------        
  106.                     l3=new JLabel(st[4]);
  107.                     l3.setForeground(Color.darkGray);
  108.                     l3.setFont(new Font("Tahoma", Font.PLAIN, 14));
  109.                     p.add(l3, new GridBagConstraints(2,x=x+3,1, 1, 0.0, 0.0,
  110.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  111.                 new Insets(50, 50, 5, 5), 0, 0));
  112.  
  113.                     for(int count=3;count>=1;count--)
  114.                             {
  115.                 ta = new JTextArea();
  116.                 sp=new JScrollPane();
  117.                 sp.setViewportView(ta);
  118.                    p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
  119.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  120.                 new Insets(5,50, 5, 5), 700,30));
  121.                             repaint();
  122.                     }
  123.  
  124.                 //----------------Epidemiology---------------------------
  125.                     l4=new JLabel(st[5]);
  126.                     l4.setForeground(Color.darkGray);
  127.                     l4.setFont(new Font("Tahoma", Font.PLAIN, 14));
  128.                     p.add(l4, new GridBagConstraints(2,x=x+3,1, 1, 0.0, 0.0,
  129.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  130.                 new Insets(50, 50, 5, 5), 0, 0));
  131.  
  132.                     for(int count=5;count>=1;count--)
  133.                             {
  134.                 ta = new JTextArea();
  135.                 sp=new JScrollPane();
  136.                 sp.setViewportView(ta);
  137.                    p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
  138.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  139.                 new Insets(5,50, 5, 5), 700,30));
  140.                             repaint();
  141.                     }
  142.  
  143.             //------------------Etiology-----------------------------
  144.                     l5=new JLabel(st[6]);
  145.                     l5.setForeground(Color.darkGray);
  146.                     l5.setFont(new Font("Tahoma", Font.PLAIN, 14));
  147.                     p.add(l5, new GridBagConstraints(2,x=x+3,1, 1, 0.0, 0.0,
  148.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  149.                 new Insets(50, 50, 5, 5), 0, 0));
  150.  
  151.                     for(int count=5;count>=1;count--)
  152.                             {
  153.                 ta = new JTextArea();
  154.                 sp=new JScrollPane();
  155.                 sp.setViewportView(ta);
  156.                    p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
  157.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  158.                 new Insets(5,50, 5, 5), 700,30));
  159.                             repaint();
  160.                     }
  161.  
  162.             //-----------------------Genetics---------------
  163.                     l6=new JLabel(st[7]);
  164.                     l6.setForeground(Color.darkGray);
  165.                     l6.setFont(new Font("Tahoma", Font.PLAIN, 14));
  166.                     p.add(l6, new GridBagConstraints(2,x=x+3,1, 1, 0.0, 0.0,
  167.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  168.                 new Insets(50, 50, 5, 5), 0, 0));
  169.  
  170.                     for(int count=5;count>=1;count--)
  171.                             {
  172.                 ta = new JTextArea();
  173.                 sp=new JScrollPane();
  174.                 sp.setViewportView(ta);
  175.                    p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
  176.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  177.                 new Insets(5,50, 5, 5), 700,30));
  178.                             repaint();
  179.                     }
  180.  
  181.             //------------------Clinical--------------
  182.                     l7=new JLabel(st[8]);
  183.                     l7.setForeground(Color.darkGray);
  184.                     l7.setFont(new Font("Tahoma", Font.PLAIN, 14));
  185.                     p.add(l7, new GridBagConstraints(2,x=x+3,1, 1, 0.0, 0.0,
  186.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  187.                 new Insets(50, 50, 5, 5), 0, 0));
  188.  
  189.                     for(int count=5;count>=1;count--)
  190.                             {
  191.                 ta = new JTextArea();
  192.                 sp=new JScrollPane();
  193.                 sp.setViewportView(ta);
  194.                    p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
  195.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  196.                 new Insets(5,50, 5, 5), 700,30));
  197.                             repaint();
  198.                     }
  199.  
  200.             //-----------------Lab-------------------------
  201.                     l8=new JLabel(st[9]);
  202.                     l8.setForeground(Color.darkGray);
  203.                     l8.setFont(new Font("Tahoma", Font.PLAIN, 14));
  204.                     p.add(l8, new GridBagConstraints(2,x=x+3,1, 1, 0.0, 0.0,
  205.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  206.                 new Insets(50, 50, 5, 5), 0, 0));
  207.  
  208.                     for(int count=5;count>=1;count--)
  209.                             {
  210.                 ta = new JTextArea();
  211.                 sp=new JScrollPane();
  212.                 sp.setViewportView(ta);
  213.                    p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
  214.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  215.                 new Insets(5,50, 5, 5), 700,30));
  216.                             repaint();
  217.                     }
  218.  
  219.              JScrollPane sp = new JScrollPane(p);
  220.              c.add(sp, BorderLayout.CENTER);
  221.                 //f.setSize(200,200);
  222.                 //f.setVisible(true);
  223. }
  224. public void paint(Graphics g)
  225.          {
  226.             super.paint(g);
  227.            g.drawString(ta.getText(),55,100); 
  228.          }
  229. public void actionPerformed(ActionEvent e)
  230.     {
  231.     if (e.getSource() == b1)
  232.         {
  233.             count=count+2;
  234.                     ta = new JTextArea();
  235.                 sp=new JScrollPane();
  236.                 sp.setViewportView(ta);
  237.                    p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
  238.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  239.                 new Insets(5,50, 5, 5), 700,30));
  240.  
  241.                             ta.setText("That was the wrong button!:"+count);
  242.                             repaint();
  243.         }
  244.  
  245.         }
  246.     }
Jan 20 '07 #1
Share this Question
Share on Google+
7 Replies


10K+
P: 13,264
please help me
in my forum i have labels and textareas .iwant to add textarea components dyanamically when i am clicking the button.please help me

Now that I've added the code tags around your code, please explain precisely what you want to do. Where do you want to add a textarea? Is that your completed layout? It looks confusing to me. I can't even tell what the program is supposed to do.
Jan 20 '07 #2

Expert 100+
P: 1,510
below is a simple JApplet which creates JTextFeilds as requested by user input
Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4.  
  5. public class TextAreaJapplet extends JApplet implements ActionListener{
  6. JTextField numberField=new JTextField(10), resultField=new JTextField(10);
  7. JTextField textFields[];
  8. Container content;
  9.  
  10. // initialse applet
  11. public void init() {
  12.     content = getContentPane();
  13.     content.setLayout(new FlowLayout()); 
  14.     content.add(new JLabel("Number of text fields"));
  15.     numberField.addActionListener(this);
  16.     numberField.setName("number Field ");
  17.     content.add(numberField);
  18. }
  19.  
  20. // JTextArea event
  21. public void actionPerformed(ActionEvent e)
  22.   {
  23.    //System.out.println("event " + ((JTextField) e.getSource()).getName() + " text "+ ((JTextField) e.getSource()).getText());
  24.    // if event is numberField get value and create JTextFeilds
  25.    if(e.getSource() == numberField) 
  26.       {
  27.        int number=Integer.parseInt(((JTextField) e.getSource()).getText());
  28.        System.out.println("number " + number);
  29.        // new the JTextFeilds, clear old content and add new JTextFields
  30.        textFields=new JTextField[number];
  31.        content.removeAll();
  32.        content.setLayout(new GridLayout(number+2,2)); 
  33.        numberField.addActionListener(this);
  34.        content.add(new JLabel("Number of text fields"));
  35.        content.add(numberField);
  36.        content.add(new JLabel("Last text entered"));
  37.        content.add(resultField);
  38.        for(int i=0; i<number; i++)   // add new JTextFileds and actionlisteners
  39.           {
  40.           textFields[i]=new JTextField(10);
  41.           textFields[i].setName("JTextField " + i);
  42.           textFields[i].addActionListener(this);
  43.           content.add(new JLabel("JTextField " + i));
  44.           content.add(textFields[i]);
  45.           }
  46.       }
  47.    // display information about last event and repaint() the applet
  48.    resultField.setText(((JTextField) e.getSource()).getName() + " text "+ ((JTextField) e.getSource()).getText());
  49.    content.setVisible(true);
  50.    content.validate();
  51.    content.repaint() ;
  52.   }
  53. }
  54.  
Initially it displays a single JTextField, one enters a number say 5 it then displays 7 JTextFields
(1) one for number to be reentered
(2) one which displays events from the JTextFeilds
(3) and the 5 JTextFields requested
Jan 21 '07 #3

10K+
P: 13,264
please help me
in my forum i have labels and textareas .iwant to add textarea components dyanamically when i am clicking the button.please help me

Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import javax.swing.*;
  3. import javax.swing.event.*;
  4. import java.awt.event.*;
  5. import java.io.*;
  6. import java.applet.*;
  7.  
  8. public class Add1 extends JApplet implements ActionListener 
  9. {
  10.         Container c;
  11. private    int y=4,x=8,j=1,i=1,count=1;
  12.         String st[]={" ","Key features:","Definition:","Classification:","Synonyms:","Epidemiology:","Etiology:","Genetics:","Clinical:","Lab:","Radiology:","Macroscopy:","Histopathology:","Cytology:","Immunohistochemistry:","Immunofluorescence:","note:","Name","Comment", "Electron microscopy:","Prognosis:","Clinical Differential diagnosis:","Pathologic Differential diagnosis:","Radiologic Differential diagnosis:"};
  13.         JFrame f=new JFrame();
  14.         JPanel p=new JPanel();
  15.         JLabel l,l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,l11;
  16.         JTextArea ta,ta1;
  17.         JScrollPane spj,sp,sp2;
  18.         JButton b1;
  19.  
  20. public void init()
  21. {
  22.     Container c=getContentPane();
  23.         c.setLayout(new BorderLayout());
  24.         p=new JPanel();
  25.         p.setBorder(new javax.swing.border.CompoundBorder(
  26.                 new javax.swing.border.TitledBorder(new javax.swing.border.EmptyBorder(0, 0, 0, 0),
  27.             "CoEdit collaboration software & service by Contexta", javax.swing.border.TitledBorder.CENTER,
  28.                     javax.swing.border.TitledBorder.BOTTOM, new java.awt.Font("Dialog", java.awt.Font.BOLD, 18),
  29.                     java.awt.Color.black), p.getBorder())); p.addPropertyChangeListener(new java.beans.PropertyChangeListener(){public void propertyChange(java.beans.PropertyChangeEvent e){if("border".equals(e.getPropertyName()))throw new RuntimeException();}});
  30.         p.setForeground(Color.lightGray);
  31.         p.setLayout(new GridBagLayout());
  32.  
  33.         ((GridBagLayout)p.getLayout()).columnWidths = new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  34.             ((GridBagLayout)p.getLayout()).rowHeights = new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  35.             ((GridBagLayout)p.getLayout()).columnWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};
  36.             ((GridBagLayout)p.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};
  37.  
  38.  
  39.  
  40.             //---------------Key features-----------------------
  41.                     l=new JLabel(st[1]);
  42.                     l.setForeground(Color.darkGray);
  43.                     l.setFont(new Font("Tahoma", Font.PLAIN, 14));
  44.                     p.add(l, new GridBagConstraints(2,y=y+3,1, 1, 0.0, 0.0,
  45.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  46.                 new Insets(50, 50, 5, 5), 0, 0));
  47.  
  48.                     for(;count>=1;count--)
  49.                             {
  50.                 ta = new JTextArea();
  51.                 sp=new JScrollPane();
  52.                 sp.setViewportView(ta);
  53.                    p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
  54.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  55.                 new Insets(5,50, 5, 5), 700,30));
  56.                             repaint();
  57.                     }        
  58.  
  59.  
  60.               //--------------------JButton--------------------------------------    
  61.  
  62.              b1 = new JButton("add");
  63.                p.add(b1, new GridBagConstraints(20,10,1, 1, 0.0, 0.0,
  64.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  65.                 new Insets(0, 0, 5, 5), 0, 0));
  66.  
  67.                 b1.addActionListener(this);
  68.  
  69.             //-----------------------Definition--------------------------        
  70.                     l1=new JLabel(st[2]);
  71.                     l1.setForeground(Color.darkGray);
  72.                     l1.setFont(new Font("Tahoma", Font.PLAIN, 14));
  73.                     p.add(l1, new GridBagConstraints(2,x=x+3,1, 1, 0.0, 0.0,
  74.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  75.                 new Insets(50, 50, 5, 5), 0, 0));
  76.  
  77.                     for(int count=1;count>=1;count--)
  78.                             {
  79.                 ta = new JTextArea();
  80.                 sp=new JScrollPane();
  81.                 sp.setViewportView(ta);
  82.                    p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
  83.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  84.                 new Insets(5,50, 5, 5), 700,30));
  85.                             repaint();
  86.                     }
  87.                 //---------------    Classification-----------------------        
  88.                     l2=new JLabel(st[3]);
  89.                     l2.setForeground(Color.darkGray);
  90.                     l2.setFont(new Font("Tahoma", Font.PLAIN, 14));
  91.                     p.add(l2, new GridBagConstraints(2,x=x+3,1, 1, 0.0, 0.0,
  92.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  93.                 new Insets(50, 50, 5, 5), 0, 0));
  94.  
  95.                     for(int count=5;count>=1;count--)
  96.                             {
  97.                 ta = new JTextArea();
  98.                 sp=new JScrollPane();
  99.                 sp.setViewportView(ta);
  100.                    p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
  101.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  102.                 new Insets(5,50, 5, 5), 700,30));
  103.                             repaint();
  104.                     }
  105.             //----------------------Synonyms----------------------        
  106.                     l3=new JLabel(st[4]);
  107.                     l3.setForeground(Color.darkGray);
  108.                     l3.setFont(new Font("Tahoma", Font.PLAIN, 14));
  109.                     p.add(l3, new GridBagConstraints(2,x=x+3,1, 1, 0.0, 0.0,
  110.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  111.                 new Insets(50, 50, 5, 5), 0, 0));
  112.  
  113.                     for(int count=3;count>=1;count--)
  114.                             {
  115.                 ta = new JTextArea();
  116.                 sp=new JScrollPane();
  117.                 sp.setViewportView(ta);
  118.                    p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
  119.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  120.                 new Insets(5,50, 5, 5), 700,30));
  121.                             repaint();
  122.                     }
  123.  
  124.                 //----------------Epidemiology---------------------------
  125.                     l4=new JLabel(st[5]);
  126.                     l4.setForeground(Color.darkGray);
  127.                     l4.setFont(new Font("Tahoma", Font.PLAIN, 14));
  128.                     p.add(l4, new GridBagConstraints(2,x=x+3,1, 1, 0.0, 0.0,
  129.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  130.                 new Insets(50, 50, 5, 5), 0, 0));
  131.  
  132.                     for(int count=5;count>=1;count--)
  133.                             {
  134.                 ta = new JTextArea();
  135.                 sp=new JScrollPane();
  136.                 sp.setViewportView(ta);
  137.                    p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
  138.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  139.                 new Insets(5,50, 5, 5), 700,30));
  140.                             repaint();
  141.                     }
  142.  
  143.             //------------------Etiology-----------------------------
  144.                     l5=new JLabel(st[6]);
  145.                     l5.setForeground(Color.darkGray);
  146.                     l5.setFont(new Font("Tahoma", Font.PLAIN, 14));
  147.                     p.add(l5, new GridBagConstraints(2,x=x+3,1, 1, 0.0, 0.0,
  148.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  149.                 new Insets(50, 50, 5, 5), 0, 0));
  150.  
  151.                     for(int count=5;count>=1;count--)
  152.                             {
  153.                 ta = new JTextArea();
  154.                 sp=new JScrollPane();
  155.                 sp.setViewportView(ta);
  156.                    p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
  157.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  158.                 new Insets(5,50, 5, 5), 700,30));
  159.                             repaint();
  160.                     }
  161.  
  162.             //-----------------------Genetics---------------
  163.                     l6=new JLabel(st[7]);
  164.                     l6.setForeground(Color.darkGray);
  165.                     l6.setFont(new Font("Tahoma", Font.PLAIN, 14));
  166.                     p.add(l6, new GridBagConstraints(2,x=x+3,1, 1, 0.0, 0.0,
  167.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  168.                 new Insets(50, 50, 5, 5), 0, 0));
  169.  
  170.                     for(int count=5;count>=1;count--)
  171.                             {
  172.                 ta = new JTextArea();
  173.                 sp=new JScrollPane();
  174.                 sp.setViewportView(ta);
  175.                    p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
  176.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  177.                 new Insets(5,50, 5, 5), 700,30));
  178.                             repaint();
  179.                     }
  180.  
  181.             //------------------Clinical--------------
  182.                     l7=new JLabel(st[8]);
  183.                     l7.setForeground(Color.darkGray);
  184.                     l7.setFont(new Font("Tahoma", Font.PLAIN, 14));
  185.                     p.add(l7, new GridBagConstraints(2,x=x+3,1, 1, 0.0, 0.0,
  186.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  187.                 new Insets(50, 50, 5, 5), 0, 0));
  188.  
  189.                     for(int count=5;count>=1;count--)
  190.                             {
  191.                 ta = new JTextArea();
  192.                 sp=new JScrollPane();
  193.                 sp.setViewportView(ta);
  194.                    p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
  195.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  196.                 new Insets(5,50, 5, 5), 700,30));
  197.                             repaint();
  198.                     }
  199.  
  200.             //-----------------Lab-------------------------
  201.                     l8=new JLabel(st[9]);
  202.                     l8.setForeground(Color.darkGray);
  203.                     l8.setFont(new Font("Tahoma", Font.PLAIN, 14));
  204.                     p.add(l8, new GridBagConstraints(2,x=x+3,1, 1, 0.0, 0.0,
  205.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  206.                 new Insets(50, 50, 5, 5), 0, 0));
  207.  
  208.                     for(int count=5;count>=1;count--)
  209.                             {
  210.                 ta = new JTextArea();
  211.                 sp=new JScrollPane();
  212.                 sp.setViewportView(ta);
  213.                    p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
  214.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  215.                 new Insets(5,50, 5, 5), 700,30));
  216.                             repaint();
  217.                     }
  218.  
  219.              JScrollPane sp = new JScrollPane(p);
  220.              c.add(sp, BorderLayout.CENTER);
  221.                 //f.setSize(200,200);
  222.                 //f.setVisible(true);
  223. }
  224. public void paint(Graphics g)
  225.          {
  226.             super.paint(g);
  227.            g.drawString(ta.getText(),55,100); 
  228.          }
  229. public void actionPerformed(ActionEvent e)
  230.     {
  231.     if (e.getSource() == b1)
  232.         {
  233.             count=count+2;
  234.                     ta = new JTextArea();
  235.                 sp=new JScrollPane();
  236.                 sp.setViewportView(ta);
  237.                    p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
  238.                 GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  239.                 new Insets(5,50, 5, 5), 700,30));
  240.  
  241.                             ta.setText("That was the wrong button!:"+count);
  242.                             repaint();
  243.         }
  244.  
  245.         }
  246.     }
Is the problem solved then?
Jan 23 '07 #4

P: 6
please help me. In my frame the components r generated dyanamicaly when i am click the button.
after clicking is over create 2nd component.but when i am clicking each time second label created. i want to create my second label after end of last click.
please help me


import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.io.*;
import java.applet.*;

public class Add1 extends JApplet implements ActionListener
{
Container c;
int y=8,x=8,j=1,i=1,count=1,t;
JFrame f=new JFrame();
JPanel p=new JPanel();
JLabel l;
JTextArea ta;
JTextArea ta1,ta2;
JScrollPane sp,sp1;
JButton b1,b2;

Add1()
{
Container c=f.getContentPane();
c.setLayout(new BorderLayout());
p=new JPanel();
p.setBorder(new javax.swing.border.CompoundBorder(
new javax.swing.border.TitledBorder(new javax.swing.border.EmptyBorder(0, 0, 0, 0),
" ", javax.swing.border.TitledBorder.CENTER,
javax.swing.border.TitledBorder.BOTTOM, new java.awt.Font("Dialog", java.awt.Font.BOLD, 18),
java.awt.Color.black), p.getBorder())); p.addPropertyChangeListener(new java.beans.PropertyChangeListener(){public void propertyChange(java.beans.PropertyChangeEvent e){if("border".equals(e.getPropertyName()))throw new RuntimeException();}});
p.setForeground(Color.lightGray);
p.setLayout(new GridBagLayout());

((GridBagLayout)p.getLayout()).columnWidths = new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
((GridBagLayout)p.getLayout()).rowHeights = new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
((GridBagLayout)p.getLayout()).columnWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};
((GridBagLayout)p.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};

//---------------Key features-----------------------
l=new JLabel("Key Features");
l.setForeground(Color.darkGray);
l.setFont(new Font("Tahoma", Font.PLAIN, 14));
p.add(l, new GridBagConstraints(2,7,1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(50, 50, 5, 5), 0, 0));

ta1=new JTextArea();
sp1=new JScrollPane();
sp1.setViewportView(ta1);
p.add(sp1, new GridBagConstraints(2,8, 17, 2, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(5,50, 5, 5), 700,30));

//--------------------JButton--------------------------------------

b1 = new JButton("add");
p.add(b1, new GridBagConstraints(20,9,1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 5, 5), 0, 0));

b1.addActionListener(this);
JScrollPane sp = new JScrollPane();
sp.setViewportView(p);
c.add(sp, BorderLayout.CENTER);
f.setSize(400,400);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == b1)
{
ta2=new JTextArea();
sp1=new JScrollPane();
sp1.setViewportView(ta2);
p.add(sp1, new GridBagConstraints(2,x=x+2, 17, 2, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(5,50, 5, 5), 700,30));

b2 = new JButton("add");
p.add(b2, new GridBagConstraints(20,y=y+2,1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 5, 5), 0, 0));
}
b2.addActionListener(this);
if(e.getSource() ==b2)
{
l=new JLabel("defination");
l.setForeground(Color.darkGray);
l.setFont(new Font("Tahoma", Font.PLAIN, 14));
p.add(l, new GridBagConstraints(2,x=x+2,1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(50, 50, 5, 5), 0, 0));
}
b1=b2;
f.validate();
}

public static void main(String[] a)
{
Add1 a1=new Add1();
}
}
Jan 23 '07 #5

10K+
P: 13,264
please help me. In my frame the components r generated dyanamicaly when i am click the button.
after clicking is over create 2nd component.but when i am clicking each time second label created. i want to create my second label after end of last click.
please help me


import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.io.*;
import java.applet.*;

public class Add1 extends JApplet implements ActionListener
{
Container c;
int y=8,x=8,j=1,i=1,count=1,t;
JFrame f=new JFrame();
JPanel p=new JPanel();
JLabel l;
JTextArea ta;
JTextArea ta1,ta2;
JScrollPane sp,sp1;
JButton b1,b2;

Add1()
{
Container c=f.getContentPane();
c.setLayout(new BorderLayout());
p=new JPanel();
p.setBorder(new javax.swing.border.CompoundBorder(
new javax.swing.border.TitledBorder(new javax.swing.border.EmptyBorder(0, 0, 0, 0),
" ", javax.swing.border.TitledBorder.CENTER,
javax.swing.border.TitledBorder.BOTTOM, new java.awt.Font("Dialog", java.awt.Font.BOLD, 18),
java.awt.Color.black), p.getBorder())); p.addPropertyChangeListener(new java.beans.PropertyChangeListener(){public void propertyChange(java.beans.PropertyChangeEvent e){if("border".equals(e.getPropertyName()))throw new RuntimeException();}});
p.setForeground(Color.lightGray);
p.setLayout(new GridBagLayout());

((GridBagLayout)p.getLayout()).columnWidths = new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
((GridBagLayout)p.getLayout()).rowHeights = new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
((GridBagLayout)p.getLayout()).columnWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};
((GridBagLayout)p.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};

//---------------Key features-----------------------
l=new JLabel("Key Features");
l.setForeground(Color.darkGray);
l.setFont(new Font("Tahoma", Font.PLAIN, 14));
p.add(l, new GridBagConstraints(2,7,1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(50, 50, 5, 5), 0, 0));

ta1=new JTextArea();
sp1=new JScrollPane();
sp1.setViewportView(ta1);
p.add(sp1, new GridBagConstraints(2,8, 17, 2, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(5,50, 5, 5), 700,30));

//--------------------JButton--------------------------------------

b1 = new JButton("add");
p.add(b1, new GridBagConstraints(20,9,1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 5, 5), 0, 0));

b1.addActionListener(this);
JScrollPane sp = new JScrollPane();
sp.setViewportView(p);
c.add(sp, BorderLayout.CENTER);
f.setSize(400,400);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == b1)
{
ta2=new JTextArea();
sp1=new JScrollPane();
sp1.setViewportView(ta2);
p.add(sp1, new GridBagConstraints(2,x=x+2, 17, 2, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(5,50, 5, 5), 700,30));

b2 = new JButton("add");
p.add(b2, new GridBagConstraints(20,y=y+2,1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 5, 5), 0, 0));
}
b2.addActionListener(this);
if(e.getSource() ==b2)
{
l=new JLabel("defination");
l.setForeground(Color.darkGray);
l.setFont(new Font("Tahoma", Font.PLAIN, 14));
p.add(l, new GridBagConstraints(2,x=x+2,1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(50, 50, 5, 5), 0, 0));
}
b1=b2;
f.validate();
}

public static void main(String[] a)
{
Add1 a1=new Add1();
}
}
1.) Please do not double post
2.) Use code tags when posting code
3.)Did you follow the advice given you when you posted this yesterday?
Jan 23 '07 #6

P: 6
please help i have 3 classes 1.NewForm3.java(design of fame)2.NewFormxml2.java(generate xml file)3.OpenForm3.java(retrieve xml values in to frame)
but my problem is i am retrieveing xml values in OpenForm3.java those values does n't display corresponding fields. please help me.


//NewForm3.java
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.io.*;
import java.applet.*;

public class NewForm3 extends JApplet
{
JFrame f=new JFrame();
String str=new String();
String dir2,dir1;
public String str2=" ";

JMenuBar mb;
JMenu file;
JPanel p;
JLabel l;
JTextArea ta1;
JScrollPane sp,sp1;
JComboBox cb;

public void hold2(String str2)
{
this.str2=str2;
System.out.println(str2);
}

public NewForm3()
{
cb = new JComboBox();
mb = new JMenuBar();
file = new JMenu("file");


ta1 = new JTextArea();
sp1 = new JScrollPane();

Container c=f.getContentPane();
c.setLayout(new BorderLayout());
p=new JPanel();
p.setBorder(new javax.swing.border.CompoundBorder(
new javax.swing.border.TitledBorder(new javax.swing.border.EmptyBorder(0, 0, 0, 0),
" ", javax.swing.border.TitledBorder.CENTER,
javax.swing.border.TitledBorder.BOTTOM, new java.awt.Font("Dialog", java.awt.Font.BOLD, 18),
java.awt.Color.black), p.getBorder())); p.addPropertyChangeListener(new java.beans.PropertyChangeListener(){public void propertyChange(java.beans.PropertyChangeEvent e){if("border".equals(e.getPropertyName()))throw new RuntimeException();}});
p.setForeground(Color.lightGray);
p.setLayout(new GridBagLayout());

((GridBagLayout)p.getLayout()).columnWidths = new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
((GridBagLayout)p.getLayout()).rowHeights = new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
((GridBagLayout)p.getLayout()).columnWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};
((GridBagLayout)p.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};

//-------menubar------
OpenAction open = new OpenAction("open",new ImageIcon("action.gif"));
JMenuItem mi2 = new JMenuItem(open);
JButton eb2 = new JButton("open");
file.add(mi2);
mb.add(file);

OpenAction save = new OpenAction("save",new ImageIcon("action.gif"));
JMenuItem mi1 = new JMenuItem(save);
JButton eb = new JButton("save");
file.add(mi1);

p.add(mb, new GridBagConstraints(2, 0, 21, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 5,5),1024, 0));

l=new JLabel("Key features:");
l.setForeground(Color.darkGray);
l.setFont(new Font("Tahoma", Font.PLAIN, 14));
p.add(l, new GridBagConstraints(2,7,1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(50, 50, 5, 5), 0, 0));

sp1=new JScrollPane();
sp1.setViewportView(ta1);
p.add(sp1, new GridBagConstraints(2,10, 17, 2, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(5,50, 5, 5), 700,40));

JScrollPane sp = new JScrollPane(p);
c.add(sp, BorderLayout.CENTER);

f.setSize(200,200);
f.setVisible(true);
}

public class OpenAction extends AbstractAction {
public OpenAction(String text, Icon icon) {
super(text,icon);
}
public void actionPerformed(ActionEvent e) {
String s=e.getActionCommand();
if(s.equals("open"))
{
try{
FileDialog fd=new FileDialog(f,"open",FileDialog.LOAD);
fd.show();
String dir1=fd.getDirectory();
String fname1=fd.getFile();
if((dir1 != null)&&(fname1 != null))
{
dir1=dir1+"/"+fname1;
readFile(dir1);
}
OpenForm3 o1=new OpenForm3();
o1.hold1(dir1);
o1.parseXmlFile();
ta1.setText(str2);
System.out.println(str2);
}
catch(Exception ex)
{
System.out.println(ex);
}
}

else if(s.equals("save"))
{
try{
FileDialog fd=new FileDialog(f,"Save As",FileDialog.SAVE);
fd.show();
String dir2=fd.getDirectory();
String fname2=fd.getFile();
if((dir2 != null)&&(fname2 != null))
{
dir2=dir2+"/"+fname2;
System.out.println(dir2);
writeFile(dir2);
}
str=ta1.getText();
NewFormxml2 n1=new NewFormxml2();
n1.hold(str,dir2);
n1.MyParser();
ta1.setText(" ");
}
catch(Exception ex)
{
System.out.println(ex);
}
}
}//ap
}//ope

public void writeFile(String dir2)
{
try{
FileOutputStream fos=new FileOutputStream(dir2);
String data="<?xml version=\"1.0\"?><Lesion></Lesion>";
byte ba[]=data.getBytes();
fos.write(ba);
fos.close();
}
catch(Exception ex)
{ }
}

public void readFile(String dir1)
{
try{
FileInputStream fis=new FileInputStream(dir1);
byte ba[]=new byte[fis.available()];
fis.read(ba);
fis.close();
}
catch(Exception ex)
{ }

}
public static void main(String[] a)
{
NewForm3 n=new NewForm3();
}
}

//NewFormxml2.java

import java.io.*;
import com.ibm.xml.parser.*;
import org.w3c.dom.*;
public class NewFormxml2
{
String str,dir2;
public void hold(String str,String dir2)
{
this.dir2=dir2;
this.str=str;
}
public void MyParser()
{
try{
Parser p=new Parser("myerrors");
TXDocument td=p.readStream(new FileInputStream(dir2));
Element Lesion=td.getDocumentElement();
Element Key_features=td.createElement("Key_features");
Node Key_features_tx=td.createTextNode(str);
Key_features.appendChild(Key_features_tx);

Lesion.appendChild(Key_features);
NodeList nl2=Lesion.getElementsByTagName("Key_features");
Node n2=nl2.item(0);
Lesion.insertBefore(Key_features,n2);

td.printWithFormat(new FileWriter(dir2));
}
catch(Exception e)
{ }
}
}

//OpenForm3.java


import java.io.*;
import com.ibm.xml.parser.*;
import org.w3c.dom.*;
public class NewFormxml2
{
String str,dir2;
public void hold(String str,String dir2)
{
this.dir2=dir2;
this.str=str;
}
public void MyParser()
{
try{
Parser p=new Parser("myerrors");
TXDocument td=p.readStream(new FileInputStream(dir2));
Element Lesion=td.getDocumentElement();
Element Key_features=td.createElement("Key_features");
Node Key_features_tx=td.createTextNode(str);
Key_features.appendChild(Key_features_tx);

Lesion.appendChild(Key_features);
NodeList nl2=Lesion.getElementsByTagName("Key_features");
Node n2=nl2.item(0);
Lesion.insertBefore(Key_features,n2);

td.printWithFormat(new FileWriter(dir2));
}
catch(Exception e)
{ }
}
}
Jan 23 '07 #7

10K+
P: 13,264
please help i have 3 classes 1.NewForm3.java(design of fame)2.NewFormxml2.java(generate xml file)3.OpenForm3.java(retrieve xml values in to frame)
but my problem is i am retrieveing xml values in OpenForm3.java those values does n't display corresponding fields. please help me.


//NewForm3.java
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.io.*;
import java.applet.*;

public class NewForm3 extends JApplet
{
JFrame f=new JFrame();
String str=new String();
String dir2,dir1;
public String str2=" ";

JMenuBar mb;
JMenu file;
JPanel p;
JLabel l;
JTextArea ta1;
JScrollPane sp,sp1;
JComboBox cb;

public void hold2(String str2)
{
this.str2=str2;
System.out.println(str2);
}

public NewForm3()
{
cb = new JComboBox();
mb = new JMenuBar();
file = new JMenu("file");


ta1 = new JTextArea();
sp1 = new JScrollPane();

Container c=f.getContentPane();
c.setLayout(new BorderLayout());
p=new JPanel();
p.setBorder(new javax.swing.border.CompoundBorder(
new javax.swing.border.TitledBorder(new javax.swing.border.EmptyBorder(0, 0, 0, 0),
" ", javax.swing.border.TitledBorder.CENTER,
javax.swing.border.TitledBorder.BOTTOM, new java.awt.Font("Dialog", java.awt.Font.BOLD, 18),
java.awt.Color.black), p.getBorder())); p.addPropertyChangeListener(new java.beans.PropertyChangeListener(){public void propertyChange(java.beans.PropertyChangeEvent e){if("border".equals(e.getPropertyName()))throw new RuntimeException();}});
p.setForeground(Color.lightGray);
p.setLayout(new GridBagLayout());

((GridBagLayout)p.getLayout()).columnWidths = new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
((GridBagLayout)p.getLayout()).rowHeights = new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
((GridBagLayout)p.getLayout()).columnWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};
((GridBagLayout)p.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};

//-------menubar------
OpenAction open = new OpenAction("open",new ImageIcon("action.gif"));
JMenuItem mi2 = new JMenuItem(open);
JButton eb2 = new JButton("open");
file.add(mi2);
mb.add(file);

OpenAction save = new OpenAction("save",new ImageIcon("action.gif"));
JMenuItem mi1 = new JMenuItem(save);
JButton eb = new JButton("save");
file.add(mi1);

p.add(mb, new GridBagConstraints(2, 0, 21, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 5,5),1024, 0));

l=new JLabel("Key features:");
l.setForeground(Color.darkGray);
l.setFont(new Font("Tahoma", Font.PLAIN, 14));
p.add(l, new GridBagConstraints(2,7,1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(50, 50, 5, 5), 0, 0));

sp1=new JScrollPane();
sp1.setViewportView(ta1);
p.add(sp1, new GridBagConstraints(2,10, 17, 2, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(5,50, 5, 5), 700,40));

JScrollPane sp = new JScrollPane(p);
c.add(sp, BorderLayout.CENTER);

f.setSize(200,200);
f.setVisible(true);
}

public class OpenAction extends AbstractAction {
public OpenAction(String text, Icon icon) {
super(text,icon);
}
public void actionPerformed(ActionEvent e) {
String s=e.getActionCommand();
if(s.equals("open"))
{
try{
FileDialog fd=new FileDialog(f,"open",FileDialog.LOAD);
fd.show();
String dir1=fd.getDirectory();
String fname1=fd.getFile();
if((dir1 != null)&&(fname1 != null))
{
dir1=dir1+"/"+fname1;
readFile(dir1);
}
OpenForm3 o1=new OpenForm3();
o1.hold1(dir1);
o1.parseXmlFile();
ta1.setText(str2);
System.out.println(str2);
}
catch(Exception ex)
{
System.out.println(ex);
}
}

else if(s.equals("save"))
{
try{
FileDialog fd=new FileDialog(f,"Save As",FileDialog.SAVE);
fd.show();
String dir2=fd.getDirectory();
String fname2=fd.getFile();
if((dir2 != null)&&(fname2 != null))
{
dir2=dir2+"/"+fname2;
System.out.println(dir2);
writeFile(dir2);
}
str=ta1.getText();
NewFormxml2 n1=new NewFormxml2();
n1.hold(str,dir2);
n1.MyParser();
ta1.setText(" ");
}
catch(Exception ex)
{
System.out.println(ex);
}
}
}//ap
}//ope

public void writeFile(String dir2)
{
try{
FileOutputStream fos=new FileOutputStream(dir2);
String data="<?xml version=\"1.0\"?><Lesion></Lesion>";
byte ba[]=data.getBytes();
fos.write(ba);
fos.close();
}
catch(Exception ex)
{ }
}

public void readFile(String dir1)
{
try{
FileInputStream fis=new FileInputStream(dir1);
byte ba[]=new byte[fis.available()];
fis.read(ba);
fis.close();
}
catch(Exception ex)
{ }

}
public static void main(String[] a)
{
NewForm3 n=new NewForm3();
}
}

//NewFormxml2.java

import java.io.*;
import com.ibm.xml.parser.*;
import org.w3c.dom.*;
public class NewFormxml2
{
String str,dir2;
public void hold(String str,String dir2)
{
this.dir2=dir2;
this.str=str;
}
public void MyParser()
{
try{
Parser p=new Parser("myerrors");
TXDocument td=p.readStream(new FileInputStream(dir2));
Element Lesion=td.getDocumentElement();
Element Key_features=td.createElement("Key_features");
Node Key_features_tx=td.createTextNode(str);
Key_features.appendChild(Key_features_tx);

Lesion.appendChild(Key_features);
NodeList nl2=Lesion.getElementsByTagName("Key_features");
Node n2=nl2.item(0);
Lesion.insertBefore(Key_features,n2);

td.printWithFormat(new FileWriter(dir2));
}
catch(Exception e)
{ }
}
}

//OpenForm3.java


import java.io.*;
import com.ibm.xml.parser.*;
import org.w3c.dom.*;
public class NewFormxml2
{
String str,dir2;
public void hold(String str,String dir2)
{
this.dir2=dir2;
this.str=str;
}
public void MyParser()
{
try{
Parser p=new Parser("myerrors");
TXDocument td=p.readStream(new FileInputStream(dir2));
Element Lesion=td.getDocumentElement();
Element Key_features=td.createElement("Key_features");
Node Key_features_tx=td.createTextNode(str);
Key_features.appendChild(Key_features_tx);

Lesion.appendChild(Key_features);
NodeList nl2=Lesion.getElementsByTagName("Key_features");
Node n2=nl2.item(0);
Lesion.insertBefore(Key_features,n2);

td.printWithFormat(new FileWriter(dir2));
}
catch(Exception e)
{ }
}
}
You are quite incapable of understanding instructions aren't you?

Ok tell me about how you want to generate the xml file first.
Jan 23 '07 #8

Post your reply

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