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 - 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;
-
private int y=4,x=8,j=1,i=1,count=1;
-
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:"};
-
JFrame f=new JFrame();
-
JPanel p=new JPanel();
-
JLabel l,l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,l11;
-
JTextArea ta,ta1;
-
JScrollPane spj,sp,sp2;
-
JButton b1;
-
-
public void init()
-
{
-
Container c=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),
-
"CoEdit collaboration software & service by Contexta", 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(st[1]);
-
l.setForeground(Color.darkGray);
-
l.setFont(new Font("Tahoma", Font.PLAIN, 14));
-
p.add(l, new GridBagConstraints(2,y=y+3,1, 1, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(50, 50, 5, 5), 0, 0));
-
-
for(;count>=1;count--)
-
{
-
ta = new JTextArea();
-
sp=new JScrollPane();
-
sp.setViewportView(ta);
-
p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(5,50, 5, 5), 700,30));
-
repaint();
-
}
-
-
-
//--------------------JButton--------------------------------------
-
-
b1 = new JButton("add");
-
p.add(b1, new GridBagConstraints(20,10,1, 1, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(0, 0, 5, 5), 0, 0));
-
-
b1.addActionListener(this);
-
-
//-----------------------Definition--------------------------
-
l1=new JLabel(st[2]);
-
l1.setForeground(Color.darkGray);
-
l1.setFont(new Font("Tahoma", Font.PLAIN, 14));
-
p.add(l1, new GridBagConstraints(2,x=x+3,1, 1, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(50, 50, 5, 5), 0, 0));
-
-
for(int count=1;count>=1;count--)
-
{
-
ta = new JTextArea();
-
sp=new JScrollPane();
-
sp.setViewportView(ta);
-
p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(5,50, 5, 5), 700,30));
-
repaint();
-
}
-
//--------------- Classification-----------------------
-
l2=new JLabel(st[3]);
-
l2.setForeground(Color.darkGray);
-
l2.setFont(new Font("Tahoma", Font.PLAIN, 14));
-
p.add(l2, new GridBagConstraints(2,x=x+3,1, 1, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(50, 50, 5, 5), 0, 0));
-
-
for(int count=5;count>=1;count--)
-
{
-
ta = new JTextArea();
-
sp=new JScrollPane();
-
sp.setViewportView(ta);
-
p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(5,50, 5, 5), 700,30));
-
repaint();
-
}
-
//----------------------Synonyms----------------------
-
l3=new JLabel(st[4]);
-
l3.setForeground(Color.darkGray);
-
l3.setFont(new Font("Tahoma", Font.PLAIN, 14));
-
p.add(l3, new GridBagConstraints(2,x=x+3,1, 1, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(50, 50, 5, 5), 0, 0));
-
-
for(int count=3;count>=1;count--)
-
{
-
ta = new JTextArea();
-
sp=new JScrollPane();
-
sp.setViewportView(ta);
-
p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(5,50, 5, 5), 700,30));
-
repaint();
-
}
-
-
//----------------Epidemiology---------------------------
-
l4=new JLabel(st[5]);
-
l4.setForeground(Color.darkGray);
-
l4.setFont(new Font("Tahoma", Font.PLAIN, 14));
-
p.add(l4, new GridBagConstraints(2,x=x+3,1, 1, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(50, 50, 5, 5), 0, 0));
-
-
for(int count=5;count>=1;count--)
-
{
-
ta = new JTextArea();
-
sp=new JScrollPane();
-
sp.setViewportView(ta);
-
p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(5,50, 5, 5), 700,30));
-
repaint();
-
}
-
-
//------------------Etiology-----------------------------
-
l5=new JLabel(st[6]);
-
l5.setForeground(Color.darkGray);
-
l5.setFont(new Font("Tahoma", Font.PLAIN, 14));
-
p.add(l5, new GridBagConstraints(2,x=x+3,1, 1, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(50, 50, 5, 5), 0, 0));
-
-
for(int count=5;count>=1;count--)
-
{
-
ta = new JTextArea();
-
sp=new JScrollPane();
-
sp.setViewportView(ta);
-
p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(5,50, 5, 5), 700,30));
-
repaint();
-
}
-
-
//-----------------------Genetics---------------
-
l6=new JLabel(st[7]);
-
l6.setForeground(Color.darkGray);
-
l6.setFont(new Font("Tahoma", Font.PLAIN, 14));
-
p.add(l6, new GridBagConstraints(2,x=x+3,1, 1, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(50, 50, 5, 5), 0, 0));
-
-
for(int count=5;count>=1;count--)
-
{
-
ta = new JTextArea();
-
sp=new JScrollPane();
-
sp.setViewportView(ta);
-
p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(5,50, 5, 5), 700,30));
-
repaint();
-
}
-
-
//------------------Clinical--------------
-
l7=new JLabel(st[8]);
-
l7.setForeground(Color.darkGray);
-
l7.setFont(new Font("Tahoma", Font.PLAIN, 14));
-
p.add(l7, new GridBagConstraints(2,x=x+3,1, 1, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(50, 50, 5, 5), 0, 0));
-
-
for(int count=5;count>=1;count--)
-
{
-
ta = new JTextArea();
-
sp=new JScrollPane();
-
sp.setViewportView(ta);
-
p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(5,50, 5, 5), 700,30));
-
repaint();
-
}
-
-
//-----------------Lab-------------------------
-
l8=new JLabel(st[9]);
-
l8.setForeground(Color.darkGray);
-
l8.setFont(new Font("Tahoma", Font.PLAIN, 14));
-
p.add(l8, new GridBagConstraints(2,x=x+3,1, 1, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(50, 50, 5, 5), 0, 0));
-
-
for(int count=5;count>=1;count--)
-
{
-
ta = new JTextArea();
-
sp=new JScrollPane();
-
sp.setViewportView(ta);
-
p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(5,50, 5, 5), 700,30));
-
repaint();
-
}
-
-
JScrollPane sp = new JScrollPane(p);
-
c.add(sp, BorderLayout.CENTER);
-
//f.setSize(200,200);
-
//f.setVisible(true);
-
}
-
public void paint(Graphics g)
-
{
-
super.paint(g);
-
g.drawString(ta.getText(),55,100);
-
}
-
public void actionPerformed(ActionEvent e)
-
{
-
if (e.getSource() == b1)
-
{
-
count=count+2;
-
ta = new JTextArea();
-
sp=new JScrollPane();
-
sp.setViewportView(ta);
-
p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(5,50, 5, 5), 700,30));
-
-
ta.setText("That was the wrong button!:"+count);
-
repaint();
-
}
-
-
}
-
}
7 2633
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.
horace1 1,510
Recognized Expert Top Contributor
below is a simple JApplet which creates JTextFeilds as requested by user input -
import java.awt.*;
-
import java.awt.event.*;
-
import javax.swing.*;
-
-
public class TextAreaJapplet extends JApplet implements ActionListener{
-
JTextField numberField=new JTextField(10), resultField=new JTextField(10);
-
JTextField textFields[];
-
Container content;
-
-
// initialse applet
-
public void init() {
-
content = getContentPane();
-
content.setLayout(new FlowLayout());
-
content.add(new JLabel("Number of text fields"));
-
numberField.addActionListener(this);
-
numberField.setName("number Field ");
-
content.add(numberField);
-
}
-
-
// JTextArea event
-
public void actionPerformed(ActionEvent e)
-
{
-
//System.out.println("event " + ((JTextField) e.getSource()).getName() + " text "+ ((JTextField) e.getSource()).getText());
-
// if event is numberField get value and create JTextFeilds
-
if(e.getSource() == numberField)
-
{
-
int number=Integer.parseInt(((JTextField) e.getSource()).getText());
-
System.out.println("number " + number);
-
// new the JTextFeilds, clear old content and add new JTextFields
-
textFields=new JTextField[number];
-
content.removeAll();
-
content.setLayout(new GridLayout(number+2,2));
-
numberField.addActionListener(this);
-
content.add(new JLabel("Number of text fields"));
-
content.add(numberField);
-
content.add(new JLabel("Last text entered"));
-
content.add(resultField);
-
for(int i=0; i<number; i++) // add new JTextFileds and actionlisteners
-
{
-
textFields[i]=new JTextField(10);
-
textFields[i].setName("JTextField " + i);
-
textFields[i].addActionListener(this);
-
content.add(new JLabel("JTextField " + i));
-
content.add(textFields[i]);
-
}
-
}
-
// display information about last event and repaint() the applet
-
resultField.setText(((JTextField) e.getSource()).getName() + " text "+ ((JTextField) e.getSource()).getText());
-
content.setVisible(true);
-
content.validate();
-
content.repaint() ;
-
}
-
}
-
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
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 - 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;
-
private int y=4,x=8,j=1,i=1,count=1;
-
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:"};
-
JFrame f=new JFrame();
-
JPanel p=new JPanel();
-
JLabel l,l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,l11;
-
JTextArea ta,ta1;
-
JScrollPane spj,sp,sp2;
-
JButton b1;
-
-
public void init()
-
{
-
Container c=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),
-
"CoEdit collaboration software & service by Contexta", 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(st[1]);
-
l.setForeground(Color.darkGray);
-
l.setFont(new Font("Tahoma", Font.PLAIN, 14));
-
p.add(l, new GridBagConstraints(2,y=y+3,1, 1, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(50, 50, 5, 5), 0, 0));
-
-
for(;count>=1;count--)
-
{
-
ta = new JTextArea();
-
sp=new JScrollPane();
-
sp.setViewportView(ta);
-
p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(5,50, 5, 5), 700,30));
-
repaint();
-
}
-
-
-
//--------------------JButton--------------------------------------
-
-
b1 = new JButton("add");
-
p.add(b1, new GridBagConstraints(20,10,1, 1, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(0, 0, 5, 5), 0, 0));
-
-
b1.addActionListener(this);
-
-
//-----------------------Definition--------------------------
-
l1=new JLabel(st[2]);
-
l1.setForeground(Color.darkGray);
-
l1.setFont(new Font("Tahoma", Font.PLAIN, 14));
-
p.add(l1, new GridBagConstraints(2,x=x+3,1, 1, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(50, 50, 5, 5), 0, 0));
-
-
for(int count=1;count>=1;count--)
-
{
-
ta = new JTextArea();
-
sp=new JScrollPane();
-
sp.setViewportView(ta);
-
p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(5,50, 5, 5), 700,30));
-
repaint();
-
}
-
//--------------- Classification-----------------------
-
l2=new JLabel(st[3]);
-
l2.setForeground(Color.darkGray);
-
l2.setFont(new Font("Tahoma", Font.PLAIN, 14));
-
p.add(l2, new GridBagConstraints(2,x=x+3,1, 1, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(50, 50, 5, 5), 0, 0));
-
-
for(int count=5;count>=1;count--)
-
{
-
ta = new JTextArea();
-
sp=new JScrollPane();
-
sp.setViewportView(ta);
-
p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(5,50, 5, 5), 700,30));
-
repaint();
-
}
-
//----------------------Synonyms----------------------
-
l3=new JLabel(st[4]);
-
l3.setForeground(Color.darkGray);
-
l3.setFont(new Font("Tahoma", Font.PLAIN, 14));
-
p.add(l3, new GridBagConstraints(2,x=x+3,1, 1, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(50, 50, 5, 5), 0, 0));
-
-
for(int count=3;count>=1;count--)
-
{
-
ta = new JTextArea();
-
sp=new JScrollPane();
-
sp.setViewportView(ta);
-
p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(5,50, 5, 5), 700,30));
-
repaint();
-
}
-
-
//----------------Epidemiology---------------------------
-
l4=new JLabel(st[5]);
-
l4.setForeground(Color.darkGray);
-
l4.setFont(new Font("Tahoma", Font.PLAIN, 14));
-
p.add(l4, new GridBagConstraints(2,x=x+3,1, 1, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(50, 50, 5, 5), 0, 0));
-
-
for(int count=5;count>=1;count--)
-
{
-
ta = new JTextArea();
-
sp=new JScrollPane();
-
sp.setViewportView(ta);
-
p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(5,50, 5, 5), 700,30));
-
repaint();
-
}
-
-
//------------------Etiology-----------------------------
-
l5=new JLabel(st[6]);
-
l5.setForeground(Color.darkGray);
-
l5.setFont(new Font("Tahoma", Font.PLAIN, 14));
-
p.add(l5, new GridBagConstraints(2,x=x+3,1, 1, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(50, 50, 5, 5), 0, 0));
-
-
for(int count=5;count>=1;count--)
-
{
-
ta = new JTextArea();
-
sp=new JScrollPane();
-
sp.setViewportView(ta);
-
p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(5,50, 5, 5), 700,30));
-
repaint();
-
}
-
-
//-----------------------Genetics---------------
-
l6=new JLabel(st[7]);
-
l6.setForeground(Color.darkGray);
-
l6.setFont(new Font("Tahoma", Font.PLAIN, 14));
-
p.add(l6, new GridBagConstraints(2,x=x+3,1, 1, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(50, 50, 5, 5), 0, 0));
-
-
for(int count=5;count>=1;count--)
-
{
-
ta = new JTextArea();
-
sp=new JScrollPane();
-
sp.setViewportView(ta);
-
p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(5,50, 5, 5), 700,30));
-
repaint();
-
}
-
-
//------------------Clinical--------------
-
l7=new JLabel(st[8]);
-
l7.setForeground(Color.darkGray);
-
l7.setFont(new Font("Tahoma", Font.PLAIN, 14));
-
p.add(l7, new GridBagConstraints(2,x=x+3,1, 1, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(50, 50, 5, 5), 0, 0));
-
-
for(int count=5;count>=1;count--)
-
{
-
ta = new JTextArea();
-
sp=new JScrollPane();
-
sp.setViewportView(ta);
-
p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(5,50, 5, 5), 700,30));
-
repaint();
-
}
-
-
//-----------------Lab-------------------------
-
l8=new JLabel(st[9]);
-
l8.setForeground(Color.darkGray);
-
l8.setFont(new Font("Tahoma", Font.PLAIN, 14));
-
p.add(l8, new GridBagConstraints(2,x=x+3,1, 1, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(50, 50, 5, 5), 0, 0));
-
-
for(int count=5;count>=1;count--)
-
{
-
ta = new JTextArea();
-
sp=new JScrollPane();
-
sp.setViewportView(ta);
-
p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(5,50, 5, 5), 700,30));
-
repaint();
-
}
-
-
JScrollPane sp = new JScrollPane(p);
-
c.add(sp, BorderLayout.CENTER);
-
//f.setSize(200,200);
-
//f.setVisible(true);
-
}
-
public void paint(Graphics g)
-
{
-
super.paint(g);
-
g.drawString(ta.getText(),55,100);
-
}
-
public void actionPerformed(ActionEvent e)
-
{
-
if (e.getSource() == b1)
-
{
-
count=count+2;
-
ta = new JTextArea();
-
sp=new JScrollPane();
-
sp.setViewportView(ta);
-
p.add(sp, new GridBagConstraints(2,x=x+1, 17, 2, 0.0, 0.0,
-
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
-
new Insets(5,50, 5, 5), 700,30));
-
-
ta.setText("That was the wrong button!:"+count);
-
repaint();
-
}
-
-
}
-
}
Is the problem solved then?
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();
}
}
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?
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)
{ }
}
}
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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 ***
|
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
|
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.
|
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...
| |
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");
|
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>
|
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();
|
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...
|
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...
|
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...
| |
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...
|
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,...
|
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...
|
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();...
|
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...
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |