// Create a MyFrame window that is derived from JFrame // Add JTextField and JLabel objects to the window. // Then write a name into the window. import java.awt.*; import javax.swing.*; import java.util.Scanner; public class MyFrame extends JFrame { public JLabel label; public JTextField textbox; public MyFrame( ) { // Set title in titlebar of window. super("MyFrame Example"); // Position textbox and label with flow layout setLayout(new FlowLayout( )); // Instantiate controls. textbox = new JTextField(15); label = new JLabel("Name"); // Add controls to window. getContentPane( ).add(textbox); getContentPane( ).add(label); // Set size of window to 200 pixels by 100 pixels. setSize(200, 100); // Make window visible. setVisible(true); } public static void main(String[ ] args) { // Create Scanner object. Scanner s = new Scanner(System.in); // Create window. MyFrame window = new MyFrame( ); // Write name in textbox. System.out.println("Enter name in textbox: "); window.textbox.setText(s.next( )); } }