filmov
tv
Java anonymous inner class 🎭
![preview_player](https://i.ytimg.com/vi/n2Dpffp_HLc/maxresdefault.jpg)
Показать описание
Java anonymous inner class tutorial
#java #anonymous #class
public class Main {
public static void main(String[] args) {
/*anonymous class = an inner class without a name
only a single object is created from one
The object may have “extras” or "changes"
and no need to create a separate innerclass
when it only need it once.
Helps us to avoid cluttering code with a class name
Syntax is similar to a constructor,
except that there is also a class definition
within a block of code.
GREAT FOR LISTENERS
*/
MyFrame myFrame = new MyFrame();
}
}
public class MyFrame extends JFrame{
JButton button1 = new JButton("Button #1");
JButton button2 = new JButton("Button #2");
JButton button3 = new JButton("Button #3");
MyFrame(){
@Override
public void actionPerformed(ActionEvent e) {
}
});
@Override
public void actionPerformed(ActionEvent e) {
}
});
@Override
public void actionPerformed(ActionEvent e) {
}
});
}
}
#java #anonymous #class
public class Main {
public static void main(String[] args) {
/*anonymous class = an inner class without a name
only a single object is created from one
The object may have “extras” or "changes"
and no need to create a separate innerclass
when it only need it once.
Helps us to avoid cluttering code with a class name
Syntax is similar to a constructor,
except that there is also a class definition
within a block of code.
GREAT FOR LISTENERS
*/
MyFrame myFrame = new MyFrame();
}
}
public class MyFrame extends JFrame{
JButton button1 = new JButton("Button #1");
JButton button2 = new JButton("Button #2");
JButton button3 = new JButton("Button #3");
MyFrame(){
@Override
public void actionPerformed(ActionEvent e) {
}
});
@Override
public void actionPerformed(ActionEvent e) {
}
});
@Override
public void actionPerformed(ActionEvent e) {
}
});
}
}
Комментарии