I try to create a Key Listener in java, but when I try
KeyListener listener = new KeyListener();
Netbeans tells me that KeyListener is abstract, cannot be created. I know that I don’t have any other part of this listener, but since this is my first time using a key listener, I’m not sure what else I need. Why does this tell me that?
Thank,
Tomek
KeyListener- this is an interface - it must be implemented by something. So you can do:
KeyListener
KeyListener listener = new SomeKeyListenerImplementation();
but you cannot create it directly. You can use an anonymous inner class:
KeyListener listener = new KeyListener() { public void keyPressed(KeyEvent e) { /* ... */ } public void keyReleased(KeyEvent e) { /* ... */ } public void keyTyped(KeyEvent e) { /* ... */ } };
It depends on what you want to do, basically.
KeyListener - , , , . , , inline, KeyAdapter, , KeyListener, . KeyAdapter, , , . , keyPressed,
KeyListener listener = new KeyAdapter() { public void keyPressed(KeyEvent e) { /* ... */ } };
.
KeyListener - , , . , tutorial.
Source: https://habr.com/ru/post/1699502/More articles:WPF application development - any way to optimize a .NET installation? - c #How to force PHP to use UTF-8 encoding - htmlWCF Duplex Service and TCP Port Exhaustion - .netWPF: проблема с флажком при привязке datatrigger к свойству "Ischecked" - checkboxEclipse CDT 5.0.1 Slow Indexer Issue (Ganymede) - c ++Best collection to use? - javaHow to create conditions based on a user role using JSF / MyFaces? - javaHow to get a file from sourceafe programmatically? - c #How to add CardSpace support to an ASP.NET application - securityHow do you use F1 help in Delphi 2007? - delphiAll Articles