Results 1 to 2 of 2
  1. #1
    FermataPlays is offline Member
    Join Date
    Mar 2015
    Posts
    7
    Rep Power
    0

    Exclamation Making a registration form - Lots of errors please help!

    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.Calendar;
    import java.util.Date;
    
    public class Register {
    	public static void makeName() {
    		JTextField nameField = new JTextField(20);
    		nameField.addActionListener(this);
    		// Creates a text field to enter a name.
    	}
    	public static void makeGender() {
    		JRadioButton maleButton = new JRadioButton("Male");
    		JRadioButton femaleButton = new JRadioButton("Female");
    		ButtonGroup genderGroup = new ButtonGroup();
    		genderGroup.add(maleButton);
    		genderGroup.add(femaleButton);
    		// Creates radio buttons for gender, then groups together.
    	}
    	public static void makeAge() {
    
    		int[] ageValues = {};
    		for (int i=0; i<=111; i++) {
    			ageValues[i] = i;
    		}
    		JComboBox ageList = new JComboBox(ageValues);
    		ageList.setSelectedIndex(19);
    		// Creates loop to put values into array. Adds array values to ageList. Selected index set to 19 (value=18).
    	}
    	public static  void makeBday() {
    		SpinnerModel dateModel = new SpinnerDateModel();
    		JSpinner dateSpinner = new JSpinner(dateModel);
    		JLabel dateLabel = new JLabel("Birthdate:");
    		JPanel datePanel = new JPanel(new BorderLayout());
    		datePanel.add(dateSpinner, BorderLayout.CENTER);
    		// Creates dateModel and uses it to create dateSpinner.
    		// dateSpinner placed in datePanel.
    	}
    	public static void makeYes() {
    		JCheckBox yesButton = new JCheckBox("Yes");
    		JCheckBox noButton = new JCheckBox("No");
    		JLabel agreeLabel = new JLabel("Is this an awesome program?");
    		JPanel checkPanel = new JPanel(new GridLayout(0,1));
    		checkPanel.add(agreeLabel);
    		checkPanel.add(yesButton);
    		checkPanel.add(noButton);
    		// Creates label that asks if this is an awesome program.
    		// Creates yes/no checkboxes and adds them to a panel (checkPanel).
    	}
    	public static void addFields() {
    		frame.add(nameField);
    		frame.add(genderGroup);
    		frame.add(ageList);
    		framel.add(datePanel);
    		frame.add(checkPanel);
    		frame.pack();
    		frame.setSize(600,600);
    		// Adds all fields to frame. Sets frame size.
    	}
    	
    	public static void main(String args[]) {
    		JFrame frame = new JFrame("Registration");
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		makeName();
    		makeGender();
    		makeAge();
    		makeBday();
    		makeAgree();
    		addFields();
    		// Makes all fields and adds them to the frame.
    		
    		String name = nameField.getText();
    		String gender;
    		if(maleButton.isSelected()) {
    			String gender = "Male";
    		} else if(femaleButton.isSelected()) {
    			String gender = "Female";
    		}
    		int age = ageList.getSelectedIten();
    		String bday = dateSpinner.getSelectedIten().toString();
    		String awesomeProgram;
    		if(yesButton.isSelected()) {
    			String awesomeProgram = "Yes";
    		} else if(noButton.isSelected()) {
    			String awesomeProgram = "No";
    		}
    		System.out.println("Your Profile");
    		System.out.println("------------");
    		System.out.println("Name: " + name);
    		System.out.println("Gender: " + gender);
    		System.out.println("Age: " + age);
    		System.out.println("Birthdate: " + bday);
    		System.out.println("Is this Program Awesom? " + awesomeProgram);
    	}
    }

    Compiler Errors:
    Java Code:
    C:\Users\Lauren\Dropbox\Schoolwork\9th Grade\Java Programming\Unit 6 - GUI Intro
    duction>javac Register.java
    Register.java:10: error: non-static variable this cannot be referenced from a st
    atic context
                    nameField.addActionListener(this);
                                                ^
    Register.java:27: error: no suitable constructor found for JComboBox(int[])
                    JComboBox ageList = new JComboBox(ageValues);
                                        ^
        constructor JComboBox.JComboBox(ComboBoxModel) is not applicable
          (argument mismatch; int[] cannot be converted to ComboBoxModel)
        constructor JComboBox.JComboBox(Object[]) is not applicable
          (argument mismatch; int[] cannot be converted to Object[])
        constructor JComboBox.JComboBox(Vector) is not applicable
          (argument mismatch; int[] cannot be converted to Vector)
    Register.java:52: error: cannot find symbol
                    frame.add(nameField);
                              ^
      symbol:   variable nameField
      location: class Register
    Register.java:52: error: cannot find symbol
                    frame.add(nameField);
                    ^
      symbol:   variable frame
      location: class Register
    Register.java:53: error: cannot find symbol
                    frame.add(genderGroup);
                              ^
      symbol:   variable genderGroup
      location: class Register
    Register.java:53: error: cannot find symbol
                    frame.add(genderGroup);
                    ^
      symbol:   variable frame
      location: class Register
    Register.java:54: error: cannot find symbol
                    frame.add(ageList);
                              ^
      symbol:   variable ageList
      location: class Register
    Register.java:54: error: cannot find symbol
                    frame.add(ageList);
                    ^
      symbol:   variable frame
      location: class Register
    Register.java:55: error: cannot find symbol
                    framel.add(datePanel);
                               ^
      symbol:   variable datePanel
      location: class Register
    Register.java:55: error: cannot find symbol
                    framel.add(datePanel);
                    ^
      symbol:   variable framel
      location: class Register
    Register.java:56: error: cannot find symbol
                    frame.add(checkPanel);
                              ^
      symbol:   variable checkPanel
      location: class Register
    Register.java:56: error: cannot find symbol
                    frame.add(checkPanel);
                    ^
      symbol:   variable frame
      location: class Register
    Register.java:57: error: cannot find symbol
                    frame.pack();
                    ^
      symbol:   variable frame
      location: class Register
    Register.java:58: error: cannot find symbol
                    frame.setSize(600,600);
                    ^
      symbol:   variable frame
      location: class Register
    Register.java:69: error: cannot find symbol
                    makeAgree();
                    ^
      symbol:   method makeAgree()
      location: class Register
    Register.java:73: error: cannot find symbol
                    String name = nameField.getText();
                                  ^
      symbol:   variable nameField
      location: class Register
    Register.java:75: error: cannot find symbol
                    if(maleButton.isSelected()) {
                       ^
      symbol:   variable maleButton
      location: class Register
    Register.java:76: error: variable gender is already defined in method main(Strin
    g[])
                            String gender = "Male";
                                   ^
    Register.java:77: error: cannot find symbol
                    } else if(femaleButton.isSelected()) {
                              ^
      symbol:   variable femaleButton
      location: class Register
    Register.java:78: error: variable gender is already defined in method main(Strin
    g[])
                            String gender = "Female";
                                   ^
    Register.java:80: error: cannot find symbol
                    int age = ageList.getSelectedIten();
                              ^
      symbol:   variable ageList
      location: class Register
    Register.java:81: error: cannot find symbol
                    String bday = dateSpinner.getSelectedIten().toString();
                                  ^
      symbol:   variable dateSpinner
      location: class Register
    Register.java:83: error: cannot find symbol
                    if(yesButton.isSelected()) {
                       ^
      symbol:   variable yesButton
      location: class Register
    Register.java:84: error: variable awesomeProgram is already defined in method ma
    in(String[])
                            String awesomeProgram = "Yes";
                                   ^
    Register.java:85: error: cannot find symbol
                    } else if(noButton.isSelected()) {
                              ^
      symbol:   variable noButton
      location: class Register
    Register.java:86: error: variable awesomeProgram is already defined in method ma
    in(String[])
                            String awesomeProgram = "No";
                                   ^
    Note: Some messages have been simplified; recompile with -Xdiags:verbose to get
    full output
    26 errors
    
    C:\Users\Lauren\Dropbox\Schoolwork\9th Grade\Java Programming\Unit 6 - GUI Intro
    duction>
    Please help I have to get this finished by today!

  2. #2
    pj6444 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    168
    Rep Power
    7

    Default Re: Making a registration form - Lots of errors please help!

    You have a ton of errors. I would recommend you use an IDE so you can figure out all of them. Nobody is going to do this for you, so you need to figure it out on your own.

Similar Threads

  1. Create registration form | insert into database | call the database
    By FamilyGuy in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 04-23-2012, 11:08 AM
  2. Returning multiple form errors
    By KingdomX in forum New To Java
    Replies: 1
    Last Post: 01-20-2012, 03:23 AM
  3. Replies: 5
    Last Post: 04-16-2010, 01:10 PM
  4. JSP Registration Form error
    By ak88 in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 10-26-2009, 10:54 AM
  5. Duplicate entry in registration form!!!
    By anki1234 in forum Advanced Java
    Replies: 1
    Last Post: 01-04-2008, 08:15 PM

Posting Permissions

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