package com.IST240Apps import java.awt.event.* import java.awt.* public class Li
ID: 3709613 • Letter: P
Question
package com.IST240Apps import java.awt.event.* import java.awt.* public class ListenerKey extends Jframe implements Keylistener i JtextPield keyTextnew JTextField (80) Jlabel keyLabelnew Jlabel("Press any key in the text field.) public Listenerkey) super(ListenerKey setLookAndFeel); setsize (350, 100); setDefaultcloseonoperation (JFrame.EXIT ON CLOSE) keyText.addKeyListener (this); BorderLayout bordnew BorderLayout ) setLayout (border) add(keyLabel,BorderLayout.NORTH) add (keyText, BorderLayout.CENTER) setvisible (true) Override public void keyTyped (KeyEvent input) ( char key input.getKeyChar() keyLabel.setText ("You pressed: "+ key) @Override public void keyPressed (KeyEvent txt) // do nothing Override public void kyeeased (XeyEvent txt) ( private static void setLookAndFee1) try t UIManager.setLookAndFeel ( com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel" catch (Exception exc) f // ignore errorExplanation / Answer
Overriding:::
We add @override before the method declaration when the interface is implemented.
This is annotation.
It is to check wether the given method declaration is same as the method mention in the interface or not.
It is an approach to check the correctness of the methiod declaration.
It avoids accidentally declaring the new methods which are different from the interface declared methods.
This will take some time to compile because it inter-checks the methods declarations.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.