import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class PetSurvey extends JFrame
{
public static voind main (string [] args)
{
new PetSurvey () ;
}
JTextField name, phone, address;
JRadioButton cat, dog , fish, oneOrMore , threeOrMore ;
JCheckBox house, bungalow, appartment;
}
Public PetSurvey ()
{
this.setTitle ("Pet Survey");
this.setDefualtCloseOperation (JFrame.EXIT_ON_CLOSE);
JPanel panel = new Jpanel ();
panel1.SetLayout ( new GridBagLayout());
}
{
ButtonListener bl = new ButtonListener ();
AddItem( panel1, new JLabel ("Name"),
0, 0, 1, 1, GridBagConstraints.EAST);
addItem(panel1, new JLabel ("Phone: "),
0, 1, 1, 1, GridBagConstraints.EAST);
addItem(panel1, new JLabel ("Phone: "),
0, 1, 1, 1, GridBagConstraints.EAST);
name = new JTextField (20);
phone = new JTextField(10);
address = new JTextField(20);
addItem(panel1, name, 1, 0, 2, 1, GridBagConstraints.WEST);
addItem(panel1, phone, 1, 1, 1, 1, GridBagConstraints.WEST);
addItem(panel1, address, 1, 2, 2, 1, GridBagConstraints.WEST);
}
{
Box sizeBox = Box.createVerticalBox();
house = new JRadioButton("House");
bungalow = new JRadioButton("bungalow");
appartment = new JRadioButton("Appartment");
ButtonGroup sizeGroup = new ButtonGroup();
sizeGroup.add(house);
sizeGroup.add(bungalow);
sizeGroup.add(apprartment);
}
{
sizeBox.add(house);
sizeBox.add(bungalow);
sizeBox.add(appartment);
sizeBox.setBorder(BorderFactory.createTitledBorder("Select your house"));
addItem(panel1, sizeBox, 0, 3, 1, 1, GridBagConstraints.NORTH);
}
{
Box styleBox = Box.createVerticalBox ();
thin = new JRadioButton("oneOrMore");
thick = new JRadioButton("threeOrMore");
ButtonGroup styleGroup = new ButtonGroup();
}
{
styleGroup.add(oneOrMore);
styleGroup.add(threeOrMore);
styleBox.add(oneOrMore);
styleBox.add(threeOrMore);
styleBox.setBorder(BorderFactory.createTitledBorder ("How many pets do you have"));
addItem(panel1, styleBox, 1, 3, 1, 1, GridBagConstraints.NORTH);
}
{
Box topBox = Box.createVerticalBox();
house = new JCheckBox("House");
bungalow = new JCheckBox("Bungalow");
appartment = new JCheckBox("Appartment");
topBox.add(house);
topBox.add(bungalow);
topBox.add(appartment);
topBox.setBorder(BorderFactory.createTitledBorder("Where do you live"));
addItem(panel1, topBox, 2, 3, 1, 1, GridBagConstraints.NORTH);
Box buttonBox = Box.createHorizontalBox();
okButton = new JButton("OK");
okButton.addActionListener(bl);
String msg = "You ordered a ";
if(small.isSelected()) msg += "xxx ";
if(medium.isSelected()) msg += "xxx";
if (large.isSelected ()) msg += "xxx ";
//String name = name.getText;
if(tops.equals(""))
msg += "you have selected no toppings";
else
msg += "the following toppings:\n "+ tops + base;
JOptionPane.showMessageDialog(okButton, msg, "Your Results!", JOptionPane.INFORMATION_MESSAGE);
house.setSelected(false);
bungalow.setSelected(false);
appartment.setSelected(false);
cat.setSelected(false);
dog.setSelected(true);
fish.setSelected(true);
}
if (e.getSource() == closeButton)
{
System.exit(0);
}
}
}
}
}