Professional Documents
Culture Documents
013 RadioButton
013 RadioButton
// ***********************************************************************
// 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.*;
JRadioButton pizzaButton;
JRadioButton hamburgerButton;
JRadioButton hotdogButton;
ImageIcon pizzaIcon;
ImageIcon hamburgerIcon;
ImageIcon hotdogIcon;
MyFrame()
{
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new FlowLayout());
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!");
}
}
}