I read the book "Learning java" and thought that I understood what was happening. But on the Internet I came across a lesson with events. Here is the code:

import java.awt.*; import java.applet.*; public class Focus extends Applet { String msg; public void init() { msg=""; Font font=new Font("TimesRoman",Font.BOLD,16); setFont(font); } public void paint(Graphics g) { g.drawString(msg,50,50); } public boolean gotFocus(Event evt, Object arg) { msg="Получен фокус"; repaint(); return true; } public boolean lostFocus(Event evt, Object arg) { msg="Фокус утерян"; repaint(); return true; } } 

How it works? Where are the internal classes with implementations, where are the students? And in general, I was surprised how it started. Comrades, please explain!

  • This is not accidentally associated with the parent class, the class applet initially contains listeners? - Vikkingg 7:38 pm
  • Applets died about 10 years ago - they now have a very limited scope of use, so they didn’t start studying. - Barmaley

1 answer 1

 import java.awt.*; import java.applet.*; public class Focus extends Applet { String msg; //унаследовано от Applet public void init() { msg=""; Font font=new Font("TimesRoman",Font.BOLD,16); setFont(font); } //унаследовано от Applet, а он у java.awt.Component public void paint(Graphics g) { g.drawString(msg,50,50); } //унаследовано от Applet, а он у java.awt.Component public boolean gotFocus(Event evt, Object arg) { msg="Получен фокус"; repaint(); return true; } //унаследовано от Applet, а он у java.awt.Component public boolean lostFocus(Event evt, Object arg) { msg="Фокус утерян"; repaint(); return true; } } 
  • Well, about I realized that this is due to inheritance . Thank you - Vikkingg
  • it’s strange that you started java right from the applets, and not the PLO, everything there is swing ... - Gorets
  • @override annotation serves for clarity. - VladD