Java radio buttons 🔘

Sdílet
Vložit
  • čas přidán 23. 08. 2020
  • Java radio button JRadioButton GUI swing tutorial for beginners
    #Java #radio #JRadioButton #button #GUI #swing #tutorial #beginners
    // ***********************************************************************
    public class Main{
    public static void main(String[] args) {
    // JRadioButton = One or more buttons in a grouping in which only 1 may be selected per group
    new MyFrame();
    }
    }
    // ***********************************************************************
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class MyFrame extends JFrame implements ActionListener{
    JRadioButton pizzaButton;
    JRadioButton hamburgerButton;
    JRadioButton hotdogButton;
    ImageIcon pizzaIcon;
    ImageIcon hamburgerIcon;
    ImageIcon hotdogIcon;
    MyFrame(){
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setLayout(new FlowLayout());
    //pizzaIcon = new ImageIcon("pizza.png");
    //hamburgerIcon = new ImageIcon("hamburger.png");
    //hotdogIcon = new ImageIcon("hotdog.png");
    pizzaButton = new JRadioButton("pizza");
    hamburgerButton = new JRadioButton("hamburger");
    hotdogButton = new JRadioButton("hotdog");
    ButtonGroup group = new ButtonGroup();
    group.add(pizzaButton);
    group.add(hamburgerButton);
    group.add(hotdogButton);
    pizzaButton.addActionListener(this);
    hamburgerButton.addActionListener(this);
    hotdogButton.addActionListener(this);
    //pizzaButton.setIcon(pizzaIcon);
    //hamburgerButton.setIcon(hamburgerIcon);
    //hotdogButton.setIcon(hotdogIcon);
    this.add(pizzaButton);
    this.add(hamburgerButton);
    this.add(hotdogButton);
    this.pack();
    this.setVisible(true);
    }
    @Override
    public void actionPerformed(ActionEvent e) {
    if(e.getSource()==pizzaButton) {
    System.out.println("You ordered pizza!");
    }
    else if(e.getSource()==hamburgerButton) {
    System.out.println("You ordered a hamburger!");
    }
    else if(e.getSource()==hotdogButton) {
    System.out.println("You ordered a hotdog!");
    }
    }
    }
  • Věda a technologie

Komentáře • 52

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

    // ***********************************************************************
    public class Main{
    public static void main(String[] args) {

    // JRadioButton = One or more buttons in a grouping in which only 1 may be selected per group

    new MyFrame();
    }
    }
    // ***********************************************************************
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class MyFrame extends JFrame implements ActionListener{
    JRadioButton pizzaButton;
    JRadioButton hamburgerButton;
    JRadioButton hotdogButton;
    //ImageIcon pizzaIcon;
    //ImageIcon hamburgerIcon;
    //ImageIcon hotdogIcon;

    MyFrame(){
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setLayout(new FlowLayout());

    //pizzaIcon = new ImageIcon("pizza.png");
    //hamburgerIcon = new ImageIcon("hamburger.png");
    //hotdogIcon = new ImageIcon("hotdog.png");

    pizzaButton = new JRadioButton("pizza");
    hamburgerButton = new JRadioButton("hamburger");
    hotdogButton = new JRadioButton("hotdog");

    ButtonGroup group = new ButtonGroup();
    group.add(pizzaButton);
    group.add(hamburgerButton);
    group.add(hotdogButton);

    pizzaButton.addActionListener(this);
    hamburgerButton.addActionListener(this);
    hotdogButton.addActionListener(this);

    //pizzaButton.setIcon(pizzaIcon);
    //hamburgerButton.setIcon(hamburgerIcon);
    //hotdogButton.setIcon(hotdogIcon);

    this.add(pizzaButton);
    this.add(hamburgerButton);
    this.add(hotdogButton);
    this.pack();
    this.setVisible(true);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
    if(e.getSource()==pizzaButton) {
    System.out.println("You ordered pizza!");
    }
    else if(e.getSource()==hamburgerButton) {
    System.out.println("You ordered a hamburger!");
    }
    else if(e.getSource()==hotdogButton) {
    System.out.println("You ordered a hotdog!");
    }
    }
    }

  • @aquate9637
    @aquate9637 Před 3 lety +11

    Thanks bro! I feel these videos are the type where they get recommend to everyone in like 10 years from now.

  • @julianep3shen
    @julianep3shen Před 3 lety +17

    Bro, I've been going through your Java GUI series. Your explanations are easy to understand and I appreciate the creative tips. It's just enough to launch your imagination in implementation rather than resulting in dated looking GUIs. Thank you

  • @EnglishVocabularyBooster
    @EnglishVocabularyBooster Před 11 měsíci +2

    It's nice to have such an amazing people that share their knowledge. Thanks a lot!

  • @lykaviabendanillo
    @lykaviabendanillo Před rokem

    OMG, I am so grateful I found your channel! Thank you!

  • @full_disclosure_now5844

    Cool and clear Tutorial!

  • @pavelkvasnicka6856
    @pavelkvasnicka6856 Před rokem +2

    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

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

    So far, this course is amazing

  • @rickr.a2806
    @rickr.a2806 Před 3 lety +4

    You're a savior man. Never stop making videos

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

      thank you for watching Rick! I don't plan on stopping 👍

  • @infotechlab
    @infotechlab Před rokem +1

    good job, Bro! it's really simple to understand your tutorials.

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

    Thanks bro! this course is easy to learn.

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

    thanks bro. man this channel helps me so much

  • @bohdanakachmar6965
    @bohdanakachmar6965 Před rokem +1

    Okay! Cool, it helps me/ Thanks

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

    Nice video

  • @zari_723
    @zari_723 Před rokem

    another great vid

  • @henriquefelinimena3693

    thank you for the content

  • @traveltheworld5241
    @traveltheworld5241 Před rokem +1

    its just funny how I haven't had hiccups since I started this series, almost 8 hours in

  • @ElColombre27360
    @ElColombre27360 Před 3 lety

    thank you!

  • @YTSHANKY
    @YTSHANKY Před 3 lety

    Liked commemted subscribed

  • @insanecodkiller2240
    @insanecodkiller2240 Před rokem

    I was sitting here hopeless thinking I’m failing my exam today this man just saved me and my cousin

  • @ridhoaditya9280
    @ridhoaditya9280 Před 3 lety

    very good video

  • @chennadasari6327
    @chennadasari6327 Před 2 lety

    you are a legend bro

  • @chzzh6634
    @chzzh6634 Před 3 lety

    Thank you bro

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

    Thanks, Bro

  • @kk-gs1dc
    @kk-gs1dc Před rokem

    nice

  • @greeneggsandmushrooms9855

    i ordered them all

  • @shivamthakur1226
    @shivamthakur1226 Před rokem

    🔥🙌

  • @ibrahimylmaz8378
    @ibrahimylmaz8378 Před 2 lety

    thanks bro

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

    Thanks

  • @eilasullivan8930
    @eilasullivan8930 Před 3 lety

    Oh my god “bro code” I get it

  • @jaymob5037
    @jaymob5037 Před 2 lety

    What about resizing the radio buttons, I know you can resize the text with setfont but if you do so, the radio buttons would stay the same size originally

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

    Bro I'm having a problem with icons.
    Can you please tell me from where do you download icon.
    My downloaded icon sizes are too large so they don't fit with my text

  • @YTSHANKY
    @YTSHANKY Před 3 lety

    I am watching

  • @towbeetowbee3124
    @towbeetowbee3124 Před 2 lety

    im trynna wherein sum text just only gonna pop up in the console if you click the submit button(JButton) after you choose an item in a JRadioButton form. is it possible? i dont seem to know.

  • @jianhe
    @jianhe Před 3 lety

    I have problem set RadioIcon. Would it be possible to share your image icon in here. So I can test if it's related to image size issue.

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

    BRO, I add the images just as you did, I made them small enough (40x40) and they for some reason just don't show... this is driving me crazy!!

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

    Can I use all types of images in java like jpg, jpeg, png, etc?

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

      These 3 are supported ones, yeah (I think you already figured it out, so sorry for the late response).

  • @nithinnithu4337
    @nithinnithu4337 Před rokem

    Hi have one question suppose u have to enter some field after clicking radio btn exa:if u click female radio btn u enter name but now u change ur mind and select other btn now the value entered in the female btn i. e., name is not cleared which causes form to not submit so how to clear radio btn field values once u select other btn please please try to clear my question
    Hoping positive response🙂

  • @x_.rimina._.chan._x5244

    it wont work to me ; and how i wright the same code but all in the main !!
    i really hope u answer me soon bc i have an exem in that and i can't wright my project conversion programme

  • @phengeang1382
    @phengeang1382 Před 2 lety

    Bro how to indent the button?

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

    1.9K ...🐌 2K

  • @Man-daragat
    @Man-daragat Před rokem

    pls help my activity
    Using JFrame and 3 RadioButton.Create a java application that will allow user to draw and choose the color they want to use.
    😥

  • @ciaraleannebermudo2623

    can i get a source code ?

  • @Monsta1291
    @Monsta1291 Před 2 lety

    youtube algorithm comment

  • @user-xk9rk6uk1p
    @user-xk9rk6uk1p Před 9 měsíci

    Hi ;(} parent ; don't laugh at me:(). I c u ll why the hate child where I am you were, where you are I will be. (Hint) we all bleed red. Do not let knowledge consume u pray for crk

  • @joyceasante8292
    @joyceasante8292 Před rokem

    Practicing...
    public class Main{
    public static void main(String[] args){
    new MyFrame();
    }
    }
    **********************************
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class MyFrame extends JFrame implements ActionListener
    {
    JRadioButton funkButton;
    JRadioButton soulButton;
    JRadioButton reggaeButton;
    ImageIcon funkIcon;
    ImageIcon soulIcon;
    ImageIcon reggaeIcon;
    MyFrame ()
    {
    this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
    this.setLayout (new FlowLayout ());
    funkIcon = new ImageIcon("funk.png");
    soulIcon = new ImageIcon("soul.png");
    reggaeIcon = new ImageIcon("reggae.png");
    funkButton = new JRadioButton("funk");
    soulButton = new JRadioButton("soul");
    reggaeButton = new JRadioButton("reggae");
    ButtonGroup group = new ButtonGroup();
    group.add(funkButton);
    group.add(soulButton);
    group.add(reggaeButton);
    funkButton.addActionListener(this);
    soulButton.addActionListener(this);
    reggaeButton.addActionListener(this);
    funkButton.setIcon(funkIcon);
    soulButton.setIcon(soulIcon);
    reggaeButton.setIcon(reggaeIcon);
    this.add(funkButton);
    this.add(soulButton);
    this.add(reggaeButton);
    this.pack ();
    this.setVisible (true);
    }
    @Override
    public void actionPerformed (ActionEvent e){
    if(e.getSource()==funkButton){
    System.out.println("Play me some funk music.");
    }
    else if(e.getSource()==soulButton){
    System.out.println("Play me some soul music.");
    }
    else if (e.getSource()==reggaeButton){
    System.out.println("Play me some reggae music.");
    }
    }
    }

  • @x_.rimina._.chan._x5244

    it wont work to me
    and how i wright the same code but all in the main !!
    i really hope u answer me soon bc i have an exem in that and i can't wright my project conversion programme

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

      in the main function you cannot use "this" for the JFrame. You need to create a new JFrame ("JFrame myFrame"), ("myFrame=new JFrame"). Then instead of "this", you write "myFrame".