J3n
asked on
help me! sorry about that
My code
========================== =========
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<APPLET CODE="CustomerDetail" WIDTH="500" HEIGHT="300"></APPLET> */
public class CustomerDetail extends Applet implements ActionListener
{
Label lb1, lb2, lb3, lb4, lb5,lb6, lb7;
TextField id, name, address, phone, email;
Choice sex;
Button bt1,bt2;
GridBagLayout gb;
GridBagConstraints gbc;
public void init()
{
gb = new GridBagLayout();
setLayout(gb);
gbc= new GridBagConstraints();
lb1 = new Label("Customer Detail");
lb2 = new Label("Student ID");
lb3 = new Label("Student Name");
lb4 = new Label("Sex");
lb5 = new Label("Address");
lb6 = new Label("Phone");
lb7 = new Label("Email");
id = new TextField(20);
name = new TextField(20);
address = new TextField(20);
phone = new TextField(20);
email = new TextField(20);
sex = new Choice();
sex.addItem("Male");
sex.addItem("FerMale");
bt1 = new Button("Save");
bt2 = new Button("Reset");
addComponent(lb1,0,1,1,2,G ridBagCons traints.HO RIZONTAL);
addComponent(lb2,1,0,1,1,G ridBagCons traints.HO RIZONTAL);
addComponent(id,1,1,1,2,Gr idBagConst raints.HOR IZONTAL);
addComponent(lb3,2,0,1,1,G ridBagCons traints.HO RIZONTAL);
addComponent(name,2,1,1,2, GridBagCon straints.H ORIZONTAL) ;
addComponent(lb4,3,0,1,1,G ridBagCons traints.HO RIZONTAL);
addComponent(sex,3,1,1,2,G ridBagCons traints.HO RIZONTAL);
addComponent(lb5,4,0,1,1,G ridBagCons traints.HO RIZONTAL);
addComponent(address,4,1,1 ,2,GridBag Constraint s.HORIZONT AL);
addComponent(lb6,5,0,1,1,G ridBagCons traints.HO RIZONTAL);
addComponent(phone,5,1,1,2 ,GridBagCo nstraints. HORIZONTAL );
addComponent(lb7,6,0,1,1,G ridBagCons traints.HO RIZONTAL);
addComponent(email,6,1,1,2 ,GridBagCo nstraints. HORIZONTAL );
Panel p = new Panel();
p.add(bt1);
p.add(bt2);
addComponent(p,7,0,1,1,Gri dBagConstr aints.HORI ZONTAL);
gbc.anchor = GridBagConstraints.WEST;
Font f = new Font("arial",Font.BOLD,13) ;
lb2.setFont(f);
lb3.setFont(f);
lb4.setFont(f);
lb5.setFont(f);
lb6.setFont(f);
lb7.setFont(f);
bt1.setFont(f);
bt2.setFont(f);
Font f1 = new Font("arial",Font.BOLD, 16);
lb1.setFont(f1);
id.addActionListener(this) ;
name.addActionListener(thi s);
phone.addActionListener(th is);
email.addActionListener(th is);
bt1.addActionListener(this );
bt2.addActionListener(this );
}
public void addComponent(Component c, int row, int col, int nrow, int ncol, int fill)
{
gbc.gridx = col;
gbc.gridy = row;
gbc.gridwidth = ncol;
gbc.gridheight = nrow;
gbc.fill = fill;
gb.setConstraints(c,gbc);
add(c);
}
public void actionPerformed (ActionEvent e)
{
if(e.getSource() == bt2)
{
id.setText("");
name.setText("");
address.setText("");
phone.setText("");
email.setText("");
showStatus("Reset");
}
if(e.getSource() == bt1)
{
if(id.getText().equals("") )
{
showStatus("Student ID field must be fill!!");
id.requestFocus();
}
else if(name.getText().equals(" "))
{
showStatus("Student Name field must be fill!!");
name.requestFocus();
}
}
}
}
========================== ========== ======
hix, i dunt know how to set: email must follow the pattern 'useid@company.com'
+ phone must be number
+ when user click on Save button all data must be save to "text.txt" file
==========================
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<APPLET CODE="CustomerDetail" WIDTH="500" HEIGHT="300"></APPLET> */
public class CustomerDetail extends Applet implements ActionListener
{
Label lb1, lb2, lb3, lb4, lb5,lb6, lb7;
TextField id, name, address, phone, email;
Choice sex;
Button bt1,bt2;
GridBagLayout gb;
GridBagConstraints gbc;
public void init()
{
gb = new GridBagLayout();
setLayout(gb);
gbc= new GridBagConstraints();
lb1 = new Label("Customer Detail");
lb2 = new Label("Student ID");
lb3 = new Label("Student Name");
lb4 = new Label("Sex");
lb5 = new Label("Address");
lb6 = new Label("Phone");
lb7 = new Label("Email");
id = new TextField(20);
name = new TextField(20);
address = new TextField(20);
phone = new TextField(20);
email = new TextField(20);
sex = new Choice();
sex.addItem("Male");
sex.addItem("FerMale");
bt1 = new Button("Save");
bt2 = new Button("Reset");
addComponent(lb1,0,1,1,2,G
addComponent(lb2,1,0,1,1,G
addComponent(id,1,1,1,2,Gr
addComponent(lb3,2,0,1,1,G
addComponent(name,2,1,1,2,
addComponent(lb4,3,0,1,1,G
addComponent(sex,3,1,1,2,G
addComponent(lb5,4,0,1,1,G
addComponent(address,4,1,1
addComponent(lb6,5,0,1,1,G
addComponent(phone,5,1,1,2
addComponent(lb7,6,0,1,1,G
addComponent(email,6,1,1,2
Panel p = new Panel();
p.add(bt1);
p.add(bt2);
addComponent(p,7,0,1,1,Gri
gbc.anchor = GridBagConstraints.WEST;
Font f = new Font("arial",Font.BOLD,13)
lb2.setFont(f);
lb3.setFont(f);
lb4.setFont(f);
lb5.setFont(f);
lb6.setFont(f);
lb7.setFont(f);
bt1.setFont(f);
bt2.setFont(f);
Font f1 = new Font("arial",Font.BOLD, 16);
lb1.setFont(f1);
id.addActionListener(this)
name.addActionListener(thi
phone.addActionListener(th
email.addActionListener(th
bt1.addActionListener(this
bt2.addActionListener(this
}
public void addComponent(Component c, int row, int col, int nrow, int ncol, int fill)
{
gbc.gridx = col;
gbc.gridy = row;
gbc.gridwidth = ncol;
gbc.gridheight = nrow;
gbc.fill = fill;
gb.setConstraints(c,gbc);
add(c);
}
public void actionPerformed (ActionEvent e)
{
if(e.getSource() == bt2)
{
id.setText("");
name.setText("");
address.setText("");
phone.setText("");
email.setText("");
showStatus("Reset");
}
if(e.getSource() == bt1)
{
if(id.getText().equals("")
{
showStatus("Student ID field must be fill!!");
id.requestFocus();
}
else if(name.getText().equals("
{
showStatus("Student Name field must be fill!!");
name.requestFocus();
}
}
}
}
==========================
hix, i dunt know how to set: email must follow the pattern 'useid@company.com'
+ phone must be number
+ when user click on Save button all data must be save to "text.txt" file
Hi,
1.
String string = "userid@company.com";
b = string.indexOf("@") > 0;
if (b == false)
{
// Wrong email
}
else
{
// Do your logic here
}
URL:http://www.javaalmanac.com/egs/java.lang/HasSubstr.html
2.
You can use Integer.parseInt to check it.
try
{
int phone = Integer.parseInt("123123") ;
}
catch (Exception e)
{
e.printStackTrace();
System.out.println("Phone must be number");
}
3.
http://www.devdaily.com/java/edu/pj/pj010017/index.shtml
I hope that helps.
Regards
Dave
1.
String string = "userid@company.com";
b = string.indexOf("@") > 0;
if (b == false)
{
// Wrong email
}
else
{
// Do your logic here
}
URL:http://www.javaalmanac.com/egs/java.lang/HasSubstr.html
2.
You can use Integer.parseInt to check it.
try
{
int phone = Integer.parseInt("123123")
}
catch (Exception e)
{
e.printStackTrace();
System.out.println("Phone must be number");
}
3.
http://www.devdaily.com/java/edu/pj/pj010017/index.shtml
I hope that helps.
Regards
Dave
ASKER
thanks much
but i still error, can you write complete code for me
Thanks again
but i still error, can you write complete code for me
Thanks again
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi,
Sorry.
else if((email.getText()).index Of('@') < 0)
{
System.out.println("Email must have @!!");
}
Regards
Dave
Sorry.
else if((email.getText()).index
{
System.out.println("Email must have @!!");
}
Regards
Dave
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
1." email must follow the pattern 'useid@company.com'". i think that you can check it using instr method of String.
2. "phone must be number". I can give you some sample after this.
3. I will show you how to save data into text file.
Regards
Dave