dear Nazish
here is your program but i am still confused with the field width. plz tell me clearly whether to increse the field length with the string size or width of it so i will do that also INSHAALLAH.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
public class NFString extends JFrame
{
JLabel headl = new JLabel();
public JTextField tf = new JTextField("",0);
JPanel border1 = new JPanel(new BorderLayout(5,5));
JPanel border2 = new JPanel(new BorderLayout(5,5));
public JTextField tf1 = new JTextField("",0);
public JButton b1 = new JButton();
public String srg;
public int spaces;
public NFString()
{
super("String program");
this.setResizable(true);
Container content =getContentPane();
headl.setText("Type a string");
b1.setText("CHECK IT OUT");
b1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
if(ae.getActionCommand().equals("OK"))
{
srg = tf.getText();
int i2 = srg.length();
for(int a=0;a<i2;a++)
{
char ch = Character.toLowerCase(srg.charAt(a));
if(Character.isWhitespace(ch))
spaces++;
}
i2 = i2-spaces;
tf1.setText("the string is "+srg+" and "+" its "+i2+" characters long");
}
}
});
border1.add("North",headl);
border1.add("Center",border2);
border2.add("North",tf);
border2.add("Center",tf1);
border2.add("South",b1);
content.add(border1);
pack();
}
public static void main(String args[])
{
NFString nfs = new NFString();
nfs.setVisible(true);
}
}
take care and work hard
HumaMunir
|