Forums don't work that way. Post code using the code tags ([code][/code]. Also post a full description of your problem. Plus any error messages you get.
Please, before dumping a shitload of unformatted **** on the forum take a read of:
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.physci.org/codes/sscce/
import javax.swing.*;
import java.awt.*;
import java.sql.*;
import java.awt.event.*;
import java.applet.*;
public class client extends JApplet implements ActionListener
{
//Labels
JFrame frame;
JPanel panel;
JLabel username;
JButton check;
JLabel password;
JLabel Lconfpassword;
JLabel Lfname;
JLabel Llname;
JLabel Lmname;
JLabel Lemail;
JLabel Laddress;
JLabel Lcity;
JLabel Lstate;
JLabel Lcellno;
JLabel Lstdcode;
JLabel Lphoneno;
JLabel Lpqualification;
JLabel Lugraduate;
JLabel Lkeywords;
JLabel Lresume;
//Text Areas
JTextField Tusername;
JPasswordField Tpassword;
JPasswordField Tconfpassword;
JTextField Tfname;
JTextField Tlname;
JTextField Tmname;
JTextField Temail;
JTextField Taddress;
JTextField Tcity;
JTextField Tstate;
JTextField Tcellno;
JTextField Tstdcode;
JTextField Tphoneno;
JComboBox chighestqualification;
JComboBox cugraduate;
JTextField Tkeywords;
JTextArea Tresume;
JButton submit;
JButton refresh;
String[] pqual={"Select","Ph.d","MBA","MCA","M.Tech","M.Sc","M.Com","M.A","PG/Diploma","others"};
String[] uqual={"select","B.Tech","B.A","B.Com","B.Sc","others"};
public static void main(String args[])
{
new client();
}
public client()
{
panel=new JPanel();
frame=new JFrame("Candidate Registration");
frame.setSize(350,350);
frame.setVisible(true);
frame.getContentPane().add(panel);
username=new JLabel("User Name");
password=new JLabel("Password");
Lconfpassword=new JLabel("Confirm Password");
Lfname=new JLabel("First Name");
Lmname=new JLabel("Middle Name");
Llname=new JLabel("Last Name");
Lemail=new JLabel("E-Mail");
Laddress=new JLabel("Address");
Lcity=new JLabel("City");
Lstate=new JLabel("State");
Lcellno=new JLabel("Cell Number");
Lstdcode=new JLabel("STD code");
Lphoneno=new JLabel("LandLine");
Lpqualification=new JLabel("PG");
Lugraduate=new JLabel("UG");
Lkeywords=new JLabel("Keywords");
Lresume=new JLabel("Resume");
Tusername=new JTextField(20);
Tpassword=new JPasswordField(20);
Tconfpassword=new JPasswordField(20);
Tfname=new JTextField(20);
Tlname=new JTextField(20);
Tmname=new JTextField(20);
Temail=new JTextField(20);
Taddress=new JTextField(50);
Tcity=new JTextField(20);
Tstate=new JTextField(20);
Tcellno=new JTextField(15);
Tstdcode=new JTextField(10);
Tphoneno=new JTextField(20);
chighestqualification=new JComboBox(pqual);
cugraduate=new JComboBox(uqual);
Tkeywords=new JTextField(35);
Tresume=new JTextArea(10,10);
submit=new JButton("Submit");
refresh=new JButton("Refresh");
check=new JButton("Check Avialability");
submit.addActionListener(this);
refresh.addActionListener(this);
char[] input = Tpassword.getPassword();
panel.setLayout(new GridLayout(25,10,-5,-5));
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
panel.setLayout(gridbag);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 5;
gridbag.setConstraints(username,gbc);
panel.add(username);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 5;
gridbag.setConstraints(Tusername,gbc);
panel.add(Tusername);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 10;
gbc.gridy = 5;
gridbag.setConstraints(check,gbc);
panel.add(check);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 10;
gbc.fill = GridBagConstraints.HORIZONTAL;//changed to vertical from hori
gridbag.setConstraints(password,gbc);
panel.add(password);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 10;
gridbag.setConstraints(Tpassword,gbc);
panel.add(Tpassword);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 14;
gridbag.setConstraints(Lconfpassword,gbc);
panel.add(Lconfpassword);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 14;
gridbag.setConstraints(Tconfpassword,gbc);
panel.add(Tconfpassword);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 18;
gridbag.setConstraints(Lfname,gbc);
panel.add(Lfname);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 18;
gridbag.setConstraints(Tfname,gbc);
panel.add(Tfname);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 22;
gridbag.setConstraints(Lmname,gbc);
panel.add(Lmname);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 22;
gridbag.setConstraints(Tmname,gbc);
panel.add(Tmname);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 26;
gridbag.setConstraints(Llname,gbc);
panel.add(Llname);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 26;
gridbag.setConstraints(Tlname,gbc);
panel.add(Tlname);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 30;
gridbag.setConstraints(Lemail,gbc);
panel.add(Lemail);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 30;
gridbag.setConstraints(Temail,gbc);
panel.add(Temail);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 34;
gridbag.setConstraints(Laddress,gbc);
panel.add(Laddress);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 34;
gridbag.setConstraints(Taddress,gbc);
panel.add(Taddress);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 38;
gridbag.setConstraints(Lcity,gbc);
panel.add(Lcity);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 38;
gridbag.setConstraints(Tcity,gbc);
panel.add(Tcity);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 42;
gridbag.setConstraints(Lstate,gbc);
panel.add(Lstate);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 42;
gridbag.setConstraints(Tstate,gbc);
panel.add(Tstate);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 46;
gridbag.setConstraints(Lcellno,gbc);
panel.add(Lcellno);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 46;
gridbag.setConstraints(Tcellno,gbc);
panel.add(Tcellno);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 50;
gridbag.setConstraints(Lstdcode,gbc);
panel.add(Lstdcode);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 50;
gridbag.setConstraints(Tstdcode,gbc);
panel.add(Tstdcode);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 54;
gridbag.setConstraints(Lphoneno,gbc);
panel.add(Lphoneno);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 54;
gridbag.setConstraints(Tphoneno,gbc);
panel.add(Tphoneno);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 58;
gridbag.setConstraints(Lpqualification,gbc);
panel.add(Lpqualification);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 58;
gridbag.setConstraints(chighestqualification,gbc);
panel.add(chighestqualification);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 62;
gridbag.setConstraints(Lugraduate,gbc);
panel.add(Lugraduate);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 62;
gridbag.setConstraints(cugraduate,gbc);
panel.add(cugraduate);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 66;
gridbag.setConstraints(Lkeywords,gbc);
panel.add(Lkeywords);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 66;
gridbag.setConstraints(Tkeywords,gbc);
panel.add(Tkeywords);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 70;
gridbag.setConstraints(Lresume,gbc);
panel.add(Lresume);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 70;
gridbag.setConstraints(Tresume,gbc);
panel.add(Tresume);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 74;
gridbag.setConstraints(submit,gbc);
panel.add(submit);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 74;
gridbag.setConstraints(refresh,gbc);
panel.add(refresh);
}
public void actionPerformed(ActionEvent e)
{
Object source=e.getSource();
if(source==submit)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con;
con=DriverManager.getConnection("jdbc:odbc:job");
PreparedStatement stat=con.prepareStatement("insert into cand(username,password,confirm_password,first_name,middle_name,email,ug,pg,address,city,state,mobile_no,stdcode,phone_no_landline,keywords,resume)values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
stat.setString(1,Tusername.getText());
stat.setString(2,Tpassword.getText());
stat.setString(3,Tconfpassword.getText());
stat.setString(4,Tfname.getText());
stat.setString(5,Tmname.getText());
stat.setString(6,Tlname.getText());
stat.setString(6,Temail.getText());
stat.setString(7,(String)chighestqualification.getSelectedItem());
stat.setString(8,(String)cugraduate.getSelectedItem());
stat.setString(9,Taddress.getText());
stat.setString(10,Tcity.getText());
stat.setString(11,Tstate.getText());
stat.setString(12,Tcellno.getText());
stat.setString(13,Tstdcode.getText());
stat.setString(14,Tphoneno.getText());
stat.setString(15,Tkeywords.getText());
stat.setString(16,Tresume.getText());
stat.executeUpdate();
JOptionPane.showMessageDialog(frame,new String("Your details have been registered"));
}catch(Exception ae)
{
System.out.println(ae);
}
}
}
}
Hey,
thats some list of JComponents there. How about making it a bit readable .e.g:
String[] labels = { "Lfname", "Llname", "Lmname", "Lemail" };
String[] names = { "First Name", "Last Name", "Middle Name", "E-Mail" };
for(int i =0; i < labels.length; i++)
{
JLabel labels[i] = new JLabel(names[i]);
}
its an idea or something like that , so that your scroll wheel doesn't get abused - we all have to do a bit for the environment.
Soz mate,
Hadn't tried it, but looks like a got a bit too cocky about my brief understanding of swing.
Won't happen again, could you please tell me why thats bad, it looks ok as it would just take the value from the arrays just like typing a jlabel labelName = new Jlabel(label text).
Be good to see where my understandings going wrong.
> Soz mate,
>
> Hadn't tried it, but looks like a got a bit too cocky
> about my brief understanding of swing.
>
> Won't happen again, could you please tell me why
> thats bad, it looks ok as it would just take the
> value from the arrays just like typing a jlabel
> labelName = new Jlabel(label text).
>
> Be good to see where my understandings going wrong.
If you wanted to suggest an array of JLabels, here's a way:
String[] names = { "First Name", "Last Name", "Middle Name", "E-Mail" };
JLabel[] labels = new JLabel[names.length];
for(int i =0; i < labels.length; i++)
{
labels[i] = new JLabel(names[i]);
}
>Java does not support that style of variable based variable names.
>
>Use a map.
It's sad that the original poster had to list 400 (400!) lines of code
to get his question across. What happened to posting a short
example program? Doesn't the poster know that the longer
the code listing the fewer eyes will scan it, the less help he'll get,
the shorter and more dismissive the replies will be?
When will people learn? Why don't they get it?