//************************************************************************************************** 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 is 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");
Your examples are amazing. I Really gotta give you props on how clear and complete you make your explanations. From defining the actual word and giving it some context, providing a simple example, and then showing a use case. It's just top notch work my guy. I wish you the best!
this is really high quality content!!, and your way in explaining the things make them so easy to understand; I was so scary from the inner class for months for now until this video.
In Chinese there is something calls 匿名内部类,匿名对象,means a inner class or object without a name,it is convenient to use it if you want to use it only once a time.which always used to implement interface and override method, and it is very basic knowledge for us to know because if we don’t familiar with it , it will be hard for us to understand lambda expression.
Chinese teachers teaches their students by using very boring examples and it’s make me very hard to remember. And I really don’t know why they don’t teach me anything about Java swing classes such as JFrame or event. Action listeners. Your example is really easy to remember and it’s more interesting. And by the way, button1.addActionListener can be replaced by lambda expression so that it makes code more beautiful and easy to read.
I remember that when I learned android studio , I have learnt something like this : Button btn = (Button) findViewById(R.id.button) ; btn.setOnClickListener(welcome) ;
// Once the onClick event is detected , run the code below . public View.OnClickListener welcome = new View.OnClickListener() { public void onClick(View v) { // code block } } ; I figure out that I can write it in a similar way in eclipse : button1.addActionListener(welcome) ;
public ActionListener welcome = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("Hello") ; } } ; Android studio and the GUI functions similarly . I was confused of that strange structure . Now you let me know that it is anonymous class . Thank you bro . The funny fact is that my tutor teaches me to use the methods (more difficult) mentioned above before teaching us to use implements which is very efficient for handling many buttons .
//**************************************************************************************************
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 is 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 pressed button #3");
}
});
this.add(button1);
this.add(button2);
this.add(button3);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(500, 500);
this.setLayout(null);
this.setVisible(true);
}
}
Great content! Honestly one of the best coding channels out there. Keep up the great vids!
Your examples are amazing. I Really gotta give you props on how clear and complete you make your explanations. From defining the actual word and giving it some context, providing a simple example, and then showing a use case. It's just top notch work my guy. I wish you the best!
I love this guy's tutorials. I've learnt so much from him.
Great content! Honestly, one of the best coding channels out there. Keep up the good work.
this is really high quality content!!, and your way in explaining the things make them so easy to understand; I was so scary from the inner class for months for now until this video.
Gracias hermano
Bro Code, you are very under-rated. Your tutorial videos are really helpful. Love from Myanmar.
I literally love you for the stuff you've done for us struggling
The best in YT
thank you bro
Excellent video. Thanks for the knowledge.
Very nice BRO ;)
I am learning so much from you bro, thank you
In Chinese there is something calls 匿名内部类,匿名对象,means a inner class or object without a name,it is convenient to use it if you want to use it only once a time.which always used to implement interface and override method, and it is very basic knowledge for us to know because if we don’t familiar with it , it will be hard for us to understand lambda expression.
didn't hear of that programming language
@@wiktorstankiewicz3568 xdddd
Great Video, you have a new suscriber now. Thanks
I learned something new
hey Bro, superb lesson!
I am really happy to see ur video as i expected and got what i need ..tqqq so much...
that´s neat bro, I had always done it by typing all that "crap" ( x'DDD) at the beggining, now you enlightened me haha, thanks sr !
Keep up!!
thats some Good content Bro!
81th. Thank you, ma Bro Sensei
You're a lifesaver
you helped me a lot thank you bro
Hey thank you for the Java content Please make video about Arrays and maybe Array.list in while loops so I can print all after the loop its over
Chinese teachers teaches their students by using very boring examples and it’s make me very hard to remember. And I really don’t know why they don’t teach me anything about Java swing classes such as JFrame or event. Action listeners. Your example is really easy to remember and it’s more interesting. And by the way, button1.addActionListener can be replaced by lambda expression so that it makes code more beautiful and easy to read.
That is true. I want to make a video on lambda soon, however it's taking a lot of time because it's difficult to explain
Bro Code thanks! On that course I must try my best to understand it. Because it is really hard to understand.
Your channel should have got more viewer bro
Thanks. Great explanation!
Don't know what Jframe is but thank you so much for explaining
Commenting to help BRO
thank you ! your videos are great !
niceeeeeeeee and cleannn explanation Bro Code! Thanks a lot!!!!
thanks for watching Temur!
Something professional like "yo bro!"😂😂
Very helpful bro..!
And why method name Welcome capitalized? Just to confide beginners?
nice tutorial
thanks for making me pass my OOP exam lol
Chefs kiss
Thank you so much Bro!!
Hi!
Thank you!
thanks bro💛
thanks bro
What is and is not in scope in the anonymous inner class?
Aren't methods supposed to be lowercase?
Can anyone help I'm getting an error saying can't find symbol for class MyFrame? 😢
🤩
Ly bro 9
Thanks
thank you!
i found it thx
thank you
THANK YOU
:)
where is the code
I'm probably too late but it's in the description
Help me, help you
you
@@tngrmngr4665 WAS
@@tngrmngr4665 Was willst du von mir?
@@tngrmngr4665 Ich hab genau so wenig Ahnung wie du
I remember that when I learned android studio , I have learnt something like this :
Button btn = (Button) findViewById(R.id.button) ;
btn.setOnClickListener(welcome) ;
// Once the onClick event is detected , run the code below .
public View.OnClickListener welcome = new View.OnClickListener()
{
public void onClick(View v)
{
// code block
}
} ;
I figure out that I can write it in a similar way in eclipse :
button1.addActionListener(welcome) ;
public ActionListener welcome = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("Hello") ;
}
} ;
Android studio and the GUI functions similarly . I was confused of that strange structure . Now you let me know that it is anonymous class . Thank you bro .
The funny fact is that my tutor teaches me to use the methods (more difficult) mentioned above before teaching us to use implements which is very efficient for handling many buttons .
CHAAD
Thanks