Swing/Java: How to use the getText and setText string properly

后端 未结 4 1584
青春惊慌失措
青春惊慌失措 2021-01-05 16:28

I\'m trying to make input nameField appear in a Label called label1 after a Button called button1 is clicked

4条回答
  •  心在旅途
    2021-01-05 17:01

    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.

    Example:

    label1.setText(nameField.getText()); 
    

提交回复
热议问题