Results 1 to 3 of 3
Thread: please help
- 01-02-2011, 02:30 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 2
- Rep Power
- 0
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>
*/
}
- 01-02-2011, 02:33 PM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 787
- Rep Power
- 9
getContentPane().add(panelobject);
panelobject is null, because you dont create an object.
--> getContentPane().add(panelobject=new JPanel());
- 01-02-2011, 06:54 PM #3
Member
- Join Date
- Jan 2011
- Posts
- 2
- Rep Power
- 0
Bookmarks