Swing/Java: How to use the getText and setText string properly
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:
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:
Two ways: 1. Implement ActionListener in your class, then use jBtnSelection.addActionListener(this); Later, you’ll have to define a menthod, public void actionPerformed(ActionEvent e). However, doing this for multiple buttons can be confusing, because the actionPerformed method will have to check the source of each event (e.getSource()) to see which button it came from. 2. Use anonymous inner classes: Later, you’ll have to define selectionButtonPressed(). … Read more
use frame.setLayout(null); this will allow you to place the Label, Button etc. where you like