k a * q1: Write a public class named DryMouseListener that implements the MouseL
ID: 3698768 • Letter: K
Question
k a * q1: Write a public class named DryMouseListener that implements the MouseListener *interface. This class will have a public constructor that takes a JTextField and a JLabel * as parameters and stores these in instance variables. Override the mouseEntered method to * display the text from the JTextField on the JLabel in all upper case letters. Then, * override the mouseReleased method to display the text from the JTextField on the JLabel in all lower case letters. The other three methods from the MouseListener interface can be * left emptyExplanation / Answer
import javax.swing.*; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; public class DryMouseListener implements MouseListener { private JTextField textField; private JLabel label; public DryMouseListener(JTextField textField, JLabel label) { this.textField = textField; this.label = label; } @Override public void mouseClicked(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { label.setText(textField.getText().toLowerCase()); } @Override public void mouseEntered(MouseEvent e) { label.setText(textField.getText().toUpperCase()); } @Override public void mouseExited(MouseEvent e) { } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.