Explain the code to create a textfield using java [closed]

In CreateNewJTextField:

this.getContentPane().setLayout(new FlowLayout());

This create a Pane and sets a default layout. Pane is like a piece of paper on which you draw.

JTextField field3 = new JTextField(10);
add(field3);

This creates a text field and adds it to that pane.

In createAndShowGUI, you are adding this pane to a JFrame(the frame with minimize, close buttons), which is like a drawing board.

frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Then you set the visibility of the frame, define what should happen on clicking close button.

Browse More Popular Posts

Leave a Comment