fork download
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;



    public class PetSurvey extends JFrame
{
    public static void 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.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
      JPanel panel = new JPanel ();
      panel.SetLayout ( new GridBagLayout());
      
   


  ButtonListener bl = new ButtonListener ();
      
      addItem(panel, new JLabel ("Name"),
              0, 0, 1, 1, GridBagConstraints.EAST);
     addItem(panel, new JLabel ("Phone: "), 
              0, 1, 1, 1, GridBagConstraints.EAST);
        name = new JTextField (20);
       phone = new JTextField(10);
        
        
      addItem(panel, name, 1, 0, 2, 1, GridBagConstraints.WEST);
        addItem(panel, phone, 1, 1, 1, 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);                        //Adding buttons to button group
 sizeGroup.add(bungalow);
 sizeGroup.add(appartment);
 

 sizeBox.add(house);
 sizeBox.add(bungalow);
 sizeBox.add(appartment);
 sizeBox.setBorder(BorderFactory.createTitledBorder("Select your house"));
 addItem(panel, sizeBox, 0, 3, 1, 1, GridBagConstraints.NORTH);
 


 Box styleBox = Box.createVerticalBox ();
 oneOrMore = new JRadioButton("oneOrMore");
threeOrMore = 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(panel, 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(panel, topBox, 2, 3, 1, 1,  GridBagConstraints.NORTH);
 Box buttonBox = Box.createHorizontalBox();
     okButton = new JButton("OK");
     okButton.addActionListener(bl);
 
 closeButton = new JButton ("Close");
 closeButton.addActionListener(bl);

 buttonBox.add(okButton);
 buttonBox.add(Box.createHorizontalStrut (20));
 buttonBox.add(closeButton);
 addItem(panel1, buttonBox, 2, 4, 1, 1, GridBagConstraints.NORTH);
 this.add(panel1);
  this.pack ();
 this.setVisible(true);
 
 {
 private void addItem(JPanel p, JComponent c, int x, int y, int width, int height, int align)
 }
 
 GridBagConstraints gc = new GridBagConstraints ();
 gc.gridx = x;
 gc.gridy = y;
 gc.gridwidth = width;
 gc.gridheight = height;
 gc.weightx  = 100.0;
 gc.weighty = 100.0;
 gc.insets = new Insets (5, 5, 5, 5);
 gc.anchor = align;
 gc.fill = GridBagConstraints.NONE;
 p.add(c, gc);
 }
 
 private class ButtonListener implements ActionListener

  {
  public void actionPerformed(ActionEvent e)
  {
   if (e.getSource() == okButton)
   {
   
       String tops = "" ;
   if (house.isSelected()) tops +="House\n";
   if (bungalow.isSelected()) tops += "Bungalow \n";
   if (appartment.isSelected()) tops += "Appartment\n";
   
    String base = " your base type is ";
   if (oneOrMore.isSelected()) base += "OneOrMore";
   if(threeOrMore.isSelected()) base += "ThreeOrMore";
   
   String msg = "You ordered a ";
   if(small.isSelected()) msg += "...";
   if(medium.isSelected()) msg += "...";
   if (large.isSelected ()) msg += "...";

   
                                                         //String name = name.getText;
   
   if(tops.equals(""))
   
   msg += "you have no pets";
   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);
   }
  }
}
   
}





Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:101: error: illegal start of expression
 private void addItem(JPanel p, JComponent c, int x, int y, int width, int height, int align)
 ^
Main.java:101: error: illegal start of expression
 private void addItem(JPanel p, JComponent c, int x, int y, int width, int height, int align)
         ^
Main.java:101: error: ';' expected
 private void addItem(JPanel p, JComponent c, int x, int y, int width, int height, int align)
                     ^
Main.java:101: error: ';' expected
 private void addItem(JPanel p, JComponent c, int x, int y, int width, int height, int align)
                                          ^
Main.java:101: error: not a statement
 private void addItem(JPanel p, JComponent c, int x, int y, int width, int height, int align)
                                           ^
Main.java:101: error: ';' expected
 private void addItem(JPanel p, JComponent c, int x, int y, int width, int height, int align)
                                            ^
Main.java:101: error: <identifier> expected
 private void addItem(JPanel p, JComponent c, int x, int y, int width, int height, int align)
                                                    ^
Main.java:101: error: not a statement
 private void addItem(JPanel p, JComponent c, int x, int y, int width, int height, int align)
                                                         ^
Main.java:101: error: ';' expected
 private void addItem(JPanel p, JComponent c, int x, int y, int width, int height, int align)
                                                          ^
Main.java:101: error: <identifier> expected
 private void addItem(JPanel p, JComponent c, int x, int y, int width, int height, int align)
                                                                      ^
Main.java:101: error: not a statement
 private void addItem(JPanel p, JComponent c, int x, int y, int width, int height, int align)
                                                                           ^
Main.java:101: error: ';' expected
 private void addItem(JPanel p, JComponent c, int x, int y, int width, int height, int align)
                                                                                 ^
Main.java:101: error: ';' expected
 private void addItem(JPanel p, JComponent c, int x, int y, int width, int height, int align)
                                                                                            ^
13 errors
stdout

Standard output is empty