♠ Posted by Unknown in Adv Java at 01:09
JTextField Class
The
swing text field is encapsulated by the JTextComponent class, which extends
JComponent. It provides functionality that is common to Swing text components.
One of its subclass is JTextField, which allows you to edit one line of text.
Some of its constructors are show here:
Some of its constructors are show here:
JTextFields()
JTextFields(int cols)
JTextFields(String s, int cols)
JTextFields(String s)
Here
s, is the string to be presented, and cols is the number of columns In the text
field.
/*
* <APPLET CODE = "JTextFieldExample.CLASS"
WIDTH = 500 HEIGHT = 500"></APPLET>
* */
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public
class JTextFieldExample extends JApplet implements ActionListener
{
JTextField jtf1, jtf2;
JLabel jl1, jl2;
public void init()
{
Container contentPane =
getContentPane();
contentPane.setLayout(new
FlowLayout());
jl1 = new JLabel("Enter
String : ");
jtf1 = new JTextField(15);
jl2 = new JLabel("See The
Output :");
jtf2 = new JTextField(15);
contentPane.add(jl1);
contentPane.add(jtf1);
contentPane.add(jl2);
contentPane.add(jtf2);
jtf1.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
jtf2.setText(jtf1.getText());
}
}
0 comments:
Post a Comment