Write code that would go inside of a handler in a GUI program. The program shoul
ID: 3578556 • Letter: W
Question
Write code that would go inside of a handler in a GUI program. The program should do the following: when the user clicks the submit button, the program should get the text typed into the name field the program should display the name back to the user in all capital letters using the label once the display is updated, the user should not be able to click the button again The program might have more than one button that uses this listener! Use the following variables: JTextField nameInputField JLabel nameOutputLabel JButton submitButton Your code would go here: public class ButtonListener implements ActionListener { public void actionPerformed(ActionEvent e) { // YOUR CODE HERE } } Thank you
Explanation / Answer
class ButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
// YOUR CODE HERE
if(e.getSource() == submitButton ){//when submitButton button clicks
String name = nameInputField.getText();
nameOutputLabel.setText(name.toUpperCase());
submitButton.setEnabled(false);
}
else{
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.