tubeshowcase●1,194,391 videosβ™‘ My collection 0
← Learn to Code

Learn to Code11:19

Java anonymous inner class 🎭

Bro Code β†—

From the creator

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(); } } import java.awt.event.*; import javax.swing.*; public class MyFrame extends JFrame{ JButton button1 = new JButton("Button #1"); JButton button2 = new JButton("Button #2"); JButton button3 = new JButton("Button #3"); MyFrame(){ button1.setBounds(100,100,100,100); button2.setBounds(200,100,100,100); button3.setBounds(300,100,100,100); button1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("You pressed button #1"); } }); button2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("You pressed button #2"); } }); button3.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("You pr

Published 2020-06-13 Β· Watch on YouTube β†—
Availability and playback restrictions are controlled by the original channel.

Keep exploring Learn to Code