CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Jan 2009
    Posts
    18

    My Applet doesnt initialise on the web page

    I tried embedding my applet in my webpage but it refuses to initialise,i think there's something wrong with my code but i'm having trouble figuring it out.It gives me exceptions like a nullpointer exception.Heres the code including my html code as well

    Code:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.sql.*;
    import java.applet.*;
    
    public class AppForm2 extends Applet implements ActionListener
    {
    
    
    
    JLabel Application_Form, Applying_For, Graduation_Degree_Program, School, Personal_Details, Names,
    First, Middle, Last, Address, City,State, Zip_Code, Phone_Residence, Country, Country_Code1,
    Area_Code1, Phone_Number1, Phone_Office, Country_Code2, Area_Code2, Phone_Number2, Email_Address,
    Gender, Female, Male, Date_of_Birth, Month, Day, Year, Status;
    
    
    
    
    JTextField GradField, SchoolField, FirstField, MiddleField, LastField, AddressField, CityField,
    StateField, ZipCodeField, CountryField, CountryCode1Field, AreaCode1Field, PhoneNumber1Field,
    CountryCode2Field, AreaCode2Field, PhoneNumber2Field, EmailField, MonthField, DayField, YearField;
    
    JButton Continue;
    
    JCheckBox CFemale, CMale;
    
    
    JFrame p1;
    
    Font fo=new Font ("Monospaced", Font.BOLD,16);
    GridBagLayout gbl;
    
    public void init()
    	{
    p1.setTitle("APPLICATION FORM");
    p1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Allow for app to close on command
    
    setSize(760,440);
    
    
    p1=new JFrame();
    p1.getContentPane().setLayout(new BorderLayout());
    gbl=new GridBagLayout();
    GridBagConstraints gbc=new GridBagConstraints();
    p1.setLayout(gbl);
    
    
    gbc.gridx=0;
    gbc.gridy=0;
    gbc.gridwidth=1;
    Application_Form=new JLabel("Application Form");
    p1.add(Application_Form, gbc);
    
    
    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.gridwidth=1;
    gbc.gridheight=1;
    Applying_For = new JLabel("Applying For: ");
    Applying_For.setFont(fo);
    p1.add(Applying_For, gbc);
    
    
    gbc.gridx = 0;
    gbc.gridy = 2;
    gbc.gridwidth=1;
    gbc.gridheight=1;
    Graduation_Degree_Program = new JLabel("Graduation Degree Program: ");
    p1.add(Graduation_Degree_Program, gbc);
    
    
    gbc.gridx = 1;
    gbc.gridy = 2;
    gbc.gridwidth=2;
    GradField=new JTextField(20);
    p1.add(GradField, gbc);
    
    
    gbc.gridx = 0;
    gbc.gridy = 3;
    gbc.gridwidth=1;
    School=new JLabel("School");
    p1.add(School, gbc);
    
    
    gbc.gridx = 1;
    gbc.gridy = 3;
    gbc.gridwidth=2;
    SchoolField=new JTextField(20);
    p1.add(SchoolField, gbc);
    
    
    gbc.gridx = 0;
    gbc.gridy = 4;
    gbc.gridwidth=1;
    Personal_Details=new JLabel("Personal Details: ");
    Personal_Details.setFont(fo);
    p1.add(Personal_Details, gbc);
    
    gbc.gridx = 0;
    gbc.gridy = 5;
    gbc.gridwidth=1;
    Names=new JLabel("Names: ");
    p1.add(Names, gbc);
    
    
    gbc.gridx = 0;
    gbc.gridy = 6;
    gbc.gridwidth=1;
    First = new JLabel("First");
    p1.add(First, gbc);
    
    
    gbc.gridx = 1;
    gbc.gridy = 6;
    gbc.gridwidth=1;
    FirstField = new JTextField(10);
    p1.add(FirstField, gbc);
    
    
    gbc.gridx = 2;
    gbc.gridy = 6;
    gbc.gridwidth=1;
    Middle = new JLabel("Middle");
    p1.add(Middle, gbc);
    
    
    gbc.gridx = 3;
    gbc.gridy = 6;
    gbc.gridwidth=1;
    MiddleField = new JTextField(10);
    p1.add(MiddleField, gbc);
    
    
    gbc.gridx = 4;
    gbc.gridy = 6;
    gbc.gridwidth=1;
    Last = new JLabel("Last");
    p1.add(Last, gbc);
    
    
    gbc.gridx = 5;
    gbc.gridy = 6;
    gbc.gridwidth=1;
    LastField = new JTextField(10);
    p1.add(LastField, gbc);
    
    
    gbc.gridx = 0;
    gbc.gridy = 7;
    gbc.gridwidth=1;
    Address=new JLabel("Address: ");
    p1.add(Address, gbc);
    
    
    gbc.gridx = 1;
    gbc.gridy = 7;
    gbc.gridwidth=5;
    AddressField=new JTextField(50);
    p1.add(AddressField, gbc);
    
    
    gbc.gridx = 0;
    gbc.gridy = 8;
    gbc.gridwidth=1;
    City=new JLabel("City");
    p1.add(City, gbc);
    
    
    gbc.gridx = 1;
    gbc.gridy = 8;
    gbc.gridwidth=1;
    CityField=new JTextField(10);
    p1.add(CityField, gbc);
    
    
    gbc.gridx = 3;
    gbc.gridy = 8;
    gbc.gridwidth=1;
    State=new JLabel("State");
    p1.add(State, gbc);
    
    
    gbc.gridx = 4;
    gbc.gridy = 8;
    gbc.gridwidth=1;
    StateField=new JTextField(10);
    p1.add(StateField, gbc);
    
    
    gbc.gridx = 0;
    gbc.gridy = 9;
    gbc.gridwidth=1;
    Zip_Code=new JLabel("Zip Code");
    p1.add(Zip_Code, gbc);
    
    
    gbc.gridx = 1;
    gbc.gridy = 9;
    gbc.gridwidth=1;
    ZipCodeField=new JTextField(10);
    p1.add(ZipCodeField, gbc);
    
    
    gbc.gridx = 3;
    gbc.gridy = 9;
    gbc.gridwidth=1;
    Country=new JLabel("Country");
    p1.add(Country, gbc);
    
    
    gbc.gridx = 4;
    gbc.gridy = 9;
    gbc.gridwidth=1;
    CountryField=new JTextField(10);
    p1.add(CountryField, gbc);
    
    
    gbc.gridx = 0;
    gbc.gridy = 10;
    gbc.gridwidth=1;
    Phone_Residence=new JLabel("Phone (Residence):");
    p1.add(Phone_Residence, gbc);
    
    
    gbc.gridx = 0;
    gbc.gridy = 11;
    gbc.gridwidth=1;
    Country_Code1=new JLabel("Country Code");
    p1.add(Country_Code1, gbc);
    
    
    gbc.gridx = 1;
    gbc.gridy = 11;
    gbc.gridwidth=1;
    CountryCode1Field=new JTextField(10);
    p1.add(CountryCode1Field, gbc);
    
    
    gbc.gridx = 2;
    gbc.gridy = 11;
    gbc.gridwidth=1;
    Area_Code1=new JLabel("Area Code");
    p1.add(Area_Code1, gbc);
    
    
    gbc.gridx = 3;
    gbc.gridy = 11;
    gbc.gridwidth=1;
    AreaCode1Field=new JTextField(10);
    p1.add(AreaCode1Field, gbc);
    
    
    gbc.gridx = 4;
    gbc.gridy = 11;
    gbc.gridwidth=1;
    Phone_Number1=new JLabel("Phone Number");
    p1.add(Phone_Number1, gbc);
    
    
    gbc.gridx = 5;
    gbc.gridy = 11;
    gbc.gridwidth=1;
    PhoneNumber1Field=new JTextField(10);
    p1.add(PhoneNumber1Field, gbc);
    
    
    gbc.gridx = 0;
    gbc.gridy = 12;
    gbc.gridwidth=1;
    Phone_Office=new JLabel("Phone (Office): ");
    p1.add(Phone_Office, gbc);
    
    
    gbc.gridx = 0;
    gbc.gridy = 13;
    gbc.gridwidth=1;
    Country_Code2=new JLabel("Country Code");
    p1.add(Country_Code2, gbc);
    
    
    gbc.gridx = 1;
    gbc.gridy = 13;
    gbc.gridwidth=1;
    CountryCode2Field=new JTextField(10);
    p1.add(CountryCode2Field, gbc);
    
    
    gbc.gridx = 2;
    gbc.gridy = 13;
    gbc.gridwidth=1;
    Area_Code2=new JLabel("Area Code");
    p1.add(Area_Code2, gbc);
    
    
    gbc.gridx = 3;
    gbc.gridy = 13;
    gbc.gridwidth=1;
    AreaCode2Field=new JTextField(10);
    p1.add(AreaCode2Field, gbc);
    
    
    gbc.gridx = 4;
    gbc.gridy = 13;
    gbc.gridwidth=1;
    Phone_Number2=new JLabel("Phone Number");
    p1.add(Phone_Number2, gbc);
    
    
    gbc.gridx = 5;
    gbc.gridy = 13;
    gbc.gridwidth=1;
    PhoneNumber2Field=new JTextField(10);
    p1.add(PhoneNumber2Field, gbc);
    
    
    gbc.gridx = 0;
    gbc.gridy = 14;
    gbc.gridwidth=1;
    Email_Address=new JLabel("E-mail Address: ");
    p1.add(Email_Address, gbc);
    
    
    gbc.gridx = 1;
    gbc.gridy = 14;
    gbc.gridwidth=1;
    EmailField=new JTextField(10);
    p1.add(EmailField, gbc);
    
    
    gbc.gridx = 0;
    gbc.gridy = 15;
    gbc.gridwidth=1;
    Gender=new JLabel("Gender");
    p1.add(Gender, gbc);
    
    
    gbc.gridx = 2;
    gbc.gridy = 15;
    gbc.gridwidth=1;
    Female=new JLabel("Female");
    p1.add(Female, gbc);
    
    
    gbc.gridx = 3;
    gbc.gridy = 15;
    gbc.gridwidth=1;
    CFemale=new JCheckBox();
    p1.add(CFemale, gbc);
    
    
    gbc.gridx = 4;
    gbc.gridy = 15;
    gbc.gridwidth=1;
    Male=new JLabel("Male");
    p1.add(Male, gbc);
    
    
    gbc.gridx = 5;
    gbc.gridy = 15;
    gbc.gridwidth=1;
    CMale=new JCheckBox();
    p1.add(CMale, gbc);
    
    
    gbc.gridx = 0;
    gbc.gridy = 16;
    gbc.gridwidth=1;
    Date_of_Birth=new JLabel("Date of Birth: ");
    p1.add(Date_of_Birth, gbc);
    
    
    gbc.gridx = 0;
    gbc.gridy = 17;
    gbc.gridwidth=1;
    Month=new JLabel("Month");
    p1.add(Month, gbc);
    
    
    gbc.gridx = 1;
    gbc.gridy = 17;
    gbc.gridwidth=1;
    MonthField=new JTextField(10);
    p1.add(MonthField, gbc);
    
    
    gbc.gridx = 2;
    gbc.gridy = 17;
    gbc.gridwidth=1;
    Day=new JLabel("Day");
    p1.add(Day, gbc);
    
    
    gbc.gridx = 3;
    gbc.gridy = 17;
    gbc.gridwidth=1;
    DayField=new JTextField(10);
    p1.add(DayField, gbc);
    
    
    gbc.gridx = 4;
    gbc.gridy = 17;
    gbc.gridwidth=1;
    Year=new JLabel("Year");
    p1.add(Year, gbc);
    
    
    gbc.gridx = 5;
    gbc.gridy = 17;
    gbc.gridwidth=1;
    YearField=new JTextField(10);
    p1.add(YearField, gbc);
    
    
    gbc.gridx = 0;
    gbc.gridy = 18;
    gbc.gridwidth=4;
    Status=new JLabel("Citizen Status:    U.S. Citizen/U.S. Permanent Resident/Not a U.S. Citizen/Decline to state");
    p1.add(Status, gbc);
    
    
    gbc.gridx = 5;
    gbc.gridy = 19;
    gbc.gridwidth=1;
    Continue=new JButton("Continue");
    Continue.addActionListener(this);
    p1.add(Continue, gbc);
    
    
    p1.getContentPane().add(p1,"North");
    setVisible(true);
    
    	}
    
    
    public void actionPerformed(ActionEvent ae)
    			{
    if(ae.getActionCommand()=="Continue")
    {
    
    
    try
    	{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con=DriverManager.getConnection("jdbc:odbc:MyDataSource","","");
    PreparedStatement stat=con.prepareStatement("INSERT INTO ApplicationForm VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
    String Graduation_Degree_Program = GradField.getText();
    String School=SchoolField.getText();
    String FirstName = FirstField.getText();
    String MiddleName=MiddleField.getText();
    String LastName=LastField.getText();
    String Address=AddressField.getText();
    String City=CityField.getText();
    String State=StateField.getText();
    String ZipCode=ZipCodeField.getText();
    String Country=CountryField.getText();
    String R_C_Code=CountryCode1Field.getText();
    String R_A_Code=AreaCode1Field.getText();
    String R_PhoneNumber=PhoneNumber1Field.getText();
    String O_C_Code=CountryCode2Field.getText();
    String O_A_Code=AreaCode2Field.getText();
    String O_PhoneNumber=PhoneNumber2Field.getText();
    String Email=EmailField.getText();
    String Month=MonthField.getText();
    String Day=DayField.getText();
    String Year=YearField.getText();
    
    stat.setString(1, Graduation_Degree_Program);
    stat.setString(2, School);
    stat.setString(3, FirstName);
    stat.setString(4, MiddleName);
    stat.setString(5, LastName);
    stat.setString(6, Address);
    stat.setString(7, City);
    stat.setString(8, State);
    stat.setString(9, ZipCode);
    stat.setString(10, Country);
    stat.setString(11, R_C_Code);
    stat.setString(12, R_A_Code);
    stat.setString(13, R_PhoneNumber);
    stat.setString(14, O_C_Code);
    stat.setString(15, O_A_Code);
    stat.setString(16, O_PhoneNumber);
    stat.setString(17, Email);
    stat.setString(18, Month);
    stat.setString(19, Day);
    stat.setString(20, Year);
    
    stat.executeUpdate();
    con.close();
    	}
    catch(Exception e)
    		{
    System.out.println("Error: "+e);
    		}
    
    }			
    			}
    
    
    }

    i even tried putting a main method in it but that didnt work,when i used the applet viewer it said the applet was unable to initailise,here is the html code

    Code:
    <html>
    <head><title>LEARNING ON THE WEB</title>
    </head>
    <body>
    <table cellpadding="5" bgcolor="#FF0000">
    <tr>
    <td>
    <APPLET CODE="AppForm2.class" WIDTH="600" HEIGHT="500">
    
    </APPLET></td>
    </tr>
    </table> 
    </body>
    </html>
    and yes they are both in the same directory,please does anybody know to make the applet run,or is there something i'm missing?
    Last edited by seken1; April 19th, 2009 at 06:59 AM.

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: My Applet doesnt initialise on the web page

    1. Please use code tags when posting code.

    2. If your applet throws an exception then post the whole of the exception message and stack trace as that gives a big clue as to what is going wrong.

  3. #3
    Join Date
    Jan 2009
    Posts
    18

    Re: My Applet doesnt initialise on the web page

    sorry to come off as ignorant but what and how do i use code tags?

    plus these are the errors i get when i try to load the page:

    Java Plug-in 1.6.0_11
    Using JRE version 1.6.0_11 Java HotSpot(TM) Client VM
    User home directory = C:\Documents and Settings\USER1
    ----------------------------------------------------
    c: clear console window
    f: finalize objects on finalization queue
    g: garbage collect
    h: display this help message
    l: dump classloader list
    m: print memory usage
    o: trigger logging
    q: hide console
    r: reload policy configuration
    s: dump system and deployment properties
    t: dump thread list
    v: dump thread stack
    x: clear classloader cache
    0-5: set trace level to <n>
    ----------------------------------------------------


    java.lang.NullPointerException
    at AppForm2.init(AppForm2.java:34)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Exception: java.lang.NullPointerException
    java.lang.NullPointerException
    at AppForm2.init(AppForm2.java:36)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Exception: java.lang.NullPointerException
    java.lang.NullPointerException
    at AppForm2.init(AppForm2.java:36)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Exception: java.lang.NullPointerException
    java.lang.NullPointerException
    at AppForm2.init(AppForm2.java:36)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Exception: java.lang.NullPointerException
    java.lang.NullPointerException
    at AppForm2.init(AppForm2.java:36)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Exception: java.lang.NullPointerException
    java.lang.NullPointerException
    at AppForm2.init(AppForm2.java:36)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Exception: java.lang.NullPointerException
    java.lang.NullPointerException
    at AppForm2.init(AppForm2.java:36)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Exception: java.lang.NullPointerException
    java.lang.NullPointerException
    at AppForm2.init(AppForm2.java:36)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Exception: java.lang.NullPointerException
    java.lang.NullPointerException
    at AppForm2.init(AppForm2.java:36)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Exception: java.lang.NullPointerException
    java.lang.NullPointerException
    at AppForm2.init(AppForm2.java:36)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Exception: java.lang.NullPointerException
    java.lang.NullPointerException
    at AppForm2.init(AppForm2.java:36)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Exception: java.lang.NullPointerException

  4. #4
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: My Applet doesnt initialise on the web page

    sorry to come off as ignorant but what and how do i use code tags?
    If you'd read the "before you post' notes you would know
    The easiest way is to highlight the code and click on the 'code' toolbar button.

    The problem with your code is you are trying to use an object that hasn't been created yet, the error is on line 36 (see the exception text). If you look at your code you will see you are setting the frame title but you haven't created the frame object yet - you do that several lines later.

  5. #5
    Join Date
    Jan 2009
    Posts
    18

    Re: My Applet doesnt initialise on the web page

    Thanks,i'll read the "before you post' notes asap,i got the applet to show on my webpage and this is what i did:


    Code:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.sql.*;
    import java.applet.*;
    
    public class AppForm2 extends JApplet implements ActionListener
    {
    
    
    
    JLabel Application_Form, Applying_For, Graduation_Degree_Program, School, Personal_Details, Names,
    First, Middle, Last, Address, City,State, Zip_Code, Phone_Residence, Country, Country_Code1,
    Area_Code1, Phone_Number1, Phone_Office, Country_Code2, Area_Code2, Phone_Number2, Email_Address,
    Gender, Female, Male, Date_of_Birth, Month, Day, Year, Status;
    
    
    
    
    JTextField GradField, SchoolField, FirstField, MiddleField, LastField, AddressField, CityField,
    StateField, ZipCodeField, CountryField, CountryCode1Field, AreaCode1Field, PhoneNumber1Field,
    CountryCode2Field, AreaCode2Field, PhoneNumber2Field, EmailField, MonthField, DayField, YearField;
    
    JButton Continue;
    
    JCheckBox CFemale, CMale;
    
    
    JPanel p1;
    
    Font fo=new Font ("Monospaced", Font.BOLD,16);
    GridBagLayout gbl;
    
    public void init()
    	{
    
    
    p1=new JPanel();
    p1.setLayout(new BorderLayout());
    gbl=new GridBagLayout();
    GridBagConstraints gbc=new GridBagConstraints();
    p1.setLayout(gbl);
    
    
    gbc.gridx=0;
    gbc.gridy=0;
    gbc.gridwidth=1;
    Application_Form=new JLabel("Application Form");
    p1.add(Application_Form, gbc);
    
    
    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.gridwidth=1;
    gbc.gridheight=1;
    Applying_For = new JLabel("Applying For: ");
    Applying_For.setFont(fo);
    p1.add(Applying_For, gbc);
    
    
    gbc.gridx = 0;
    gbc.gridy = 2;
    gbc.gridwidth=1;
    gbc.gridheight=1;
    Graduation_Degree_Program = new JLabel("Graduation Degree Program: ");
    p1.add(Graduation_Degree_Program, gbc);
    
    
    gbc.gridx = 1;
    gbc.gridy = 2;
    gbc.gridwidth=2;
    GradField=new JTextField(20);
    p1.add(GradField, gbc);
    
    
    gbc.gridx = 0;
    gbc.gridy = 3;
    gbc.gridwidth=1;
    School=new JLabel("School");
    p1.add(School, gbc);
    
    
    gbc.gridx = 1;
    gbc.gridy = 3;
    gbc.gridwidth=2;
    SchoolField=new JTextField(20);
    p1.add(SchoolField, gbc);
    
    
    gbc.gridx = 0;
    gbc.gridy = 4;
    gbc.gridwidth=1;
    Personal_Details=new JLabel("Personal Details: ");
    Personal_Details.setFont(fo);
    p1.add(Personal_Details, gbc);
    
    gbc.gridx = 0;
    gbc.gridy = 5;
    gbc.gridwidth=1;
    Names=new JLabel("Names: ");
    p1.add(Names, gbc);
    
    
    gbc.gridx = 0;
    gbc.gridy = 6;
    gbc.gridwidth=1;
    First = new JLabel("First");
    p1.add(First, gbc);
    
    
    gbc.gridx = 1;
    gbc.gridy = 6;
    gbc.gridwidth=1;
    FirstField = new JTextField(10);
    p1.add(FirstField, gbc);
    
    
    gbc.gridx = 2;
    gbc.gridy = 6;
    gbc.gridwidth=1;
    Middle = new JLabel("Middle");
    p1.add(Middle, gbc);
    
    
    gbc.gridx = 3;
    gbc.gridy = 6;
    gbc.gridwidth=1;
    MiddleField = new JTextField(10);
    p1.add(MiddleField, gbc);
    
    
    gbc.gridx = 4;
    gbc.gridy = 6;
    gbc.gridwidth=1;
    Last = new JLabel("Last");
    p1.add(Last, gbc);
    
    
    gbc.gridx = 5;
    gbc.gridy = 6;
    gbc.gridwidth=1;
    LastField = new JTextField(10);
    p1.add(LastField, gbc);
    
    
    gbc.gridx = 0;
    gbc.gridy = 7;
    gbc.gridwidth=1;
    Address=new JLabel("Address: ");
    p1.add(Address, gbc);
    
    
    gbc.gridx = 1;
    gbc.gridy = 7;
    gbc.gridwidth=5;
    AddressField=new JTextField(50);
    p1.add(AddressField, gbc);
    
    
    gbc.gridx = 0;
    gbc.gridy = 8;
    gbc.gridwidth=1;
    City=new JLabel("City");
    p1.add(City, gbc);
    
    
    gbc.gridx = 1;
    gbc.gridy = 8;
    gbc.gridwidth=1;
    CityField=new JTextField(10);
    p1.add(CityField, gbc);
    
    
    gbc.gridx = 3;
    gbc.gridy = 8;
    gbc.gridwidth=1;
    State=new JLabel("State");
    p1.add(State, gbc);
    
    
    gbc.gridx = 4;
    gbc.gridy = 8;
    gbc.gridwidth=1;
    StateField=new JTextField(10);
    p1.add(StateField, gbc);
    
    
    gbc.gridx = 0;
    gbc.gridy = 9;
    gbc.gridwidth=1;
    Zip_Code=new JLabel("Zip Code");
    p1.add(Zip_Code, gbc);
    
    
    gbc.gridx = 1;
    gbc.gridy = 9;
    gbc.gridwidth=1;
    ZipCodeField=new JTextField(10);
    p1.add(ZipCodeField, gbc);
    
    
    gbc.gridx = 3;
    gbc.gridy = 9;
    gbc.gridwidth=1;
    Country=new JLabel("Country");
    p1.add(Country, gbc);
    
    
    gbc.gridx = 4;
    gbc.gridy = 9;
    gbc.gridwidth=1;
    CountryField=new JTextField(10);
    p1.add(CountryField, gbc);
    
    
    gbc.gridx = 0;
    gbc.gridy = 10;
    gbc.gridwidth=1;
    Phone_Residence=new JLabel("Phone (Residence):");
    p1.add(Phone_Residence, gbc);
    
    
    gbc.gridx = 0;
    gbc.gridy = 11;
    gbc.gridwidth=1;
    Country_Code1=new JLabel("Country Code");
    p1.add(Country_Code1, gbc);
    
    
    gbc.gridx = 1;
    gbc.gridy = 11;
    gbc.gridwidth=1;
    CountryCode1Field=new JTextField(10);
    p1.add(CountryCode1Field, gbc);
    
    
    gbc.gridx = 2;
    gbc.gridy = 11;
    gbc.gridwidth=1;
    Area_Code1=new JLabel("Area Code");
    p1.add(Area_Code1, gbc);
    
    
    gbc.gridx = 3;
    gbc.gridy = 11;
    gbc.gridwidth=1;
    AreaCode1Field=new JTextField(10);
    p1.add(AreaCode1Field, gbc);
    
    
    gbc.gridx = 4;
    gbc.gridy = 11;
    gbc.gridwidth=1;
    Phone_Number1=new JLabel("Phone Number");
    p1.add(Phone_Number1, gbc);
    
    
    gbc.gridx = 5;
    gbc.gridy = 11;
    gbc.gridwidth=1;
    PhoneNumber1Field=new JTextField(10);
    p1.add(PhoneNumber1Field, gbc);
    
    
    gbc.gridx = 0;
    gbc.gridy = 12;
    gbc.gridwidth=1;
    Phone_Office=new JLabel("Phone (Office): ");
    p1.add(Phone_Office, gbc);
    
    
    gbc.gridx = 0;
    gbc.gridy = 13;
    gbc.gridwidth=1;
    Country_Code2=new JLabel("Country Code");
    p1.add(Country_Code2, gbc);
    
    
    gbc.gridx = 1;
    gbc.gridy = 13;
    gbc.gridwidth=1;
    CountryCode2Field=new JTextField(10);
    p1.add(CountryCode2Field, gbc);
    
    
    gbc.gridx = 2;
    gbc.gridy = 13;
    gbc.gridwidth=1;
    Area_Code2=new JLabel("Area Code");
    p1.add(Area_Code2, gbc);
    
    
    gbc.gridx = 3;
    gbc.gridy = 13;
    gbc.gridwidth=1;
    AreaCode2Field=new JTextField(10);
    p1.add(AreaCode2Field, gbc);
    
    
    gbc.gridx = 4;
    gbc.gridy = 13;
    gbc.gridwidth=1;
    Phone_Number2=new JLabel("Phone Number");
    p1.add(Phone_Number2, gbc);
    
    
    gbc.gridx = 5;
    gbc.gridy = 13;
    gbc.gridwidth=1;
    PhoneNumber2Field=new JTextField(10);
    p1.add(PhoneNumber2Field, gbc);
    
    
    gbc.gridx = 0;
    gbc.gridy = 14;
    gbc.gridwidth=1;
    Email_Address=new JLabel("E-mail Address: ");
    p1.add(Email_Address, gbc);
    
    
    gbc.gridx = 1;
    gbc.gridy = 14;
    gbc.gridwidth=1;
    EmailField=new JTextField(10);
    p1.add(EmailField, gbc);
    
    
    gbc.gridx = 0;
    gbc.gridy = 15;
    gbc.gridwidth=1;
    Gender=new JLabel("Gender");
    p1.add(Gender, gbc);
    
    
    gbc.gridx = 2;
    gbc.gridy = 15;
    gbc.gridwidth=1;
    Female=new JLabel("Female");
    p1.add(Female, gbc);
    
    
    gbc.gridx = 3;
    gbc.gridy = 15;
    gbc.gridwidth=1;
    CFemale=new JCheckBox();
    p1.add(CFemale, gbc);
    
    
    gbc.gridx = 4;
    gbc.gridy = 15;
    gbc.gridwidth=1;
    Male=new JLabel("Male");
    p1.add(Male, gbc);
    
    
    gbc.gridx = 5;
    gbc.gridy = 15;
    gbc.gridwidth=1;
    CMale=new JCheckBox();
    p1.add(CMale, gbc);
    
    
    gbc.gridx = 0;
    gbc.gridy = 16;
    gbc.gridwidth=1;
    Date_of_Birth=new JLabel("Date of Birth: ");
    p1.add(Date_of_Birth, gbc);
    
    
    gbc.gridx = 0;
    gbc.gridy = 17;
    gbc.gridwidth=1;
    Month=new JLabel("Month");
    p1.add(Month, gbc);
    
    
    gbc.gridx = 1;
    gbc.gridy = 17;
    gbc.gridwidth=1;
    MonthField=new JTextField(10);
    p1.add(MonthField, gbc);
    
    
    gbc.gridx = 2;
    gbc.gridy = 17;
    gbc.gridwidth=1;
    Day=new JLabel("Day");
    p1.add(Day, gbc);
    
    
    gbc.gridx = 3;
    gbc.gridy = 17;
    gbc.gridwidth=1;
    DayField=new JTextField(10);
    p1.add(DayField, gbc);
    
    
    gbc.gridx = 4;
    gbc.gridy = 17;
    gbc.gridwidth=1;
    Year=new JLabel("Year");
    p1.add(Year, gbc);
    
    
    gbc.gridx = 5;
    gbc.gridy = 17;
    gbc.gridwidth=1;
    YearField=new JTextField(10);
    p1.add(YearField, gbc);
    
    
    gbc.gridx = 0;
    gbc.gridy = 18;
    gbc.gridwidth=4;
    Status=new JLabel("Citizen Status:    U.S. Citizen/U.S. Permanent Resident/Not a U.S. Citizen/Decline to state");
    p1.add(Status, gbc);
    
    
    gbc.gridx = 5;
    gbc.gridy = 19;
    gbc.gridwidth=1;
    Continue=new JButton("Continue");
    Continue.addActionListener(this);
    p1.add(Continue, gbc);
    
    add(p1);
    	}
    
    public void actionPerformed(ActionEvent ae)
    			{
    if(ae.getActionCommand()=="Continue")
    {
    
    
    try
    	{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con=DriverManager.getConnection("jdbc:odbc:MyDataSource","","");
    PreparedStatement stat=con.prepareStatement("INSERT INTO ApplicationForm VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
    String Graduation_Degree_Program = GradField.getText();
    String School=SchoolField.getText();
    String FirstName = FirstField.getText();
    String MiddleName=MiddleField.getText();
    String LastName=LastField.getText();
    String Address=AddressField.getText();
    String City=CityField.getText();
    String State=StateField.getText();
    String ZipCode=ZipCodeField.getText();
    String Country=CountryField.getText();
    String R_C_Code=CountryCode1Field.getText();
    String R_A_Code=AreaCode1Field.getText();
    String R_PhoneNumber=PhoneNumber1Field.getText();
    String O_C_Code=CountryCode2Field.getText();
    String O_A_Code=AreaCode2Field.getText();
    String O_PhoneNumber=PhoneNumber2Field.getText();
    String Email=EmailField.getText();
    String Month=MonthField.getText();
    String Day=DayField.getText();
    String Year=YearField.getText();
    
    stat.setString(1, Graduation_Degree_Program);
    stat.setString(2, School);
    stat.setString(3, FirstName);
    stat.setString(4, MiddleName);
    stat.setString(5, LastName);
    stat.setString(6, Address);
    stat.setString(7, City);
    stat.setString(8, State);
    stat.setString(9, ZipCode);
    stat.setString(10, Country);
    stat.setString(11, R_C_Code);
    stat.setString(12, R_A_Code);
    stat.setString(13, R_PhoneNumber);
    stat.setString(14, O_C_Code);
    stat.setString(15, O_A_Code);
    stat.setString(16, O_PhoneNumber);
    stat.setString(17, Email);
    stat.setString(18, Month);
    stat.setString(19, Day);
    stat.setString(20, Year);
    
    stat.executeUpdate();
    con.close();
    	}
    catch(Exception e)
    		{
    System.out.println("Error: "+e);
    		}
    
    }			
    			}
     
    
    
    }
    and my applet showed...but it did not send the information inputed to the database,plus i would like to include code that helps me make the CONTINUE button transfer that page to another page which loads a different applet

    thanks
    Last edited by seken1; April 19th, 2009 at 07:07 AM.

  6. #6
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: My Applet doesnt initialise on the web page

    Thanks,i'll read the "before you post' notes asap,
    Whilst my previous post requesting you use code tags was polite, it didn't mean you should only start to use them when you can be bothered to work out how to do it. It mean't use them from now on.

    If you are not prepared to make the effort to post your code in a way that makes it easier for us to help you then why should we give up our valuable time to help you.

    Also, posting the same monsterous chunk of unformatted code twice won't help you get your post answered either.

  7. #7
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: My Applet doesnt initialise on the web page

    Delete everything BUT the first post, then go into that and highlight your code, and press the CODE icon (in the advanced options)
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  8. #8
    Join Date
    Jan 2009
    Posts
    18

    Re: My Applet doesnt initialise on the web page

    i have corrected my mistake,the truth is i had no idea of what you were talking about when u reffered to "code tags",i didnt realise they were used just like html tags,i was busy looking for a code tag button somewhere,i even started thinking an administrator disabled it(which would have been odd if true)....

    Sorry for the inconvenience. About the applet, i need this first one to send all the details iputed to the database and at the same time make THIS applet disappear and the next one which has a submit button to appear....

    the code for the first applet has already been posted this is the second one

    Code:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.sql.*;
    import java.applet.*;
    
    public class AppForm3 extends JApplet
    {
    JLabel Qualification_Details, Graduation_Degree_Program1, Grade,
    School1, University, GRE_Scores, TestDate, Score,Toefl_Score,
    Details;
    
    JTextField GraduationField, GradeField,SchoolField1,
    UniversityField, GREField, TestDateField, ScoreField,ToeflField;
    
    JTextArea DetailsTA;
    
    JButton Submit;
    
    JPanel pa;
    Font fo1=new Font ("Monospaced", Font.BOLD,16);
    GridBagLayout gbl;
    
    
    public void init()
    {
    
    
    pa=new JPanel();
    pa.setLayout(new BorderLayout());
    gbl=new GridBagLayout();
    GridBagConstraints gbc=new GridBagConstraints();
    pa.setLayout(gbl);
    
    
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.gridwidth=2;
    Qualification_Details = new JLabel("Qualification Details: ");
    Qualification_Details.setFont(fo1);
    pa.add(Qualification_Details, gbc);
    
    
    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.gridwidth=1;
    Graduation_Degree_Program1=new JLabel("Graduation Degree Program: ");
    pa.add(Graduation_Degree_Program1, gbc);
    
    
    gbc.gridx = 1;
    gbc.gridy = 1;
    gbc.gridwidth=2;
    GraduationField=new JTextField(20);
    pa.add(GraduationField, gbc);
    
    
    gbc.gridx = 3;
    gbc.gridy = 1;
    gbc.gridwidth=1;
    Grade=new JLabel("Grade: ");
    pa.add(Grade, gbc);
    
    
    gbc.gridx = 4;
    gbc.gridy = 1;
    gbc.gridwidth=1;
    GradeField=new JTextField(5);
    pa.add(GradeField, gbc);
    
    
    gbc.gridx =0;
    gbc.gridy = 2;
    gbc.gridwidth=1;
    School1=new JLabel("School: ");
    pa.add(School1, gbc);
    
    
    gbc.gridx =1;
    gbc.gridy = 2;
    gbc.gridwidth=2;
    SchoolField1=new JTextField(20);
    pa.add(SchoolField1, gbc);
    
    
    gbc.gridx =3;
    gbc.gridy = 2;
    gbc.gridwidth=1;
    University=new JLabel("University: ");
    pa.add(University, gbc);
    
    
    gbc.gridx =4;
    gbc.gridy = 2;
    gbc.gridwidth=2;
    UniversityField=new JTextField(20);
    pa.add(UniversityField, gbc);
    
    
    gbc.gridx =0;
    gbc.gridy = 3;
    gbc.gridwidth=2;
    GRE_Scores=new JLabel("Graduate Record Examination (GRE) Score: ");
    pa.add(GRE_Scores, gbc);
    
    
    gbc.gridx =2;
    gbc.gridy = 3;
    gbc.gridwidth=1;
    GREField=new JTextField(10);
    pa.add(GREField, gbc);
    
    gbc.gridx =0;
    gbc.gridy = 4;
    gbc.gridwidth=1;
    TestDate=new JLabel("Test Date: ");
    pa.add(TestDate, gbc);
    
    
    gbc.gridx =1;
    gbc.gridy = 4;
    gbc.gridwidth=1;
    TestDateField=new JTextField(10);
    pa.add(TestDateField, gbc);
    
    
    gbc.gridx =2;
    gbc.gridy = 4;
    gbc.gridwidth=1;
    Score=new JLabel("Score: ");
    pa.add(Score, gbc);
    
    
    gbc.gridx =3;
    gbc.gridy = 4;
    gbc.gridwidth=1;
    ScoreField=new JTextField(10);
    pa.add(ScoreField, gbc);
    
    
    gbc.gridx =2;
    gbc.gridy = 4;
    gbc.gridwidth=1;
    Score=new JLabel("Score: ");
    pa.add(Score, gbc);
    
    
    gbc.gridx =0;
    gbc.gridy = 5;
    gbc.gridwidth=1;
    Toefl_Score=new JLabel("TOEFL Score (If required): ");
    pa.add(Toefl_Score, gbc);
    
    
    gbc.gridx =1;
    gbc.gridy = 5;
    gbc.gridwidth=1;
    ToeflField=new JTextField(10);
    pa.add(ToeflField, gbc);
    
    
    gbc.gridx =0;
    gbc.gridy = 6;
    gbc.gridwidth=2;
    Details=new JLabel("Details of Recent Honors and Awards: ");
    pa.add(Details, gbc);
    
    
    gbc.gridx = 2;
    gbc.gridy = 6;
    
    DetailsTA=new JTextArea(5, 30);
    DetailsTA.setLineWrap(true);
    DetailsTA.setWrapStyleWord(true);
    pa.add(DetailsTA, gbc);
    
    
    gbc.gridx = 4;
    gbc.gridy = 6;
    Submit=new JButton("SUBMIT");
    
    pa.add(Submit, gbc);
    
    
    add(pa);
    
    
    
    
    }
    
    
    }
    But this second applet proved unsuccesful,it didnt load.....i cant understand why


    I do hope i have been explicit enough....

    .....awaiting your most valued response (ok....now i'm really asskissing lol)

  9. #9
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: My Applet doesnt initialise on the web page

    The point of the CODE tags (explained in the 'Before you post' notes you said you were going to read), is to keep the correct code indentation. There's no point using them if your code isn't correctly indented in the first place. I suggest you indent the code properly.

    The applet code you posted should load, if the HTML page to load it is correct.

    From a programmer's point of view, the user is a peripheral that types when you issue a read request...
    P. Williams
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  10. #10
    Join Date
    Jan 2009
    Posts
    18

    Re: My Applet doesnt initialise on the web page

    Took me a while to figure out the code tag thing and believe me i tried to look for the "before u post notes" but couldnt find them.I had to search for code tags,anyway....

    .....i dont understand what you mean by my code not being properly indented,please explain


    you were right,i think the problem was from my browser.Any way,looking at the codes can u help me figure out how to get my CONTINUE button to show the second applet while hiding the first one. Thank you in anticipation

  11. #11
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: My Applet doesnt initialise on the web page

    Quote Originally Posted by seken1 View Post
    ... believe me i tried to look for the "before u post notes" but couldnt find them.
    Then why not ask? The link is clearly visible at the top of the thread list: "Announcement: Before you post"...

    .....i dont understand what you mean by my code not being properly indented,please explain
    Oh good grief... try this.

    The outcome of any serious research can only be to make two questions grow where only one grew before...
    T. Veblen
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured