Results 1 to 3 of 3
  1. #1
    robl249 is offline Member
    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0

    Default Absolute beginner with questions

    Could anyone please compile this code and tell me what the errors are about

    Java Code:
    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);
       }
      }
    }
       
    }
    Ideone.com | Online Java Compiler & Debugging Tool
    That link is the compiled code with errors

    Thanks for your time ( remember i'm only new and dont understand the java/programming lingo)

  2. #2
    robl249 is offline Member
    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0

    Default Re: Absolute beginner with questions

    Sorry for the double post guys

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,368
    Blog Entries
    7
    Rep Power
    20

    Default Re: Absolute beginner with questions

    Check your curly brackets; e.g. the left curly bracket at line #100 is incorrect.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Absolute Beginner trying to get one frame, with 2 panels.
    By Atomant2013 in forum New To Java
    Replies: 7
    Last Post: 01-17-2013, 05:18 PM
  2. "Java Programming for the Absolute Beginner"
    By finalstrike777 in forum New To Java
    Replies: 2
    Last Post: 07-12-2011, 12:41 PM
  3. Help an absolute beginner for free...
    By efth in forum New To Java
    Replies: 6
    Last Post: 05-11-2011, 08:11 AM
  4. Advice for first step for absolute beginner
    By FormerBGIuser in forum New To Java
    Replies: 8
    Last Post: 03-07-2011, 10:54 AM
  5. Absolute beginner
    By duff18 in forum New To Java
    Replies: 15
    Last Post: 02-19-2011, 10:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •