Results 1 to 3 of 3

Thread: please help

  1. #1
    aishwary2786 is offline Member
    Join Date
    Jan 2011
    Posts
    2
    Rep Power
    0

    Default please help

    hello sir,
    i am beginner of java programming language and trying to make an event program. but when i compiled it ,it got compiled normally as it should without showing any error.but when i run it ,frame had opened but there were no button or label or text box while i mentioned in program.
    please have a look on coding and please give me possible solution..



    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class customera extends JApplet

    {
    JPanel panelobject;
    JLabel labelcustname;
    JLabel labelcustcellno;
    JLabel labelcustpackage;
    JLabel labelcustage;

    JTextField textcustname;
    JTextField textcustcellno;
    JComboBox combocustpackage;
    JTextField textcustage;
    JButton buttonaccept;

    GridBagLayout gbobject;
    GridBagConstraints gbc;

    public void init()
    {
    gbobject=new GridBagLayout();
    gbc=new GridBagConstraints();
    getContentPane().add(panelobject);
    panelobject.setLayout(gbobject);
    buttonaccept=new JButton("Accept");

    labelcustname=new JLabel("Customer Name");
    labelcustcellno=new JLabel("Customer Cell No");
    labelcustpackage=new JLabel("Package");
    labelcustage=new JLabel("Age");

    textcustname=new JTextField(30);
    textcustcellno=new JTextField(10);
    textcustage=new JTextField(1);
    String packages[]={"Executive","Standerd"};
    combocustpackage=new JComboBox(packages);

    gbc.anchor=GridBagConstraints.NORTHWEST;
    gbc.gridx=1;
    gbc.gridy=5;
    gbobject.setConstraints(labelcustname,gbc);
    panelobject.add(labelcustname);

    gbc.anchor=GridBagConstraints.NORTHWEST;
    gbc.gridx=4;
    gbc.gridy=5;
    gbobject.setConstraints(textcustname,gbc);
    panelobject.add(textcustname);

    gbc.anchor=GridBagConstraints.NORTHWEST;
    gbc.gridx=1;
    gbc.gridy=8;
    gbobject.setConstraints(labelcustcellno,gbc);
    panelobject.add(labelcustcellno);

    gbc.anchor=GridBagConstraints.NORTHWEST;
    gbc.gridx=4;
    gbc.gridy=8;
    gbobject.setConstraints(textcustname,gbc);
    panelobject.add(textcustname);

    gbc.anchor=GridBagConstraints.NORTHWEST;
    gbc.gridx=1;
    gbc.gridy=11;
    gbobject.setConstraints(labelcustpackage,gbc);
    panelobject.add(labelcustpackage);

    gbc.anchor=GridBagConstraints.NORTHWEST;
    gbc.gridx=4;
    gbc.gridy=11;
    gbobject.setConstraints(labelcustname,gbc);
    panelobject.add(labelcustname);

    gbc.anchor=GridBagConstraints.NORTHWEST;
    gbc.gridx=1;
    gbc.gridy=14;
    gbobject.setConstraints(labelcustage,gbc);
    panelobject.add(labelcustage);

    gbc.anchor=GridBagConstraints.NORTHWEST;
    gbc.gridx=4;
    gbc.gridy=14;
    gbobject.setConstraints(textcustname,gbc);
    panelobject.add(textcustname);

    gbc.anchor=GridBagConstraints.NORTHWEST;
    gbc.gridx=5;
    gbc.gridy=17;
    gbobject.setConstraints(buttonaccept,gbc);
    panelobject.add(buttonaccept);

    ValidateAction validatebutton=new ValidateAction();
    buttonaccept.addActionListener(validatebutton);
    }


    class ValidateAction implements ActionListener
    {
    public void actionPerformed(ActionEvent evt)
    {
    Object obj=evt.getSource();
    if(obj==buttonaccept)

    {
    String customercellno=textcustcellno.getText();

    if(customercellno.length()==0)
    {
    getAppletContext().showStatus("Customer cell no can not be empty");
    return;
    }

    else

    {

    String customername=textcustname.getText();
    if(customername.length()==0)
    {
    getAppletContext().showStatus("Customer name can not be empty");
    return;
    }

    else

    {
    String custage=textcustage.getText();
    if(custage.length()==0)
    {
    getAppletContext().showStatus("Customer age can not be empty");
    return;
    }
    else
    {
    int customerage=Integer.parseInt(textcustage.getText() );
    if(customerage <= 0 || customerage >= 100)

    {
    getAppletContext().showStatus("Invalid value for age");
    return;
    }
    getAppletContext().showStatus("");
    }
    }
    }
    }
    }
    }
    /*
    <html>
    <body>
    <applet code="customera.class" height=300 width=300>
    </applet>
    </body>
    </html>
    */
    }

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default

    getContentPane().add(panelobject);
    panelobject is null, because you dont create an object.

    --> getContentPane().add(panelobject=new JPanel());

  3. #3
    aishwary2786 is offline Member
    Join Date
    Jan 2011
    Posts
    2
    Rep Power
    0

    Default thx but i am still suffering with same

    thanks a lot sir ..i tried by making an object ...but i am suffering with same....problem is sill same

Posting Permissions

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