Skip to content

Instantly share code, notes, and snippets.

@uncoded-ro
Created June 14, 2022 07:27
Show Gist options
  • Save uncoded-ro/ccf92e4585a190a3604f4e7bcbf832bf to your computer and use it in GitHub Desktop.
Save uncoded-ro/ccf92e4585a190a3604f4e7bcbf832bf to your computer and use it in GitHub Desktop.
package ro.virtualcampus.gui;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class RadioButtonPanel extends JPanel implements ItemListener {
private static final long serialVersionUID = 1L;
private JRadioButton rb1, rb2, rb3;
private JLabel text1, text2;
private ButtonGroup group;
public RadioButtonPanel() {
setLayout(new GridLayout(5, 1));
text1 = new JLabel("Selecteaza postul TV favorit !");
rb1 = new JRadioButton("Tvr1");
rb1.setActionCommand("Tvr1");
rb2 = new JRadioButton("ProTV");
rb2.setActionCommand("ProTV");
rb3 = new JRadioButton("Antena3");
rb3.setActionCommand("Antena3");
text2 = new JLabel("");
group = new ButtonGroup();
group.add(rb1);
group.add(rb2);
group.add(rb3);
add(text1);
add(rb1);
add(rb2);
add(rb3);
add(text2);
rb1.addItemListener(this);
rb2.addItemListener(this);
rb3.addItemListener(this);
}
public void itemStateChanged(ItemEvent e) {
String choice = group.getSelection().getActionCommand();
text2.setText(choice);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment