Java radio buttons 🔘

preview_player
Показать описание
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();

}
}
// ***********************************************************************

public class MyFrame extends JFrame implements ActionListener{

JRadioButton pizzaButton;
JRadioButton hamburgerButton;
JRadioButton hotdogButton;
ImageIcon pizzaIcon;
ImageIcon hamburgerIcon;
ImageIcon hotdogIcon;

MyFrame(){


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

ButtonGroup group = new ButtonGroup();



}

@Override
public void actionPerformed(ActionEvent e) {
}
}
}
}
}
Рекомендации по теме
Комментарии
Автор

//
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.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);









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

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

BroCodez
Автор

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

julianepshen
Автор

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

aquate
Автор

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

EnglishVocabularyBooster
Автор

i was stuck in a problem 1 hour and a half in a single line of code and within 5 minutes you solved it, thanks man

Buebito-con-Bigote
Автор

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

pavelkvasnicka
Автор

You're a savior man. Never stop making videos

rickr.a
Автор

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

lykaviabendanillo
Автор

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

infotechlab
Автор

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

traveltheworld
Автор

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

insanecodkiller
Автор

Thanks bro! this course is easy to learn.

chchong
Автор

thanks bro. man this channel helps me so much

omersond
Автор

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🙂

nithinnithu
Автор

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

nawazkamboo
Автор

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

jaymob
Автор

thank you i have a midterm exam tomorrow 😭😭😭

Faz.
Автор

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

akshaykumarsharma
Автор

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

ottttoooo
Автор

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.

jianhe