473,734 Members | 2,375 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to retrive the xml values to JFrame fields

6 New Member
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
7 2633
r035198x
13,262 MVP
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
horace1
1,510 Recognized Expert Top Contributor
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
r035198x
13,262 MVP
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
sreenulanka
6 New Member
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.eve nt.*;
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.getContentP ane();
c.setLayout(new BorderLayout()) ;
p=new JPanel();
p.setBorder(new javax.swing.bor der.CompoundBor der(
new javax.swing.bor der.TitledBorde r(new javax.swing.bor der.EmptyBorder (0, 0, 0, 0),
" ", javax.swing.bor der.TitledBorde r.CENTER,
javax.swing.bor der.TitledBorde r.BOTTOM, new java.awt.Font(" Dialog", java.awt.Font.B OLD, 18),
java.awt.Color. black), p.getBorder())) ; p.addPropertyCh angeListener(ne w java.beans.Prop ertyChangeListe ner(){public void propertyChange( java.beans.Prop ertyChangeEvent e){if("border". equals(e.getPro pertyName()))th row new RuntimeExceptio n();}});
p.setForeground (Color.lightGra y);
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 GridBagConstrai nts(2,7,1, 1, 0.0, 0.0,
GridBagConstrai nts.CENTER, GridBagConstrai nts.BOTH,
new Insets(50, 50, 5, 5), 0, 0));

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

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

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

b1.addActionLis tener(this);
JScrollPane sp = new JScrollPane();
sp.setViewportV iew(p);
c.add(sp, BorderLayout.CE NTER);
f.setSize(400,4 00);
f.setVisible(tr ue);
}
public void actionPerformed (ActionEvent e)
{
if (e.getSource() == b1)
{
ta2=new JTextArea();
sp1=new JScrollPane();
sp1.setViewport View(ta2);
p.add(sp1, new GridBagConstrai nts(2,x=x+2, 17, 2, 0.0, 0.0,
GridBagConstrai nts.CENTER, GridBagConstrai nts.BOTH,
new Insets(5,50, 5, 5), 700,30));

b2 = new JButton("add");
p.add(b2, new GridBagConstrai nts(20,y=y+2,1, 1, 0.0, 0.0,
GridBagConstrai nts.CENTER, GridBagConstrai nts.BOTH,
new Insets(0, 0, 5, 5), 0, 0));
}
b2.addActionLis tener(this);
if(e.getSource( ) ==b2)
{
l=new JLabel("definat ion");
l.setForeground (Color.darkGray );
l.setFont(new Font("Tahoma", Font.PLAIN, 14));
p.add(l, new GridBagConstrai nts(2,x=x+2,1, 1, 0.0, 0.0,
GridBagConstrai nts.CENTER, GridBagConstrai nts.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
r035198x
13,262 MVP
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.eve nt.*;
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.getContentP ane();
c.setLayout(new BorderLayout()) ;
p=new JPanel();
p.setBorder(new javax.swing.bor der.CompoundBor der(
new javax.swing.bor der.TitledBorde r(new javax.swing.bor der.EmptyBorder (0, 0, 0, 0),
" ", javax.swing.bor der.TitledBorde r.CENTER,
javax.swing.bor der.TitledBorde r.BOTTOM, new java.awt.Font(" Dialog", java.awt.Font.B OLD, 18),
java.awt.Color. black), p.getBorder())) ; p.addPropertyCh angeListener(ne w java.beans.Prop ertyChangeListe ner(){public void propertyChange( java.beans.Prop ertyChangeEvent e){if("border". equals(e.getPro pertyName()))th row new RuntimeExceptio n();}});
p.setForeground (Color.lightGra y);
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 GridBagConstrai nts(2,7,1, 1, 0.0, 0.0,
GridBagConstrai nts.CENTER, GridBagConstrai nts.BOTH,
new Insets(50, 50, 5, 5), 0, 0));

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

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

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

b1.addActionLis tener(this);
JScrollPane sp = new JScrollPane();
sp.setViewportV iew(p);
c.add(sp, BorderLayout.CE NTER);
f.setSize(400,4 00);
f.setVisible(tr ue);
}
public void actionPerformed (ActionEvent e)
{
if (e.getSource() == b1)
{
ta2=new JTextArea();
sp1=new JScrollPane();
sp1.setViewport View(ta2);
p.add(sp1, new GridBagConstrai nts(2,x=x+2, 17, 2, 0.0, 0.0,
GridBagConstrai nts.CENTER, GridBagConstrai nts.BOTH,
new Insets(5,50, 5, 5), 700,30));

b2 = new JButton("add");
p.add(b2, new GridBagConstrai nts(20,y=y+2,1, 1, 0.0, 0.0,
GridBagConstrai nts.CENTER, GridBagConstrai nts.BOTH,
new Insets(0, 0, 5, 5), 0, 0));
}
b2.addActionLis tener(this);
if(e.getSource( ) ==b2)
{
l=new JLabel("definat ion");
l.setForeground (Color.darkGray );
l.setFont(new Font("Tahoma", Font.PLAIN, 14));
p.add(l, new GridBagConstrai nts(2,x=x+2,1, 1, 0.0, 0.0,
GridBagConstrai nts.CENTER, GridBagConstrai nts.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
sreenulanka
6 New Member
please help i have 3 classes 1.NewForm3.java (design of fame)2.NewFormx ml2.java(genera te xml file)3.OpenForm 3.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.eve nt.*;
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.prin tln(str2);
}

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


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

Container c=f.getContentP ane();
c.setLayout(new BorderLayout()) ;
p=new JPanel();
p.setBorder(new javax.swing.bor der.CompoundBor der(
new javax.swing.bor der.TitledBorde r(new javax.swing.bor der.EmptyBorder (0, 0, 0, 0),
" ", javax.swing.bor der.TitledBorde r.CENTER,
javax.swing.bor der.TitledBorde r.BOTTOM, new java.awt.Font(" Dialog", java.awt.Font.B OLD, 18),
java.awt.Color. black), p.getBorder())) ; p.addPropertyCh angeListener(ne w java.beans.Prop ertyChangeListe ner(){public void propertyChange( java.beans.Prop ertyChangeEvent e){if("border". equals(e.getPro pertyName()))th row new RuntimeExceptio n();}});
p.setForeground (Color.lightGra y);
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("ope n",new ImageIcon("acti on.gif"));
JMenuItem mi2 = new JMenuItem(open) ;
JButton eb2 = new JButton("open") ;
file.add(mi2);
mb.add(file);

OpenAction save = new OpenAction("sav e",new ImageIcon("acti on.gif"));
JMenuItem mi1 = new JMenuItem(save) ;
JButton eb = new JButton("save") ;
file.add(mi1);

p.add(mb, new GridBagConstrai nts(2, 0, 21, 1, 0.0, 0.0,
GridBagConstrai nts.CENTER, GridBagConstrai nts.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 GridBagConstrai nts(2,7,1, 1, 0.0, 0.0,
GridBagConstrai nts.CENTER, GridBagConstrai nts.BOTH,
new Insets(50, 50, 5, 5), 0, 0));

sp1=new JScrollPane();
sp1.setViewport View(ta1);
p.add(sp1, new GridBagConstrai nts(2,10, 17, 2, 0.0, 0.0,
GridBagConstrai nts.CENTER, GridBagConstrai nts.BOTH,
new Insets(5,50, 5, 5), 700,40));

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

f.setSize(200,2 00);
f.setVisible(tr ue);
}

public class OpenAction extends AbstractAction {
public OpenAction(Stri ng text, Icon icon) {
super(text,icon );
}
public void actionPerformed (ActionEvent e) {
String s=e.getActionCo mmand();
if(s.equals("op en"))
{
try{
FileDialog fd=new FileDialog(f,"o pen",FileDialog .LOAD);
fd.show();
String dir1=fd.getDire ctory();
String fname1=fd.getFi le();
if((dir1 != null)&&(fname1 != null))
{
dir1=dir1+"/"+fname1;
readFile(dir1);
}
OpenForm3 o1=new OpenForm3();
o1.hold1(dir1);
o1.parseXmlFile ();
ta1.setText(str 2);
System.out.prin tln(str2);
}
catch(Exception ex)
{
System.out.prin tln(ex);
}
}

else if(s.equals("sa ve"))
{
try{
FileDialog fd=new FileDialog(f,"S ave As",FileDialog. SAVE);
fd.show();
String dir2=fd.getDire ctory();
String fname2=fd.getFi le();
if((dir2 != null)&&(fname2 != null))
{
dir2=dir2+"/"+fname2;
System.out.prin tln(dir2);
writeFile(dir2) ;
}
str=ta1.getText ();
NewFormxml2 n1=new NewFormxml2();
n1.hold(str,dir 2);
n1.MyParser();
ta1.setText(" ");
}
catch(Exception ex)
{
System.out.prin tln(ex);
}
}
}//ap
}//ope

public void writeFile(Strin g dir2)
{
try{
FileOutputStrea m fos=new FileOutputStrea m(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.jav a

import java.io.*;
import com.ibm.xml.par ser.*;
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("myerror s");
TXDocument td=p.readStream (new FileInputStream (dir2));
Element Lesion=td.getDo cumentElement() ;
Element Key_features=td .createElement( "Key_features") ;
Node Key_features_tx =td.createTextN ode(str);
Key_features.ap pendChild(Key_f eatures_tx);

Lesion.appendCh ild(Key_feature s);
NodeList nl2=Lesion.getE lementsByTagNam e("Key_features ");
Node n2=nl2.item(0);
Lesion.insertBe fore(Key_featur es,n2);

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

//OpenForm3.java


import java.io.*;
import com.ibm.xml.par ser.*;
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("myerror s");
TXDocument td=p.readStream (new FileInputStream (dir2));
Element Lesion=td.getDo cumentElement() ;
Element Key_features=td .createElement( "Key_features") ;
Node Key_features_tx =td.createTextN ode(str);
Key_features.ap pendChild(Key_f eatures_tx);

Lesion.appendCh ild(Key_feature s);
NodeList nl2=Lesion.getE lementsByTagNam e("Key_features ");
Node n2=nl2.item(0);
Lesion.insertBe fore(Key_featur es,n2);

td.printWithFor mat(new FileWriter(dir2 ));
}
catch(Exception e)
{ }
}
}
Jan 23 '07 #7
r035198x
13,262 MVP
please help i have 3 classes 1.NewForm3.java (design of fame)2.NewFormx ml2.java(genera te xml file)3.OpenForm 3.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.eve nt.*;
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.prin tln(str2);
}

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


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

Container c=f.getContentP ane();
c.setLayout(new BorderLayout()) ;
p=new JPanel();
p.setBorder(new javax.swing.bor der.CompoundBor der(
new javax.swing.bor der.TitledBorde r(new javax.swing.bor der.EmptyBorder (0, 0, 0, 0),
" ", javax.swing.bor der.TitledBorde r.CENTER,
javax.swing.bor der.TitledBorde r.BOTTOM, new java.awt.Font(" Dialog", java.awt.Font.B OLD, 18),
java.awt.Color. black), p.getBorder())) ; p.addPropertyCh angeListener(ne w java.beans.Prop ertyChangeListe ner(){public void propertyChange( java.beans.Prop ertyChangeEvent e){if("border". equals(e.getPro pertyName()))th row new RuntimeExceptio n();}});
p.setForeground (Color.lightGra y);
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("ope n",new ImageIcon("acti on.gif"));
JMenuItem mi2 = new JMenuItem(open) ;
JButton eb2 = new JButton("open") ;
file.add(mi2);
mb.add(file);

OpenAction save = new OpenAction("sav e",new ImageIcon("acti on.gif"));
JMenuItem mi1 = new JMenuItem(save) ;
JButton eb = new JButton("save") ;
file.add(mi1);

p.add(mb, new GridBagConstrai nts(2, 0, 21, 1, 0.0, 0.0,
GridBagConstrai nts.CENTER, GridBagConstrai nts.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 GridBagConstrai nts(2,7,1, 1, 0.0, 0.0,
GridBagConstrai nts.CENTER, GridBagConstrai nts.BOTH,
new Insets(50, 50, 5, 5), 0, 0));

sp1=new JScrollPane();
sp1.setViewport View(ta1);
p.add(sp1, new GridBagConstrai nts(2,10, 17, 2, 0.0, 0.0,
GridBagConstrai nts.CENTER, GridBagConstrai nts.BOTH,
new Insets(5,50, 5, 5), 700,40));

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

f.setSize(200,2 00);
f.setVisible(tr ue);
}

public class OpenAction extends AbstractAction {
public OpenAction(Stri ng text, Icon icon) {
super(text,icon );
}
public void actionPerformed (ActionEvent e) {
String s=e.getActionCo mmand();
if(s.equals("op en"))
{
try{
FileDialog fd=new FileDialog(f,"o pen",FileDialog .LOAD);
fd.show();
String dir1=fd.getDire ctory();
String fname1=fd.getFi le();
if((dir1 != null)&&(fname1 != null))
{
dir1=dir1+"/"+fname1;
readFile(dir1);
}
OpenForm3 o1=new OpenForm3();
o1.hold1(dir1);
o1.parseXmlFile ();
ta1.setText(str 2);
System.out.prin tln(str2);
}
catch(Exception ex)
{
System.out.prin tln(ex);
}
}

else if(s.equals("sa ve"))
{
try{
FileDialog fd=new FileDialog(f,"S ave As",FileDialog. SAVE);
fd.show();
String dir2=fd.getDire ctory();
String fname2=fd.getFi le();
if((dir2 != null)&&(fname2 != null))
{
dir2=dir2+"/"+fname2;
System.out.prin tln(dir2);
writeFile(dir2) ;
}
str=ta1.getText ();
NewFormxml2 n1=new NewFormxml2();
n1.hold(str,dir 2);
n1.MyParser();
ta1.setText(" ");
}
catch(Exception ex)
{
System.out.prin tln(ex);
}
}
}//ap
}//ope

public void writeFile(Strin g dir2)
{
try{
FileOutputStrea m fos=new FileOutputStrea m(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.jav a

import java.io.*;
import com.ibm.xml.par ser.*;
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("myerror s");
TXDocument td=p.readStream (new FileInputStream (dir2));
Element Lesion=td.getDo cumentElement() ;
Element Key_features=td .createElement( "Key_features") ;
Node Key_features_tx =td.createTextN ode(str);
Key_features.ap pendChild(Key_f eatures_tx);

Lesion.appendCh ild(Key_feature s);
NodeList nl2=Lesion.getE lementsByTagNam e("Key_features ");
Node n2=nl2.item(0);
Lesion.insertBe fore(Key_featur es,n2);

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

//OpenForm3.java


import java.io.*;
import com.ibm.xml.par ser.*;
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("myerror s");
TXDocument td=p.readStream (new FileInputStream (dir2));
Element Lesion=td.getDo cumentElement() ;
Element Key_features=td .createElement( "Key_features") ;
Node Key_features_tx =td.createTextN ode(str);
Key_features.ap pendChild(Key_f eatures_tx);

Lesion.appendCh ild(Key_feature s);
NodeList nl2=Lesion.getE lementsByTagNam e("Key_features ");
Node n2=nl2.item(0);
Lesion.insertBe fore(Key_featur es,n2);

td.printWithFor mat(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

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

Similar topics

1
3325
by: Tuno | last post by:
I'm relatively new to Java Swing programming. I have a console application that processes text files and while doing so I want to suspend the execution when an error is encountered that requires the user to make a choice. I want to do that with my own JFrame that allows the user to edit the bad data in a GUI and then click "Accept" or "Ignore". If the user clicks "Accept", the JFrame contributes the data to the standard output being...
1
1249
by: swathi thulasi | last post by:
hi all how to retrive the data,to same fields where we entered,and it must be editable...without datagrides,datalist..i want data must be visible in the same fields where i entered.Its urgent reply soon *** Sent via Developersdex http://www.developersdex.com ***
2
2128
by: Gian Paolo | last post by:
Hi all on .net 2.0 i have a dataset and a table with some rows. Is there a way to retrive the current row index ? So i can retrive other value of that column... something like dataset.table.columnname.value regards paolo
0
1612
nehashri
by: nehashri | last post by:
hi, I need one help regarding Asp with MsAccess database. Problem. ======== i want to retrive stored image from the MSAccess database using asp.
23
3421
nehashri
by: nehashri | last post by:
hi i am designing a database using Ms Access and ASP. i have 3 tables in access namely 'PERSONAL', other as 'POLICY' and 3rd one is named as 'STAFF'. in the contact table i have ID, Name, Children as fields. Also in policy table the firlds are:- ID, date_of_policy, no_policy, amount_paid, amount_balance and similarly the 3rd ie., staff has few fields. all three are linked my a common field which is ID all i want is when the user searches...
5
6854
Shinzon
by: Shinzon | last post by:
ok so far I have got: JFrame frame = new JFrame( "Matt's DVD's" ); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); frame.setSize( 420, 170 ); // set frame size frame.setVisible( true ); // display frame JLabel label = new JLabel("Text Label");
1
2988
by: amritranjan | last post by:
How to retrive image file from MS access database and display this in another JSPpage -------------------------------------------------------------------------------- This is my Jsp code for image upload in database: -----------Upload.jsp---------------- <html> <head> <title>Account Details </title>
6
13843
by: gaya3 | last post by:
Hi, I need to make the frame invisible on action event in swings. I have the following code: public class sample_pgm extends JFrame{ public void sample() { JFrame jf = new JFrame("Sample"); JPanel panel = new JPanel();
20
3751
by: cowboyrocks2009 | last post by:
Hi, I need help to automate my code to take data from input file. Also I need to create it as a function so that I can pass it to some other program. I am new to Java so having a bit limitation to do this. My tab delimited Input File looks like this:- 21 p 13e 0 62 1 580001 andrew -14.53 -13.95 0 0 21 p 13d 63 124 580002 1160001 andrew -13.95 -13.37 0 0 21 p 12g 311 364 2900000 3385714 john -11.63 -11.14 0 0 21 q 11.1a 1274 1321...
0
8946
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9449
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9310
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9236
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9182
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6031
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3261
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 we have to send another system
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.