Constructors | Description |
---|---|
TextField() | Constructs a new text field. |
TextField(int columns) | Constructs a new empty text field with the specified number of columns. |
TextField(String str) | Creates a new text field initialized with specified text. |
TextField(String str, int columns) | Constructs a new text field with the specified text to be displayed, and it holds the specified number of columns. |
Constructors | Description |
---|---|
JTetxField() | Used to construct a new TextFiled. |
JTetxField(Document doc, String str, int cols) | Constructs a new JTextField that uses the given text storage model and given number of columns. |
JTetxField(int cols) | Constructs new empty TextField with the given number of columns. |
JTetxField(String str) | Constructs a new TextField initialized with the specified string. |
JTetxField(String str, int cols) | Constructs a new TextField with the specified string value and columns. |
// FrameTest.java
import java.awt.*;
import java.awt.event.*;
public class FrameTest extends Frame implements ActionListener
{
String title;
Button b1, b2;
TextField text1, text2;
public FrameTest(String title)
{
super(title);
setLayout(new FlowLayout());
text1 = new TextField(20);
b1 = new Button("Reset");
text2 = new TextField(20);
b2 = new Button("Submit");
add(text1);
add(b1);
add(text2);
add(b2);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
String str = "";
if(e.getSource() == b1)
{
text1.setText(str+" You click reset button..");
}
if(e.getSource() == b2)
{
text2.setText(str+" You click submit button..");
}
}
public static void main(String args[])
{
FrameTest frame = new FrameTest("Frame with TextField & Button:");
frame.setSize(300,200);
frame.setBackground(Color.pink);
frame.setVisible(true);
}
}
Constructors | Description |
---|---|
JPasswordField() | Creates a new password field. |
JPasswordField(Document doc, String str, int size) | Creates a new JPassword field that uses the given text storage model and specifies the password size. |
JPasswordField(int size) | Constructs a new JPasswordField with the specified number of characters. |
JPasswordField(String str) | Constructs the new JPassword field initialized with specified text. |
JPasswordField(String str, int size) | Constructs a new JPasswordField initialized with the specified text and size. |
// JPasswordDemo.java
import javax.swing.*;
public class JPasswordDemo
{
public static void main(String args[])
{
JFrame frame = new JFrame("JPasswordField & JTextField");
JPanel panel = new JPanel();
JLabel l1 = new JLabel("Username");
JLabel l2 = new JLabel("Password");
JLabel l3 = new JLabel("Confirm !!!");
JTextField text = new JTextField(20);
JPasswordField pass1 = new JPasswordField(20);
JPasswordField pass2 = new JPasswordField(20);
panel.add(l1);
panel.add(text);
panel.add(l2);
panel.add(pass1);
panel.add(l3);
panel.add(pass2);
frame.add(panel);
frame.setSize(350, 150);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
// JFormattedTextFieldDemo.Java
import javax.swing.*;
public class JFormattedTextFieldDemo
{
public static void main(String args[])
{
JFrame frame = new JFrame("JFormattedTextField ");
JPanel panel = new JPanel();
JFormattedTextField jft1 = new JFormattedTextField();
String date = new String();
date = "Date";
jft1 = new JFormattedTextField(new java.util.Date());
JLabel label1 = new JLabel(date);
panel.add(label1);
panel.add(jft1);
JFormattedTextField jft2 = new FormattedTextField(java.text.NumberFormat.getCurrencyInstance());
jft2.setValue(new Float(50.50));
JLabel label2 = new JLabel("Currency");
panel.add(label2);
panel.add(jft2);
frame.add(panel);
frame.setSize(350, 180);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}