Java anonymous inner class 🎭

แชร์
ฝัง

ความคิดเห็น • 75

  • @BroCodez
    @BroCodez  4 ปีที่แล้ว +4

    //**************************************************************************************************
    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);
    }
    }

  • @owenagnel4139
    @owenagnel4139 4 ปีที่แล้ว +31

    Great content! Honestly one of the best coding channels out there. Keep up the great vids!

  • @ryan_millard
    @ryan_millard ปีที่แล้ว +4

    I love this guy's tutorials. I've learnt so much from him.

  • @frilledshrimpo3924
    @frilledshrimpo3924 2 ปีที่แล้ว +5

    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!

  • @faizalimuhammadzoda4731
    @faizalimuhammadzoda4731 2 ปีที่แล้ว +6

    Great content! Honestly, one of the best coding channels out there. Keep up the good work.

  • @ramie0n
    @ramie0n 2 ปีที่แล้ว +6

    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.

  • @eugenezuev7349
    @eugenezuev7349 6 หลายเดือนก่อน

    I literally love you for the stuff you've done for us struggling

  • @lynnmyat1661
    @lynnmyat1661 3 ปีที่แล้ว +3

    Bro Code, you are very under-rated. Your tutorial videos are really helpful. Love from Myanmar.

  • @unlockme1424
    @unlockme1424 3 ปีที่แล้ว +3

    Gracias hermano

  • @girl6994
    @girl6994 4 ปีที่แล้ว +7

    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.

    • @wiktorstankiewicz3568
      @wiktorstankiewicz3568 2 ปีที่แล้ว

      didn't hear of that programming language

    • @exx0dus
      @exx0dus ปีที่แล้ว

      @@wiktorstankiewicz3568 xdddd

  • @mateusmachado3744
    @mateusmachado3744 ปีที่แล้ว +1

    The best in YT

  • @expansivegymnast1020
    @expansivegymnast1020 3 ปีที่แล้ว +1

    Excellent video. Thanks for the knowledge.

  • @hyperkarlotheweeb2969
    @hyperkarlotheweeb2969 8 หลายเดือนก่อน

    I am learning so much from you bro, thank you

  • @bentameurmohammedayoub1464
    @bentameurmohammedayoub1464 3 ปีที่แล้ว +2

    thank you bro

  • @wombozombo
    @wombozombo ปีที่แล้ว +1

    I learned something new

  • @dogukan-u2n
    @dogukan-u2n ปีที่แล้ว +1

    Very nice BRO ;)

  • @ramie0n
    @ramie0n 2 ปีที่แล้ว +1

    Keep up!!

  • @NenadCvitan
    @NenadCvitan ปีที่แล้ว +1

    you helped me a lot thank you bro

  • @girl6994
    @girl6994 4 ปีที่แล้ว +2

    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.

    • @BroCodez
      @BroCodez  4 ปีที่แล้ว +1

      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

    • @girl6994
      @girl6994 4 ปีที่แล้ว

      Bro Code thanks! On that course I must try my best to understand it. Because it is really hard to understand.

  • @yasahiroitou1307
    @yasahiroitou1307 ปีที่แล้ว +1

    You're a lifesaver

  • @123cheke
    @123cheke 3 ปีที่แล้ว

    Great Video, you have a new suscriber now. Thanks

  • @honoredegg
    @honoredegg 2 ปีที่แล้ว

    81th. Thank you, ma Bro Sensei

  • @kiruthikas1073
    @kiruthikas1073 3 ปีที่แล้ว

    I am really happy to see ur video as i expected and got what i need ..tqqq so much...

  • @wolanus
    @wolanus 4 ปีที่แล้ว +1

    Thanks. Great explanation!

  • @rafaarteaga5544
    @rafaarteaga5544 3 ปีที่แล้ว

    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 !

  • @JnillCorreia
    @JnillCorreia 3 ปีที่แล้ว +1

    hey Bro, superb lesson!

  • @ShiroVK870
    @ShiroVK870 4 ปีที่แล้ว +2

    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

  • @Dankake23
    @Dankake23 ปีที่แล้ว +1

    Don't know what Jframe is but thank you so much for explaining

  • @ndk8111
    @ndk8111 2 ปีที่แล้ว +1

    And why method name Welcome capitalized? Just to confide beginners?

  • @nawfalnjm5699
    @nawfalnjm5699 3 ปีที่แล้ว

    thank you ! your videos are great !

  • @el-3omda476
    @el-3omda476 7 หลายเดือนก่อน

    Commenting to help BRO

  • @vibingowsic2338
    @vibingowsic2338 6 หลายเดือนก่อน

    Something professional like "yo bro!"😂😂

  • @thiagobrittosouza
    @thiagobrittosouza 3 ปีที่แล้ว

    thats some Good content Bro!

  • @temuryakhyoev5922
    @temuryakhyoev5922 4 ปีที่แล้ว

    niceeeeeeeee and cleannn explanation Bro Code! Thanks a lot!!!!

    • @BroCodez
      @BroCodez  4 ปีที่แล้ว +1

      thanks for watching Temur!

  • @hoangvu8331
    @hoangvu8331 3 ปีที่แล้ว

    Your channel should have got more viewer bro

  • @usamanadeem145
    @usamanadeem145 3 ปีที่แล้ว

    Very helpful bro..!

  • @mahmudulhasan.turjoy
    @mahmudulhasan.turjoy 3 ปีที่แล้ว

    nice tutorial

  • @kemann3815
    @kemann3815 3 ปีที่แล้ว

    Chefs kiss

  • @cbzmemes5297
    @cbzmemes5297 2 ปีที่แล้ว

    thanks for making me pass my OOP exam lol

  • @zari_723
    @zari_723 2 ปีที่แล้ว +1

    Hi!

  • @arqamkhalid5249
    @arqamkhalid5249 3 ปีที่แล้ว

    Thank you so much Bro!!

  • @KVSBharadwajReddy
    @KVSBharadwajReddy 3 หลายเดือนก่อน

    Can anyone help I'm getting an error saying can't find symbol for class MyFrame? 😢

  • @andreajeanbatchelor5142
    @andreajeanbatchelor5142 2 ปีที่แล้ว

    Thank you!

  • @erinemma392
    @erinemma392 3 ปีที่แล้ว

    Thanks

  • @manuelgonzalezpalafox2627
    @manuelgonzalezpalafox2627 2 ปีที่แล้ว +1

    Ly bro 9

  • @ibrahimylmaz8378
    @ibrahimylmaz8378 2 ปีที่แล้ว

    thanks bro

  • @alifallahi7478
    @alifallahi7478 2 ปีที่แล้ว

    thanks bro💛

  • @desmiles1567
    @desmiles1567 3 ปีที่แล้ว

    🤩

  • @cityzenctm3932
    @cityzenctm3932 4 ปีที่แล้ว

    THANK YOU

  • @fillaliziad2702
    @fillaliziad2702 3 ปีที่แล้ว

    thank you

  • @kyleMcBurnett
    @kyleMcBurnett 3 ปีที่แล้ว

    What is and is not in scope in the anonymous inner class?

  • @aliozeir4546
    @aliozeir4546 2 ปีที่แล้ว +1

    i found it thx

  • @angelcastineira2561
    @angelcastineira2561 4 ปีที่แล้ว

    thank you!

  • @Stray0
    @Stray0 3 ปีที่แล้ว

    Aren't methods supposed to be lowercase?

  • @MrLoser-ks2xn
    @MrLoser-ks2xn ปีที่แล้ว

  • @pesterlig
    @pesterlig 4 ปีที่แล้ว +1

    :)

  • @aliozeir4546
    @aliozeir4546 2 ปีที่แล้ว

    where is the code

    • @egorych462
      @egorych462 2 ปีที่แล้ว

      I'm probably too late but it's in the description

  • @babajidesanusi3526
    @babajidesanusi3526 3 ปีที่แล้ว

    Help me, help you

  • @ottttoooo
    @ottttoooo 3 ปีที่แล้ว

    you

    • @ottttoooo
      @ottttoooo 3 ปีที่แล้ว

      @@tngrmngr4665 WAS

    • @ottttoooo
      @ottttoooo 3 ปีที่แล้ว

      @@tngrmngr4665 Was willst du von mir?

    • @ottttoooo
      @ottttoooo 3 ปีที่แล้ว

      @@tngrmngr4665 Ich hab genau so wenig Ahnung wie du

  • @dmt7992
    @dmt7992 3 ปีที่แล้ว

    CHAAD

  • @maxwong1768
    @maxwong1768 2 ปีที่แล้ว

    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 .

  • @MrLoser-ks2xn
    @MrLoser-ks2xn 2 ปีที่แล้ว +1

    Thanks