SyntaxFix
Write A Post
Hire A Developer
Questions
You are setting the label text before the button is clicked to "txt". Instead when the button is clicked call setText() on the label and pass it the text from the text field.
setText()
Example:
label1.setText(nameField.getText());