
How to create "ttextfield" in java? please give a demo code of it.

import java.awt.*;
import java.sql.*;
import javax.swing.*;
import java.awt.event.*;
class TextFieldExample {
public static void main(String[] args) {
Frame f = new Frame();
Label label = new Label("Name: ");
final TextField text = new TextField(20);
Button b = new Button("Show");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String value = text.getText();
JOptionPane.showMessageDialog(null, "Hello " + value);
}
});
Panel p = new Panel(new GridLayout(2, 2));
p.add(label);
p.add(text);
p.add(b);
f.add(p);
f.setVisible(true);
f.pack();
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.