Java anonymous inner class 🎭

Поделиться
HTML-код
  • Опубликовано: 1 янв 2025

Комментарии • 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);
    }
    }

  • @ryan_millard
    @ryan_millard Год назад +4

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

  • @owenagnel4139
    @owenagnel4139 4 года назад +31

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

  • @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!

  • @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.

  • @faizalimuhammadzoda4731
    @faizalimuhammadzoda4731 2 года назад +6

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

  • @eugenezuev7349
    @eugenezuev7349 6 месяцев назад

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

  • @unlockme1424
    @unlockme1424 3 года назад +3

    Gracias hermano

  • @lynnmyat1661
    @lynnmyat1661 3 года назад +3

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

  • @expansivegymnast1020
    @expansivegymnast1020 3 года назад +1

    Excellent video. Thanks for the knowledge.

  • @mateusmachado3744
    @mateusmachado3744 Год назад +1

    The best in YT

  • @hyperkarlotheweeb2969
    @hyperkarlotheweeb2969 9 месяцев назад

    I am learning so much from you bro, thank you

  • @bentameurmohammedayoub1464
    @bentameurmohammedayoub1464 3 года назад +2

    thank you bro

  • @dogukan-u2n
    @dogukan-u2n Год назад +1

    Very nice BRO ;)

  • @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.

  • @wombozombo
    @wombozombo Год назад +1

    I learned something new

  • @honoredegg
    @honoredegg 2 года назад

    81th. Thank you, ma Bro Sensei

  • @123cheke
    @123cheke 3 года назад

    Great Video, you have a new suscriber now. Thanks

  • @ramie0n
    @ramie0n 2 года назад +1

    Keep up!!

  • @kiruthikas1073
    @kiruthikas1073 3 года назад

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

  • @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 !

  • @wolanus
    @wolanus 4 года назад +1

    Thanks. Great explanation!

  • @NenadCvitan
    @NenadCvitan Год назад +1

    you helped me a lot thank you bro

  • @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

  • @yasahiroitou1307
    @yasahiroitou1307 Год назад +1

    You're a lifesaver

  • @JnillCorreia
    @JnillCorreia 3 года назад +1

    hey Bro, superb lesson!

  • @nawfalnjm5699
    @nawfalnjm5699 3 года назад

    thank you ! your videos are great !

  • @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!

  • @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.

  • @vibingowsic2338
    @vibingowsic2338 7 месяцев назад

    Something professional like "yo bro!"😂😂

  • @Dankake23
    @Dankake23 Год назад +1

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

  • @el-3omda476
    @el-3omda476 8 месяцев назад

    Commenting to help BRO

  • @mahmudulhasan.turjoy
    @mahmudulhasan.turjoy 3 года назад

    nice tutorial

  • @hoangvu8331
    @hoangvu8331 3 года назад

    Your channel should have got more viewer bro

  • @usamanadeem145
    @usamanadeem145 3 года назад

    Very helpful bro..!

  • @cbzmemes5297
    @cbzmemes5297 2 года назад

    thanks for making me pass my OOP exam lol

  • @kemann3815
    @kemann3815 3 года назад

    Chefs kiss

  • @ndk8111
    @ndk8111 2 года назад +1

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

  • @arqamkhalid5249
    @arqamkhalid5249 3 года назад

    Thank you so much Bro!!

  • @alifallahi7478
    @alifallahi7478 3 года назад

    thanks bro💛

  • @desmiles1567
    @desmiles1567 3 года назад

    🤩

  • @andreajeanbatchelor5142
    @andreajeanbatchelor5142 2 года назад

    Thank you!

  • @ibrahimylmaz8378
    @ibrahimylmaz8378 2 года назад

    thanks bro

  • @zari_723
    @zari_723 2 года назад +1

    Hi!

  • @manuelgonzalezpalafox2627
    @manuelgonzalezpalafox2627 2 года назад +1

    Ly bro 9

  • @erinemma392
    @erinemma392 3 года назад

    Thanks

  • @angelcastineira2561
    @angelcastineira2561 4 года назад

    thank you!

  • @aliozeir4546
    @aliozeir4546 2 года назад +1

    i found it thx

  • @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?

  • @KVSBharadwajReddy
    @KVSBharadwajReddy 4 месяца назад

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

  • @Stray0
    @Stray0 3 года назад

    Aren't methods supposed to be lowercase?

  • @pesterlig
    @pesterlig 4 года назад +1

    :)

  • @MrLoser-ks2xn
    @MrLoser-ks2xn Год назад

  • @aliozeir4546
    @aliozeir4546 2 года назад

    where is the code

    • @egorych462
      @egorych462 2 года назад

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

  • @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 .

  • @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

  • @MrLoser-ks2xn
    @MrLoser-ks2xn 2 года назад +1

    Thanks