import javax.swing.*; public class Demo { public static void main(String[] args) { JFrame frame = new JFrame(); JTextField textField = new JTextField(); textField.setBounds(50, 50, 150, 30); frame.add(textField); frame.setSize(300, 200); frame.setLayout(null); frame.setVisible(true); textField.setText("Hello, World!"); } }
import javax.swing.*; public class Demo { public static void main(String[] args) { JFrame frame = new JFrame(); JTextField textField = new JTextField(); textField.setBounds(50, 50, 150, 30); frame.add(textField); frame.setSize(300, 200); frame.setLayout(null); frame.setVisible(true); textField.setText(""); } }This example creates a JFrame and adds a JTextField to it. The `setText` method is used to clear the text value of the JTextField. In both examples, the javax.swing package library is used to create the JTextField and JFrame components.