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 2602
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.
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.event.*;
import java.awt.event.*;
import java.io.*;
import java.applet.*;
public class Add1 extends JApplet implements ActionListener
{
Container c;
int y=8,x=8,j=1,i=1,count=1,t;
JFrame f=new JFrame();
JPanel p=new JPanel();
JLabel l;
JTextArea ta;
JTextArea ta1,ta2;
JScrollPane sp,sp1;
JButton b1,b2;
Add1()
{
Container c=f.getContentPane();
c.setLayout(new BorderLayout());
p=new JPanel();
p.setBorder(new javax.swing.border.CompoundBorder(
new javax.swing.border.TitledBorder(new javax.swing.border.EmptyBorder(0, 0, 0, 0),
" ", javax.swing.border.TitledBorder.CENTER,
javax.swing.border.TitledBorder.BOTTOM, new java.awt.Font("Dialog", java.awt.Font.BOLD, 18),
java.awt.Color.black), p.getBorder())); p.addPropertyChangeListener(new java.beans.PropertyChangeListener(){public void propertyChange(java.beans.PropertyChangeEvent e){if("border".equals(e.getPropertyName()))throw new RuntimeException();}});
p.setForeground(Color.lightGray);
p.setLayout(new GridBagLayout());
((GridBagLayout)p.getLayout()).columnWidths = new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
((GridBagLayout)p.getLayout()).rowHeights = new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
((GridBagLayout)p.getLayout()).columnWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};
((GridBagLayout)p.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};
//---------------Key features-----------------------
l=new JLabel("Key Features");
l.setForeground(Color.darkGray);
l.setFont(new Font("Tahoma", Font.PLAIN, 14));
p.add(l, new GridBagConstraints(2,7,1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(50, 50, 5, 5), 0, 0));
ta1=new JTextArea();
sp1=new JScrollPane();
sp1.setViewportView(ta1);
p.add(sp1, new GridBagConstraints(2,8, 17, 2, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(5,50, 5, 5), 700,30));
//--------------------JButton--------------------------------------
b1 = new JButton("add");
p.add(b1, new GridBagConstraints(20,9,1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 5, 5), 0, 0));
b1.addActionListener(this);
JScrollPane sp = new JScrollPane();
sp.setViewportView(p);
c.add(sp, BorderLayout.CENTER);
f.setSize(400,400);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == b1)
{
ta2=new JTextArea();
sp1=new JScrollPane();
sp1.setViewportView(ta2);
p.add(sp1, new GridBagConstraints(2,x=x+2, 17, 2, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(5,50, 5, 5), 700,30));
b2 = new JButton("add");
p.add(b2, new GridBagConstraints(20,y=y+2,1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 5, 5), 0, 0));
}
b2.addActionListener(this);
if(e.getSource() ==b2)
{
l=new JLabel("defination");
l.setForeground(Color.darkGray);
l.setFont(new Font("Tahoma", Font.PLAIN, 14));
p.add(l, new GridBagConstraints(2,x=x+2,1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(50, 50, 5, 5), 0, 0));
}
b1=b2;
f.validate();
}
public static void main(String[] a)
{
Add1 a1=new Add1();
}
}
please help me. In my frame the components r generated dyanamicaly when i am click the button.
after clicking is over create 2nd component.but when i am clicking each time second label created. i want to create my second label after end of last click.
please help me
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.io.*;
import java.applet.*;
public class Add1 extends JApplet implements ActionListener
{
Container c;
int y=8,x=8,j=1,i=1,count=1,t;
JFrame f=new JFrame();
JPanel p=new JPanel();
JLabel l;
JTextArea ta;
JTextArea ta1,ta2;
JScrollPane sp,sp1;
JButton b1,b2;
Add1()
{
Container c=f.getContentPane();
c.setLayout(new BorderLayout());
p=new JPanel();
p.setBorder(new javax.swing.border.CompoundBorder(
new javax.swing.border.TitledBorder(new javax.swing.border.EmptyBorder(0, 0, 0, 0),
" ", javax.swing.border.TitledBorder.CENTER,
javax.swing.border.TitledBorder.BOTTOM, new java.awt.Font("Dialog", java.awt.Font.BOLD, 18),
java.awt.Color.black), p.getBorder())); p.addPropertyChangeListener(new java.beans.PropertyChangeListener(){public void propertyChange(java.beans.PropertyChangeEvent e){if("border".equals(e.getPropertyName()))throw new RuntimeException();}});
p.setForeground(Color.lightGray);
p.setLayout(new GridBagLayout());
((GridBagLayout)p.getLayout()).columnWidths = new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
((GridBagLayout)p.getLayout()).rowHeights = new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
((GridBagLayout)p.getLayout()).columnWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};
((GridBagLayout)p.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};
//---------------Key features-----------------------
l=new JLabel("Key Features");
l.setForeground(Color.darkGray);
l.setFont(new Font("Tahoma", Font.PLAIN, 14));
p.add(l, new GridBagConstraints(2,7,1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(50, 50, 5, 5), 0, 0));
ta1=new JTextArea();
sp1=new JScrollPane();
sp1.setViewportView(ta1);
p.add(sp1, new GridBagConstraints(2,8, 17, 2, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(5,50, 5, 5), 700,30));
//--------------------JButton--------------------------------------
b1 = new JButton("add");
p.add(b1, new GridBagConstraints(20,9,1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 5, 5), 0, 0));
b1.addActionListener(this);
JScrollPane sp = new JScrollPane();
sp.setViewportView(p);
c.add(sp, BorderLayout.CENTER);
f.setSize(400,400);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == b1)
{
ta2=new JTextArea();
sp1=new JScrollPane();
sp1.setViewportView(ta2);
p.add(sp1, new GridBagConstraints(2,x=x+2, 17, 2, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(5,50, 5, 5), 700,30));
b2 = new JButton("add");
p.add(b2, new GridBagConstraints(20,y=y+2,1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 5, 5), 0, 0));
}
b2.addActionListener(this);
if(e.getSource() ==b2)
{
l=new JLabel("defination");
l.setForeground(Color.darkGray);
l.setFont(new Font("Tahoma", Font.PLAIN, 14));
p.add(l, new GridBagConstraints(2,x=x+2,1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(50, 50, 5, 5), 0, 0));
}
b1=b2;
f.validate();
}
public static void main(String[] a)
{
Add1 a1=new Add1();
}
}
1.) Please do not double post
2.) Use code tags when posting code
3.)Did you follow the advice given you when you posted this yesterday?
please help i have 3 classes 1.NewForm3.java(design of fame)2.NewFormxml2.java(generate xml file)3.OpenForm3.java(retrieve xml values in to frame)
but my problem is i am retrieveing xml values in OpenForm3.java those values does n't display corresponding fields. please help me. //NewForm3.java
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.io.*;
import java.applet.*;
public class NewForm3 extends JApplet
{
JFrame f=new JFrame();
String str=new String();
String dir2,dir1;
public String str2=" ";
JMenuBar mb;
JMenu file;
JPanel p;
JLabel l;
JTextArea ta1;
JScrollPane sp,sp1;
JComboBox cb;
public void hold2(String str2)
{
this.str2=str2;
System.out.println(str2);
}
public NewForm3()
{
cb = new JComboBox();
mb = new JMenuBar();
file = new JMenu("file");
ta1 = new JTextArea();
sp1 = new JScrollPane();
Container c=f.getContentPane();
c.setLayout(new BorderLayout());
p=new JPanel();
p.setBorder(new javax.swing.border.CompoundBorder(
new javax.swing.border.TitledBorder(new javax.swing.border.EmptyBorder(0, 0, 0, 0),
" ", javax.swing.border.TitledBorder.CENTER,
javax.swing.border.TitledBorder.BOTTOM, new java.awt.Font("Dialog", java.awt.Font.BOLD, 18),
java.awt.Color.black), p.getBorder())); p.addPropertyChangeListener(new java.beans.PropertyChangeListener(){public void propertyChange(java.beans.PropertyChangeEvent e){if("border".equals(e.getPropertyName()))throw new RuntimeException();}});
p.setForeground(Color.lightGray);
p.setLayout(new GridBagLayout());
((GridBagLayout)p.getLayout()).columnWidths = new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
((GridBagLayout)p.getLayout()).rowHeights = new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
((GridBagLayout)p.getLayout()).columnWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};
((GridBagLayout)p.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};
//-------menubar------
OpenAction open = new OpenAction("open",new ImageIcon("action.gif"));
JMenuItem mi2 = new JMenuItem(open);
JButton eb2 = new JButton("open");
file.add(mi2);
mb.add(file);
OpenAction save = new OpenAction("save",new ImageIcon("action.gif"));
JMenuItem mi1 = new JMenuItem(save);
JButton eb = new JButton("save");
file.add(mi1);
p.add(mb, new GridBagConstraints(2, 0, 21, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 5,5),1024, 0));
l=new JLabel("Key features:");
l.setForeground(Color.darkGray);
l.setFont(new Font("Tahoma", Font.PLAIN, 14));
p.add(l, new GridBagConstraints(2,7,1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(50, 50, 5, 5), 0, 0));
sp1=new JScrollPane();
sp1.setViewportView(ta1);
p.add(sp1, new GridBagConstraints(2,10, 17, 2, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(5,50, 5, 5), 700,40));
JScrollPane sp = new JScrollPane(p);
c.add(sp, BorderLayout.CENTER);
f.setSize(200,200);
f.setVisible(true);
}
public class OpenAction extends AbstractAction {
public OpenAction(String text, Icon icon) {
super(text,icon);
}
public void actionPerformed(ActionEvent e) {
String s=e.getActionCommand();
if(s.equals("open"))
{
try{
FileDialog fd=new FileDialog(f,"open",FileDialog.LOAD);
fd.show();
String dir1=fd.getDirectory();
String fname1=fd.getFile();
if((dir1 != null)&&(fname1 != null))
{
dir1=dir1+"/"+fname1;
readFile(dir1);
}
OpenForm3 o1=new OpenForm3();
o1.hold1(dir1);
o1.parseXmlFile();
ta1.setText(str2);
System.out.println(str2);
}
catch(Exception ex)
{
System.out.println(ex);
}
}
else if(s.equals("save"))
{
try{
FileDialog fd=new FileDialog(f,"Save As",FileDialog.SAVE);
fd.show();
String dir2=fd.getDirectory();
String fname2=fd.getFile();
if((dir2 != null)&&(fname2 != null))
{
dir2=dir2+"/"+fname2;
System.out.println(dir2);
writeFile(dir2);
}
str=ta1.getText();
NewFormxml2 n1=new NewFormxml2();
n1.hold(str,dir2);
n1.MyParser();
ta1.setText(" ");
}
catch(Exception ex)
{
System.out.println(ex);
}
}
}//ap
}//ope
public void writeFile(String dir2)
{
try{
FileOutputStream fos=new FileOutputStream(dir2);
String data="<?xml version=\"1.0\"?><Lesion></Lesion>";
byte ba[]=data.getBytes();
fos.write(ba);
fos.close();
}
catch(Exception ex)
{ }
}
public void readFile(String dir1)
{
try{
FileInputStream fis=new FileInputStream(dir1);
byte ba[]=new byte[fis.available()];
fis.read(ba);
fis.close();
}
catch(Exception ex)
{ }
}
public static void main(String[] a)
{
NewForm3 n=new NewForm3();
}
} //NewFormxml2.java
import java.io.*;
import com.ibm.xml.parser.*;
import org.w3c.dom.*;
public class NewFormxml2
{
String str,dir2;
public void hold(String str,String dir2)
{
this.dir2=dir2;
this.str=str;
}
public void MyParser()
{
try{
Parser p=new Parser("myerrors");
TXDocument td=p.readStream(new FileInputStream(dir2));
Element Lesion=td.getDocumentElement();
Element Key_features=td.createElement("Key_features");
Node Key_features_tx=td.createTextNode(str);
Key_features.appendChild(Key_features_tx);
Lesion.appendChild(Key_features);
NodeList nl2=Lesion.getElementsByTagName("Key_features");
Node n2=nl2.item(0);
Lesion.insertBefore(Key_features,n2);
td.printWithFormat(new FileWriter(dir2));
}
catch(Exception e)
{ }
}
}
//OpenForm3.java
import java.io.*;
import com.ibm.xml.parser.*;
import org.w3c.dom.*;
public class NewFormxml2
{
String str,dir2;
public void hold(String str,String dir2)
{
this.dir2=dir2;
this.str=str;
}
public void MyParser()
{
try{
Parser p=new Parser("myerrors");
TXDocument td=p.readStream(new FileInputStream(dir2));
Element Lesion=td.getDocumentElement();
Element Key_features=td.createElement("Key_features");
Node Key_features_tx=td.createTextNode(str);
Key_features.appendChild(Key_features_tx);
Lesion.appendChild(Key_features);
NodeList nl2=Lesion.getElementsByTagName("Key_features");
Node n2=nl2.item(0);
Lesion.insertBefore(Key_features,n2);
td.printWithFormat(new FileWriter(dir2));
}
catch(Exception e)
{ }
}
}
please help i have 3 classes 1.NewForm3.java(design of fame)2.NewFormxml2.java(generate xml file)3.OpenForm3.java(retrieve xml values in to frame)
but my problem is i am retrieveing xml values in OpenForm3.java those values does n't display corresponding fields. please help me. //NewForm3.java
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.io.*;
import java.applet.*;
public class NewForm3 extends JApplet
{
JFrame f=new JFrame();
String str=new String();
String dir2,dir1;
public String str2=" ";
JMenuBar mb;
JMenu file;
JPanel p;
JLabel l;
JTextArea ta1;
JScrollPane sp,sp1;
JComboBox cb;
public void hold2(String str2)
{
this.str2=str2;
System.out.println(str2);
}
public NewForm3()
{
cb = new JComboBox();
mb = new JMenuBar();
file = new JMenu("file");
ta1 = new JTextArea();
sp1 = new JScrollPane();
Container c=f.getContentPane();
c.setLayout(new BorderLayout());
p=new JPanel();
p.setBorder(new javax.swing.border.CompoundBorder(
new javax.swing.border.TitledBorder(new javax.swing.border.EmptyBorder(0, 0, 0, 0),
" ", javax.swing.border.TitledBorder.CENTER,
javax.swing.border.TitledBorder.BOTTOM, new java.awt.Font("Dialog", java.awt.Font.BOLD, 18),
java.awt.Color.black), p.getBorder())); p.addPropertyChangeListener(new java.beans.PropertyChangeListener(){public void propertyChange(java.beans.PropertyChangeEvent e){if("border".equals(e.getPropertyName()))throw new RuntimeException();}});
p.setForeground(Color.lightGray);
p.setLayout(new GridBagLayout());
((GridBagLayout)p.getLayout()).columnWidths = new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
((GridBagLayout)p.getLayout()).rowHeights = new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
((GridBagLayout)p.getLayout()).columnWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};
((GridBagLayout)p.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};
//-------menubar------
OpenAction open = new OpenAction("open",new ImageIcon("action.gif"));
JMenuItem mi2 = new JMenuItem(open);
JButton eb2 = new JButton("open");
file.add(mi2);
mb.add(file);
OpenAction save = new OpenAction("save",new ImageIcon("action.gif"));
JMenuItem mi1 = new JMenuItem(save);
JButton eb = new JButton("save");
file.add(mi1);
p.add(mb, new GridBagConstraints(2, 0, 21, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 5,5),1024, 0));
l=new JLabel("Key features:");
l.setForeground(Color.darkGray);
l.setFont(new Font("Tahoma", Font.PLAIN, 14));
p.add(l, new GridBagConstraints(2,7,1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(50, 50, 5, 5), 0, 0));
sp1=new JScrollPane();
sp1.setViewportView(ta1);
p.add(sp1, new GridBagConstraints(2,10, 17, 2, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(5,50, 5, 5), 700,40));
JScrollPane sp = new JScrollPane(p);
c.add(sp, BorderLayout.CENTER);
f.setSize(200,200);
f.setVisible(true);
}
public class OpenAction extends AbstractAction {
public OpenAction(String text, Icon icon) {
super(text,icon);
}
public void actionPerformed(ActionEvent e) {
String s=e.getActionCommand();
if(s.equals("open"))
{
try{
FileDialog fd=new FileDialog(f,"open",FileDialog.LOAD);
fd.show();
String dir1=fd.getDirectory();
String fname1=fd.getFile();
if((dir1 != null)&&(fname1 != null))
{
dir1=dir1+"/"+fname1;
readFile(dir1);
}
OpenForm3 o1=new OpenForm3();
o1.hold1(dir1);
o1.parseXmlFile();
ta1.setText(str2);
System.out.println(str2);
}
catch(Exception ex)
{
System.out.println(ex);
}
}
else if(s.equals("save"))
{
try{
FileDialog fd=new FileDialog(f,"Save As",FileDialog.SAVE);
fd.show();
String dir2=fd.getDirectory();
String fname2=fd.getFile();
if((dir2 != null)&&(fname2 != null))
{
dir2=dir2+"/"+fname2;
System.out.println(dir2);
writeFile(dir2);
}
str=ta1.getText();
NewFormxml2 n1=new NewFormxml2();
n1.hold(str,dir2);
n1.MyParser();
ta1.setText(" ");
}
catch(Exception ex)
{
System.out.println(ex);
}
}
}//ap
}//ope
public void writeFile(String dir2)
{
try{
FileOutputStream fos=new FileOutputStream(dir2);
String data="<?xml version=\"1.0\"?><Lesion></Lesion>";
byte ba[]=data.getBytes();
fos.write(ba);
fos.close();
}
catch(Exception ex)
{ }
}
public void readFile(String dir1)
{
try{
FileInputStream fis=new FileInputStream(dir1);
byte ba[]=new byte[fis.available()];
fis.read(ba);
fis.close();
}
catch(Exception ex)
{ }
}
public static void main(String[] a)
{
NewForm3 n=new NewForm3();
}
} //NewFormxml2.java
import java.io.*;
import com.ibm.xml.parser.*;
import org.w3c.dom.*;
public class NewFormxml2
{
String str,dir2;
public void hold(String str,String dir2)
{
this.dir2=dir2;
this.str=str;
}
public void MyParser()
{
try{
Parser p=new Parser("myerrors");
TXDocument td=p.readStream(new FileInputStream(dir2));
Element Lesion=td.getDocumentElement();
Element Key_features=td.createElement("Key_features");
Node Key_features_tx=td.createTextNode(str);
Key_features.appendChild(Key_features_tx);
Lesion.appendChild(Key_features);
NodeList nl2=Lesion.getElementsByTagName("Key_features");
Node n2=nl2.item(0);
Lesion.insertBefore(Key_features,n2);
td.printWithFormat(new FileWriter(dir2));
}
catch(Exception e)
{ }
}
}
//OpenForm3.java
import java.io.*;
import com.ibm.xml.parser.*;
import org.w3c.dom.*;
public class NewFormxml2
{
String str,dir2;
public void hold(String str,String dir2)
{
this.dir2=dir2;
this.str=str;
}
public void MyParser()
{
try{
Parser p=new Parser("myerrors");
TXDocument td=p.readStream(new FileInputStream(dir2));
Element Lesion=td.getDocumentElement();
Element Key_features=td.createElement("Key_features");
Node Key_features_tx=td.createTextNode(str);
Key_features.appendChild(Key_features_tx);
Lesion.appendChild(Key_features);
NodeList nl2=Lesion.getElementsByTagName("Key_features");
Node n2=nl2.item(0);
Lesion.insertBefore(Key_features,n2);
td.printWithFormat(new FileWriter(dir2));
}
catch(Exception e)
{ }
}
}
You are quite incapable of understanding instructions aren't you?
Ok tell me about how you want to generate the xml file first.
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...
|
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...
|
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...
|
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...
|
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
...
|
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...
|
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 =...
|
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...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |