1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: JAVA: GUI error in JApplet

Discussion in 'Software Development' started by sepala, Jan 24, 2011.

Thread Status:
Not open for further replies.
  1. sepala

    sepala Thread Starter

    Joined:
    May 20, 2010
    Messages:
    4,038
    I have created a form in JAVA, but it is not giving the expected output, seems like Items are here and there. Specially textboxes are too small, even can't see. Please help me to solve this. This is my code.

    Code:
    // Java Document
    import java.awt.*;
    import javax.swing.*;
    
    /*
     <applet code="applications.class" width=600 height=600></applet>
     */
    
    public class applications extends JApplet
    {
        JLabel hApply, hPersonal;
    
        JLabel lProgram, lSchool, lName, lFirstName, lLastName, lMiddleName, lAddress, lCity, lState, lZip, lCountry, lPhone, lCountryCode,     lAreaCode, lPhoneNumber, lPhoneOffice, lCountryCodeOffice, lAreaCodeOffice, lPhoneNumberOffice, lEmail, lGender, lDateOfBirth,                     lMonth, lDay, lYear, lStatus;
    
        JComboBox bProgram, bSchool;
    
        JTextField tFirstName, tMiddleName, tLastName, tCity, tState, tZipCode, tCountry, tCountryCode, tAreaCode, tPhoneNumber,             tCountryCodeOffice, tAreaCodeOffice, tPhoneNumberOffice, tEmail;
    
        JRadioButton rMale, rFemale;
        ButtonGroup group1;
    
        JRadioButton rUS, rPermanent, rNot, rDecline;
        ButtonGroup group2;
    
        JButton button1;
    
        GridBagLayout gbl;
        GridBagConstraints gbc;
    
        public void init()
        {
    
            /*Declaring Labels*/
    
            hApply = new JLabel("Applying For");
            hPersonal = new JLabel("Personal Details");
    
            lProgram = new JLabel("Graduation Degree Program");
            lSchool = new JLabel("School");
    
            lName = new JLabel("Name");
            lFirstName = new JLabel("First Name");
            lMiddleName = new JLabel("Middle Name");
            lLastName = new JLabel("Last Name");
    
            lAddress = new JLabel("Address");
            lCity = new JLabel("City");
            lState = new JLabel("State");
            lZip = new JLabel("Zip Code");
            lCountry = new JLabel("Country");
    
            lPhone = new JLabel("Phone (Residence):");
            lCountryCode = new JLabel("Country Code");
            lAreaCode = new JLabel("Area Code");
            lPhoneNumber = new JLabel("Phone Number");
    
            lPhoneOffice = new JLabel("Phone (Office)");
            lCountryCodeOffice = new JLabel("Country Code ");
            lAreaCodeOffice = new JLabel("Area Code");
            lPhoneNumberOffice = new JLabel("Phone Number");
    
    
            lEmail = new JLabel("Email Address");
    
            lGender = new JLabel("Gender");
    
            lDateOfBirth = new JLabel("Date Of Birth:");
    
            lMonth = new JLabel("Month");
            lDay = new JLabel("Day");
            lYear = new JLabel("Year");
    
            lStatus = new JLabel("Citizenship Status");
    
    
    
            /*Declaring Combo Boxes*/
    
            bProgram = new JComboBox();
            bProgram.addItem("Aeronautics-Astronautics");
            bProgram.addItem("Earth Science");
            bProgram.addItem("Applied Physics");
            bProgram.addItem("Biochemistry");
            bProgram.addItem("Education");
            bProgram.addItem("Humanities and Sciences");
            bProgram.addItem("Engineering and Applied Sciences");
            bProgram.addItem("Architecture");
            bProgram.addItem("Law");
            bProgram.addItem("Nursing");
            bProgram.addItem("Journalism");
    
            bSchool = new JComboBox();
            bSchool.addItem("St.John College");
            bSchool.addItem("James College");
            bSchool.addItem("New Brookers College");
            bSchool.addItem("Bucks College");
            bSchool.addItem("New Bucks College");
            bSchool.addItem("NewLine College");
            bSchool.addItem("Mareen College");
            bSchool.addItem("St.Peters College");
            bSchool.addItem("American College");
            bSchool.addItem("St.Anthony College");
            bSchool.addItem("State City College");
            bSchool.addItem("Science Acadamy College");
            bSchool.addItem("Park College");
            bSchool.addItem("City College");
            bSchool.addItem("Students International College");
            bSchool.addItem("State College");
            bSchool.addItem("Information Acadamy College");
            bSchool.addItem("St.Pauls College");
            bSchool.addItem("United College");
            bSchool.addItem("Global International College");
            bSchool.addItem("New Cineman College");
            bSchool.addItem("GreatLine College");
            bSchool.addItem("Lions Gate College");
            bSchool.addItem("Paramount College");
            bSchool.addItem("Activity College");
    
    
            /*Declaring TextFields*/
    
            tFirstName = new JTextField(5);
            tLastName = new JTextField(5);
            tMiddleName = new JTextField(5);
            tCity = new JTextField(5);
            tState = new JTextField(5);
            tZipCode = new JTextField(5);
            tCountry = new JTextField(5);
            tCountryCode = new JTextField(5);
            tAreaCode = new JTextField(5);
            tPhoneNumber = new JTextField(5);
            tCountryCodeOffice = new JTextField(5);
            tAreaCodeOffice = new JTextField(5);
            tPhoneNumberOffice = new JTextField(5);
            tEmail = new JTextField(5);
    
    
    
            /*Declaring RadioButtons*/
    
            rMale = new JRadioButton("Male");
            rFemale = new JRadioButton("Female");
            group1 = new ButtonGroup();
            group1.add(rMale);
            group1.add(rFemale);
            JPanel rPanel1 = new JPanel();
            rPanel1.setLayout(new FlowLayout());
            rPanel1.add(rMale);
            rPanel1.add(rFemale);
    
    
            rUS = new JRadioButton("U.S.Citizen");
            rPermanent = new JRadioButton("U.S Permanent Recidence");
            rNot = new JRadioButton("Not U.S. Citizen");
            rDecline = new JRadioButton("Decline to State");
            group2 = new ButtonGroup();
            group2.add(rUS);
            group2.add(rPermanent);
            group2.add(rNot);
            group2.add(rDecline);
            JPanel rPanel2 = new JPanel();
            rPanel2.setLayout(new FlowLayout());
            rPanel2.add(rUS);
            rPanel2.add(rPermanent);
            rPanel2.add(rNot);
            rPanel2.add(rDecline);
    
    
            /*Declaring the Buttons*/
            button1 = new JButton("Continue");
    
    
            /*Seting up the Final Window*/
            gbl = new GridBagLayout();
            gbc = new GridBagConstraints();
    
            JPanel panel1 = (JPanel)getContentPane();
            panel1.setLayout(gbl);
    
            gbc.anchor = GridBagConstraints.WEST;
    
               
    
    
                    gbc.gridx = 1;
                    gbc.gridy = 2;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(hApply,gbc);
                    panel1.add(hApply);
    
                    gbc.gridx = 1;
                    gbc.gridy = 3;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(lProgram,gbc);
                    panel1.add(lProgram);
    
                    gbc.gridx = 4;
                    gbc.gridy = 3;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(bProgram,gbc);
                    panel1.add(bProgram);
    
                    gbc.gridx = 1;
                    gbc.gridy = 4;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(lSchool,gbc);
                    panel1.add(lSchool);
    
                    gbc.gridx = 4;
                    gbc.gridy = 4;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(bSchool,gbc);
                    panel1.add(bSchool);
    
                    gbc.gridx = 1;
                    gbc.gridy = 5;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(hPersonal,gbc);
                    panel1.add(hPersonal);
    
                    gbc.gridx = 1;
                    gbc.gridy = 6;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(lName,gbc);
                    panel1.add(lName);
    
                    gbc.gridx = 1;
                    gbc.gridy = 7;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(lFirstName,gbc);
                    panel1.add(lFirstName);
    
                    gbc.gridx = 2;
                    gbc.gridy = 7;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(tFirstName,gbc);
                    panel1.add(tFirstName);
    
                    gbc.gridx = 4;
                    gbc.gridy = 7;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(lMiddleName,gbc);
                    panel1.add(lMiddleName);
    
                    gbc.gridx = 5;
                    gbc.gridy = 7;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(tMiddleName,gbc);
                    panel1.add(tMiddleName);
    
                    gbc.gridx = 8;
                    gbc.gridy = 7;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(lLastName,gbc);
                    panel1.add(lLastName);
    
                    gbc.gridx = 9;
                    gbc.gridy = 7;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(tLastName,gbc);
                    panel1.add(tLastName);
    
                    gbc.gridx = 1;
                    gbc.gridy = 8;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(lAddress,gbc);
                    panel1.add(lAddress);
    
                    gbc.gridx = 1;
                    gbc.gridy = 9;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(lCity,gbc);
                    panel1.add(lCity);
    
                    gbc.gridx = 2;
                    gbc.gridy = 9;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(tCity,gbc);
                    panel1.add(tCity);
    
                    gbc.gridx = 6;
                    gbc.gridy = 9;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(lState,gbc);
                    panel1.add(lState);
    
                    gbc.gridx = 8;
                    gbc.gridy = 9;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(tState,gbc);
                    panel1.add(tState);
    
                    gbc.gridx = 1;
                    gbc.gridy = 10;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(lZip,gbc);
                    panel1.add(lZip);
    
                    gbc.gridx = 2;
                    gbc.gridy = 10;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(tZipCode,gbc);
                    panel1.add(tZipCode);
    
                    gbc.gridx = 6;
                    gbc.gridy = 10;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(lCountry,gbc);
                    panel1.add(lCountry);
    
                    gbc.gridx = 8;
                    gbc.gridy = 10;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(tCountry,gbc);
                    panel1.add(tCountry);
    
                    gbc.gridx = 1;
                    gbc.gridy = 11;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(lPhone,gbc);
                    panel1.add(lPhone);
    
    
                    gbc.gridx = 1;
                    gbc.gridy = 12;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(lCountryCode,gbc);
                    panel1.add(lCountryCode);
    
                    gbc.gridx = 2;
                    gbc.gridy = 12;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(tCountryCode,gbc);
                    panel1.add(tCountryCode);
    
                    gbc.gridx = 3;
                    gbc.gridy = 12;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(lAreaCode,gbc);
                    panel1.add(lAreaCode);
    
                    gbc.gridx = 4;
                    gbc.gridy = 12;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(tAreaCode,gbc);
                    panel1.add(tAreaCode);
    
                    gbc.gridx = 6;
                    gbc.gridy = 12;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(lPhoneNumber,gbc);
                    panel1.add(lPhoneNumber);
    
                    gbc.gridx = 8;
                    gbc.gridy = 12;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(tPhoneNumber,gbc);
                    panel1.add(tPhoneNumber);
    
                    
    
                    gbc.gridx = 1;
                    gbc.gridy = 13;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(lPhoneOffice,gbc);
                    panel1.add(lPhoneOffice);
    
                    gbc.gridx = 1;
                    gbc.gridy = 14;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(lCountryCodeOffice,gbc);
                    panel1.add(lCountryCodeOffice);
    
                    gbc.gridx = 2;
                    gbc.gridy = 14;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(tCountryCodeOffice,gbc);
                    panel1.add(tCountryCodeOffice);
    
                    gbc.gridx = 3;
                    gbc.gridy = 14;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(lAreaCodeOffice,gbc);
                    panel1.add(lAreaCodeOffice);
    
                    gbc.gridx = 4;
                    gbc.gridy = 14;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(tAreaCodeOffice,gbc);
                    panel1.add(tAreaCodeOffice);
    
                    gbc.gridx = 6;
                    gbc.gridy = 14;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(lPhoneNumberOffice,gbc);
                    panel1.add(lPhoneNumberOffice);
    
                    gbc.gridx = 8;
                    gbc.gridy = 14;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(tPhoneNumberOffice,gbc);
                    panel1.add(tPhoneNumberOffice);
    
                    gbc.gridx = 1;
                    gbc.gridy = 15;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(lEmail,gbc);
                    panel1.add(lEmail);
    
                    gbc.gridx = 2;
                    gbc.gridy = 15;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(tEmail,gbc);
                    panel1.add(tEmail);
    
                    gbc.gridx = 1;
                    gbc.gridy = 16;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(lGender,gbc);
                    panel1.add(lGender);
    
                    gbc.gridx = 3;
                    gbc.gridy = 16;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(rPanel1,gbc);
                    panel1.add(rPanel1);
    
                    gbc.gridx = 1;
                    gbc.gridy = 17;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(lDateOfBirth,gbc);
                    panel1.add(lDateOfBirth);
    
                    gbc.gridx = 1;
                    gbc.gridy = 18;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(lMonth,gbc);
                    panel1.add(lMonth);
    
                    gbc.gridx = 3;
                    gbc.gridy = 18;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(lDay,gbc);
                    panel1.add(lDay);
    
                    gbc.gridx = 6;
                    gbc.gridy = 18;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(lYear,gbc);
                    panel1.add(lYear);
    
                    gbc.gridx = 1;
                    gbc.gridy = 19;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(lStatus,gbc);
                    panel1.add(lStatus);
    
                    gbc.gridx = 2;
                    gbc.gridy = 19;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(rPanel2,gbc);
                    panel1.add(rPanel2);
    
                    gbc.gridx = 9;
                    gbc.gridy = 20;
                    gbc.gridwidth= 1;
                    gbc.gridheight = 1;
                    gbl.setConstraints(button1,gbc);
                    panel1.add(button1);
    
    
        }
    
    }
    
    
    
        
    Thanks
     
  2. sepala

    sepala Thread Starter

    Joined:
    May 20, 2010
    Messages:
    4,038
    Managed to solve this by my self. Making this thread solved.
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/976666

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice