Java buttons 🛎️

Sdílet
Vložit
  • čas přidán 12. 08. 2020
  • Java button JButton GUI swing tutorial for beginners
    #Java #button #JButton #GUI #swing #tutorial #beginners
    Coding boot camps hate him! See how you can teach you to code with this one weird trick...
    Drop a comment down below and subscribe if you'd like to become a fellow bro.
    This is a tutorial channel for beginners to learn how to code.
    A few languages I plan on covering include, but are not limited to:
    Python
    Java
    C#
    C++
    C
    Javascript
    HTML
    CSS
    Django
    MySQL
    and more probably...maybe
    ¯\_(ツ)_/¯
  • Věda a technologie

Komentáře • 185

  • @BroCodez
    @BroCodez  Před 4 lety +99

    //****************************************************
    public class Main{
    public static void main(String[] args) {
    // JButton = a button that performs an action when clicked on

    new MyFrame();
    }
    }
    //****************************************************
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class MyFrame extends JFrame implements ActionListener{
    JButton button;
    JLabel label;

    MyFrame(){

    ImageIcon icon = new ImageIcon("point.png");
    ImageIcon icon2 = new ImageIcon("face.png");

    label = new JLabel();
    label.setIcon(icon2);
    label.setBounds(150, 250, 150, 150);
    label.setVisible(false);

    button = new JButton();
    button.setBounds(100, 100, 250, 100);
    button.addActionListener(this);
    button.setText("I'm a button!");

    button.setFocusable(false);
    button.setIcon(icon);
    button.setHorizontalTextPosition(JButton.CENTER);
    button.setVerticalTextPosition(JButton.BOTTOM);
    button.setFont(new Font("Comic Sans",Font.BOLD,25));
    button.setIconTextGap(-15);
    button.setForeground(Color.cyan);
    button.setBackground(Color.lightGray);
    button.setBorder(BorderFactory.createEtchedBorder());

    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setLayout(null);
    this.setSize(500,500);
    this.setVisible(true);
    this.add(button);
    this.add(label);
    }
    @Override
    public void actionPerformed(ActionEvent e) {
    if(e.getSource()==button) {
    System.out.println("poo");
    button.setEnabled(false);
    label.setVisible(true);
    }
    }
    }
    //****************************************************

    • @keichionizuka
      @keichionizuka Před 3 lety +2

      How to Copy

    • @arijitghosh3358
      @arijitghosh3358 Před 3 lety +1

      @@keichionizuka long press u will see a blue box on that word , now drag till where u want to copy

    • @omar_42
      @omar_42 Před 2 lety +1

      @@keichionizuka shift plus direction buttons

    • @ronnygamerz88
      @ronnygamerz88 Před 2 lety +1

      How add multiple buttions ???

    • @ronnygamerz88
      @ronnygamerz88 Před 2 lety +1

      @@arijitghosh3358 how to add multiple buttion can u plz tell mr

  • @colettekeurentjes1597
    @colettekeurentjes1597 Před 9 měsíci +1

    Thanks for you videos, they are great. You always explain a relatively 'straight to the point' concept but while doing that you touch upon many details and why they work the way they work. They help me loads :)

  • @pavelkvasnicka6856
    @pavelkvasnicka6856 Před rokem

    This is the best Java tutorial for beginners, so you can learn Java and English in one hit. Please keep going! I vote for Java advance tutorial. Thanks a lot Bro

  • @DrinkableWater
    @DrinkableWater Před 3 lety +2

    Always Helpful! Thank you!

  • @ryoma8402
    @ryoma8402 Před 2 lety +51

    You probably won't see this but your videos saved my semester. One of my java projects was a GUI based Sudoku game and there isn't a chance in hell I would have been able to make it without your tutorials on swing components.

  • @danny.3036
    @danny.3036 Před 3 lety +2

    Thanks, Bro! ☕ You're awesome!

  • @soniasmelodiousland
    @soniasmelodiousland Před rokem

    Such a nice video. Really good teaching. Will watch all your videos

  • @helpfulsquid2502
    @helpfulsquid2502 Před 2 lety +2

    Awsome! I wish every tutorial would be like that...

  • @childofhonor
    @childofhonor Před 3 lety +49

    Just started learning how to make a GUI for the first time and these videos have been so helpful!

    • @BroCodez
      @BroCodez  Před 3 lety +7

      thanks for watching bro! I hope they will serve u well

    • @ghasthordegd1201
      @ghasthordegd1201 Před 3 lety +1

      @@BroCodez hey there bro code. i really want to code on mobile. But I can't find a free coding editor for android that will do the import stuff. If there is one, can you give me suggestions?

    • @reubenkiwi
      @reubenkiwi Před 3 lety +1

      @@ghasthordegd1201 I recommend to use your PC or laptop (if you have one) because building GUI on mobile is more difficult (not impossible) than doing it on your computer. There are some great Java IDEs for mobile e.g. AIDE, Dcoder

    • @bruv8668
      @bruv8668 Před 2 lety

      @@ghasthordegd1201 tbh a computer would be 10x better and easier, if you can't afford your own maybe the library will allow you to download a ide? Or a computer cafe?

  • @Garrison86
    @Garrison86 Před rokem +1

    as always, great tutorial 👍👍

  • @orlandohunter2785
    @orlandohunter2785 Před 3 lety +1

    This channel is really good Bro!

  • @millejadecabrera4544
    @millejadecabrera4544 Před 3 lety +1

    It was really helpful for those who don't have no experience in coding

  • @jesusguijarro5192
    @jesusguijarro5192 Před 2 lety +2

    This video was really useful, I was looking how to do visible a lable using the ActionListener, thanks jiji

  • @checkmate8015
    @checkmate8015 Před 3 lety +1

    Very useful stuff bro subscribed!!

  • @Smile-ih5xf
    @Smile-ih5xf Před rokem +3

    I like how it was at the beginning a button called “I’m a butt” which was printing out the word poo.

  • @StriveforGainz
    @StriveforGainz Před rokem

    Keep up the good work Bro Code!!!

  • @techtalk9548
    @techtalk9548 Před 2 lety

    You are a hero!

  • @Amelia-darthmeow
    @Amelia-darthmeow Před 2 lety +2

    These videos are really really great! Thank you so much! :)

  • @lallanyadav8507
    @lallanyadav8507 Před 2 lety

    Literally best tutorial I subbed and liked

  • @jaymob5037
    @jaymob5037 Před 2 lety

    I appreciate your videos man! I hope you dont vanish

  • @ziyahosseini55
    @ziyahosseini55 Před 3 lety +1

    Thank you very much that was useful

  • @maheshbh1
    @maheshbh1 Před 3 lety +1

    You're awesome 😎

  • @user-tz4gf1cd2d
    @user-tz4gf1cd2d Před 2 lety

    I would say i love your videos

  • @elionayzuridasilveira4140
    @elionayzuridasilveira4140 Před měsícem

    Comment dropped here. Thank you!❤

  • @user-zq6yx7of5f
    @user-zq6yx7of5f Před rokem

    Thank you very much!!

  • @andifaimos
    @andifaimos Před 3 lety

    thanks
    adding it to my java presets

  • @alexshepel5599
    @alexshepel5599 Před 3 lety +2

    Nice, bro!

  • @clordz
    @clordz Před 3 lety +2

    Just started uni and started doing an assignment for it. This helped.

    • @BroCodez
      @BroCodez  Před 3 lety

      thanks for watching C Lordz!

  • @Skibbi198
    @Skibbi198 Před rokem

    I love the super oldschool swing look.

  • @optimisticalamin4474
    @optimisticalamin4474 Před 2 lety

    these vedios for learn java so good

  • @aladdinsane581
    @aladdinsane581 Před 3 lety

    thank you!

  • @Simis999
    @Simis999 Před rokem

    ačiū, brolau, labai padėjai! (LT)

  • @maxwong1768
    @maxwong1768 Před 2 lety

    You recall me the lessons about android studio in school . So similar .

  • @eugenezuev7349
    @eugenezuev7349 Před 2 měsíci

    Bro is just the java killa

  • @brogaming796
    @brogaming796 Před 2 lety

    ive been following all your steps in this video, cracked up laughing when i saw that if you set the text in the button "I'm a button" and run the program, the button only contains "I'm a butt..." and when you click it it says poo.. hilarious touch my guy

  • @talk_kurdish
    @talk_kurdish Před rokem

    the best thanks bro

  • @DS-kx1il
    @DS-kx1il Před 11 měsíci

    thank you bro .

  • @strong25
    @strong25 Před rokem

    Thanks bro 💕💕💕💕

  • @MiroZvqra0809
    @MiroZvqra0809 Před 10 měsíci +3

    If for some reason your image is not loading by simply writing its name with ".png", just write the whole terminal name \image.png
    For example:
    C:\Users\User\Desktop\image.png

  • @sigmastudio9853
    @sigmastudio9853 Před rokem

    bro i need to learn mobile app developing with java
    pls do a course regarding that,
    you are teaching gratefully,

  • @Amangupta-rh7cy
    @Amangupta-rh7cy Před 3 lety +2

    Good teaching

    • @BroCodez
      @BroCodez  Před 3 lety

      Thanks for watching Aman!

  • @RohitKumar-jf1dt
    @RohitKumar-jf1dt Před 3 lety

    A good tutorial😎😎

  • @ibrahimylmaz8378
    @ibrahimylmaz8378 Před 2 lety

    thanks bro

  • @gabriellabete617
    @gabriellabete617 Před 3 lety

    thanks a lot

  • @speklex779
    @speklex779 Před 8 měsíci

    nice video

  • @seabass6106
    @seabass6106 Před 3 lety

    Brooo!!! thanks

  • @fiona7651
    @fiona7651 Před 2 lety

    Yooo, this is so cool

  • @YTSHANKY
    @YTSHANKY Před 4 lety +6

    Even i dont like java i watch your videos to help you.. i watch the same video with my 2 accounts.😊😊

    • @BroCodez
      @BroCodez  Před 4 lety +4

      thanks man! You don't have to do that. I do appreciate the views and watch time

    • @YTSHANKY
      @YTSHANKY Před 4 lety +6

      @@BroCodez i know how hard it is to get those 4000 hours watch time.. i wil just play your video in my chrome.. and start my video editing... so benifit for both of us...

    • @BroCodez
      @BroCodez  Před 4 lety +5

      Yeah we actually hit 4000 hours of watchtime already! Took a while, but we made it 😃

    • @YTSHANKY
      @YTSHANKY Před 4 lety

      @@BroCodez bro you indian ?

    • @BroCodez
      @BroCodez  Před 4 lety +3

      no

  • @mirzababarhussain2336
    @mirzababarhussain2336 Před 2 lety +1

    Sir, I want to draw a rectangle at the push of a button. By entering its length and width. So can you make a video on it? Or can you send me the code?

  • @kemann3815
    @kemann3815 Před 2 lety

    Awesome

  • @MrLoser-ks2xn
    @MrLoser-ks2xn Před 2 lety

    Thanks

  • @sforsuraj7255
    @sforsuraj7255 Před 8 měsíci

    I wanted to add new game button after game over in snake game designed by you.
    I am trying but not able to get the logic.
    Can you make a video on it ???
    Your videos are gems for non IT students.

  • @jonathanlee4653
    @jonathanlee4653 Před 3 lety +1

    Awesome tutorial, by the way at around 1:38, how did you quickly shortcut those lines of code in? cheers

    • @DemHP.
      @DemHP. Před 3 lety +3

      I think he just had them copied before hand for the vid. If he didn't however I'd love to know this too.

  • @chiruvlogss
    @chiruvlogss Před 2 lety

    thanks

  • @jowyli4362
    @jowyli4362 Před 3 lety +2

    Hey Bro nice Video
    Can you help me pls?
    I can't put a picture in it.
    How does it work?

  • @ShrihariNBhat
    @ShrihariNBhat Před 3 lety

    The best

  • @soumelee5661
    @soumelee5661 Před rokem

    that was a lot of new things

  • @catherinepaiva988
    @catherinepaiva988 Před 3 lety

    thanksss!!!

    • @BroCodez
      @BroCodez  Před 3 lety +1

      thanks for watching Catherine!

  • @s404pain
    @s404pain Před 5 měsíci

    can you do Tutorials with Intellij or do you only use eclipse?

  • @markgimarangan8344
    @markgimarangan8344 Před rokem

    Hi sir, can you make a short video, example you have button in your first class and in the second class you also have button, if you want to disabled/enabled button in your second class you need to go in first class to click the button in the first class to disabled/enabled the button in second class. in Java swing eclipse I hope you notice me its really important.

  • @xyphyblack5585
    @xyphyblack5585 Před 3 lety

    cool bro

  • @letsthinkit
    @letsthinkit Před 3 lety +2

    How would we make round buttons in java?

  • @kingkock1
    @kingkock1 Před 2 lety

    too cool for skool

  • @mojeebullahazami2676
    @mojeebullahazami2676 Před 3 lety +3

    Bro , Make a video How to build a calculator using java :)

    • @BroCodez
      @BroCodez  Před 3 lety +1

      Got one right here:
      czcams.com/video/dfhmTyRTCSQ/video.html&ab_channel=BroCode

  • @karljanssendeguzman3107

    Hey bro, I have a question. Is it ok to implement an encapsulation to GUI like in Jbuttons?

  • @HarryPotter-bd2qb
    @HarryPotter-bd2qb Před 3 lety

    Bro,need ya help man.
    Imma currently developing a quiz app, I need to fix a 15 second timer to click the button.If time ends automatic transfer to next frame.

  • @bomapdich
    @bomapdich Před rokem

    If I didn't set the button in a different class. Instead of this, what can I put in as an argument for the addActionListener()?

  • @Sorjen108
    @Sorjen108 Před 2 lety

    Hello Bro Code
    I was wondering, is there a way of displaying the text on the button, on the icon itself? The text on my button disappeared as soon as I inserted an image(icon)
    Thank you

  • @swampus2016
    @swampus2016 Před 2 lety

    "Because
    we can
    ~~Bro Code, 2021

  • @robertdraxel7175
    @robertdraxel7175 Před 3 lety

    Just a thought. I'm watching these tutorials and I think that is a lot of work to fit all those elements into the frame by coding, coding is about logic, not beauty of a gui, aren't there IDE 's or app dev environments that let you insert buttons where you want and add features as you like by dragging them easily and the underlying code will be generated? I know there is Xamarin in C# for Android, what about environments for JAVA? Thanks.

    • @johnconnor2626
      @johnconnor2626 Před 2 lety +2

      You can start with Processing. It's a java based IDE for exactly this.

    • @robertdraxel7175
      @robertdraxel7175 Před 2 lety

      @@johnconnor2626 thank you very much

    • @7_ajinkya
      @7_ajinkya Před 2 lety

      man just install Java Window Builder in your IDE. It's available in Visual Studio by default. For Eclipse you'll need to install it separately. Saves hell lot of time

  • @peterwheler7005
    @peterwheler7005 Před 7 měsíci

    Hi Bro Code
    where do you get your emoji images from?

  • @geocojonnrigor
    @geocojonnrigor Před rokem

    Bro where do you get those Icons?

  • @noahbarbot2976
    @noahbarbot2976 Před rokem

    OOOGA BOOOGA BIG BRAIN

  • @arijitghosh3358
    @arijitghosh3358 Před 3 lety

    sir how can we assume the size and location in pixel without any measurement?

  • @user-rl1gz4ew8j
    @user-rl1gz4ew8j Před 2 lety

    nice video bro!
    help me

  • @draft_fusion
    @draft_fusion Před 6 měsíci

    Why is it that everyone makes a new class when making a JFrame? Am I missing out on something?

  • @peter00000
    @peter00000 Před 3 lety +2

    How to only increase size of content in jubutton.

  • @alexbalan681
    @alexbalan681 Před 2 lety

    How can I make more buttons? I am creating button2, but it only shows the first button

  • @Quidoute
    @Quidoute Před 3 lety

    this guy: making a button class
    javaScript devs : LOL let button = document.createElement('button');

  • @tib8569
    @tib8569 Před 2 lety

    Is it posible to change the position of a button without using setBounds()? I ve been trying to do it with all the setAlignments functions but i failed. I also tried searching it up on google but nothing worked.

  • @asemshaat6672
    @asemshaat6672 Před 3 lety

    Hey bro, the setBorder method didn't work with me
    Do you have an idea why

  • @MinhLe-qp1lo
    @MinhLe-qp1lo Před rokem

    what the "This" key word in addActionListener(this) actually is? Is it the MyFrame Obj or what

  • @javokhirs5478
    @javokhirs5478 Před 3 lety

    👍👍👍👍

  • @mohammedAli7106
    @mohammedAli7106 Před 11 měsíci

    Next Chat app please sir❤❤❤❤

  • @jaymob5037
    @jaymob5037 Před 2 lety

    can you smooth the edges?

  • @floogle355
    @floogle355 Před rokem

    The this.set... is not getting recognized. Someone help me

  • @TheFanfan7
    @TheFanfan7 Před 2 lety

    hello how to fit the JButton with the JPanel in X AXIS
    ??

  • @soltan4566
    @soltan4566 Před 2 lety

    Hi bro
    Can these codes be run inside Android Studio?
    Doesn't it matter ?? !!!!

  • @rakibulislamrakib856
    @rakibulislamrakib856 Před 2 lety

    How can I create two buttons ?

  • @rodmcmahon4829
    @rodmcmahon4829 Před rokem

    Using your code to learn from. but in buttons/labels etc I cannot get a dude.png file to show. Loaded using import/File System
    Any idea why?
    Great tutorials by the way

    • @hananokashipl9549
      @hananokashipl9549 Před rokem

      For my work when i click right icon and click "copy path/reference" and copy long text where my icon find.

  • @raihanrony1810
    @raihanrony1810 Před 3 lety

    im using geany on Linux mint
    It's throwing an error on public void actionPerformed(ActionEvent e) ... it doesn't recognize ActionEvent.. how can I fix it ??
    (Edit) had to import java.awt.event.*;

  • @mozd1729
    @mozd1729 Před 2 lety

    My button is taking up the space of my whole JFrame. Why?

  • @LikeLexor
    @LikeLexor Před 3 lety

    Dude I

  • @muzamilzaman7463
    @muzamilzaman7463 Před rokem

    Can we make app with this Java code in Android studio

  • @jobincjesty9638
    @jobincjesty9638 Před 3 lety

    Hey bro, I'm not able to get my icon on jbutton can you please help me out

  • @ifti3124
    @ifti3124 Před 2 lety

    Bro i am having a problem with button overrider if i text
    @Override
    public void actionPerformed(ActionEvent e) {
    if(e.getSource()==button) {
    System.out.println("Poo");
    }
    my sys that dosent outputs poo

  • @marcosdidierdrogbachagaslo286

    how can i do it, no using a subclasse ?

  • @colonelh.s.l.3834
    @colonelh.s.l.3834 Před rokem

    Is there a way to return a boolean of whether or not a button is clicked??

    • @MajorMonogram
      @MajorMonogram Před rokem

      You mean something like:
      boolean isClicked = button.isClicked()?
      If so that would make no sense because the use of a button is to recieve a click/hover/... event. Not an action over time!

  • @tngflash2814
    @tngflash2814 Před 3 lety

    Why does my button take up the whole screennnnnn?!?!?!?!

  • @dhanushetty2908
    @dhanushetty2908 Před 10 dny

    I have a problem when i click the button it wont work means action does not perform anything can u please give a solution for this problem 😢