Text edit in Java Program
Text edit in Java Program
import java.awt.*;
import javax.swing.*;
class TextEdit
{
public Static void main(String args[])
{
JFrame frame =new JFrame();
Container cp =frame.getContentPanel();
JPanel panel =new JPanel();
JLabel lab =new JLabel("Enter the text to be replaced");
panel.add(lab);
final JTextFiled tf1 =new JTextField("Text1",10);
panel.add(lab);
final JTextField tf2 =new JTextField("Text",10);
panel.add(tf2);
final JTextArea txt =new JTextArea(5,20);
txt.setText("The quick brown fox jumps over the lazy dog");
txt.setLineWrap(true);
final JScrollPane ScrollPane =new JScrollPane(txt);
panel.add(scrollPane);
JButton b=new JButton("Replace");
panel.add(b);
b.addActionListener(new ActionListenr()
{
public void actionPerformed(ActionEvent e)
{
String f=tf1.getText();
int n=txt.getText();
int n=txt.getText().indexOf(f);
if(n>=0&&f.length()>0)
txt.replaceRange(tf2.getText(),n,n+f.length());
}
});
cp.add(panel);
frame.setSize(300,200);
frame.setDefaultCloseOpration(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
0 coment�rios:
Post a Comment