//Displaying Radio Buttons in Swing
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SwingRadio extends JFrame
implements ActionListener
{
JRadioButton red,blue,green;
ButtonGroup rgrup;
JLabel lbl;
JPanel p;
public SwingRadio()
{
super("Displaying RadioButton in Swing");
red = new JRadioButton("Red");
blue= new JRadioButton("Magenta");
green=new JRadioButton("Blue");
rgrup = new ButtonGroup();
rgrup.add(red);
rgrup.add(green);
rgrup.add(blue);
lbl=new JLabel("Welcome to My Blog");
p=new JPanel(new GridLayout(0, 1)) ;
red.addActionListener(this);
blue.addActionListener(this);
green.addActionListener(this);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
});
p.add(red);
p.add(blue);
p.add(green);
add(p,BorderLayout.NORTH);
add(lbl,BorderLayout.CENTER);
setSize(150,200);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand().equals("Red"))
lbl.setForeground(Color.red);
else
if (e.getActionCommand().equals("Magenta"))
lbl.setForeground(Color.magenta);
else
lbl.setForeground(Color.blue);
}
public static void main(String kk[])
{
SwingRadio sr=new SwingRadio();
}
}
1 comments:
Very interesting article I feel very enthusiastic while reading and the information.....................Please contact us for Oracle Fusion Financials Training details in our Erptree Training Institute
Post a Comment