how to validate textfield for the following program?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • swetha1
    New Member
    • Aug 2014
    • 1

    how to validate textfield for the following program?

    Code:
    import java.awt.*;
    import javax.swing.*;
    import java.applet.*;
    import java.awt.event.*;
    public class stud2 extends JFrame implements ActionListener
    {JRadioButton rb1,rb2,rb3,rb4;  
    JButton b1,b2;
      
      Label l1=new Label("Name :",Label.LEFT);
      Label l2=new Label("Age :",Label.LEFT);
      Label l3=new Label("Gender :",Label.LEFT);
      Label l4=new Label("Address :",Label.LEFT);
      Label l8=new Label("Network :",Label.LEFT);
      Label l5=new Label("simcard amnt :",Label.LEFT);
      Label l6=new Label("Pincode :",Label.LEFT);
      Label l7=new Label("Alternate PH.No :",Label.LEFT);
      TextField t1=new TextField();
    TextField t5=new TextField();
      Choice c1=new Choice();
      CheckboxGroup cbg=new CheckboxGroup();
      Checkbox ck1=new Checkbox("Male",false,cbg);
      Checkbox ck2=new Checkbox("Female",false,cbg);
      ButtonGroup bg=new ButtonGroup(); 
      TextArea t2=new TextArea("",180,90,TextArea.SCROLLBARS_VERTICAL_ONLY);
      Choice serpro=new Choice();
      TextField t3=new TextField();
      TextField t4=new TextField();
    public stud2()
     {
      setBackground(Color.white);
      setForeground(Color.black);
      setLayout(null);
    rb1=new JRadioButton("AIRTEL");
    rb2=new JRadioButton("VODAFONE");
    rb3=new JRadioButton("DOCOMO");
    rb4=new JRadioButton("AIRCEL"); 
    b1=new JButton("Next"); 
    b2=new JButton("personl details");;
    add(rb1);
    add(rb2);
    add(rb3);
    add(rb4);
    add(b1); 
    add(b2);
    bg.add(rb1);
    bg.add(rb2); 
    bg.add(rb3);
    bg.add(rb4);
      
      add(l1);
      add(l2);
      add(l3);
      add(l4);
      add(l5);
      add(l6);
      add(l7);
      add(l8);
      add(t1);
      add(t2);
      add(ck1);
      add(ck2);
      add(serpro);
      add(t3);
      add(t4);
      add(t5);
      serpro.add("RS.50");
      serpro.add("RS.75");
      serpro.add("RS.100");
     serpro.add("RS.125");
     serpro.add("RS.150");
    
      
      l1.setBounds(25,100,100,20);
      l2.setBounds(25,150,100,20);
      l3.setBounds(25,200,100,20);
      l4.setBounds(25,250,100,20);
      l6.setBounds(25,350,100,20);
      l8.setBounds(25,400,100,20); 
      l5.setBounds(25,450,100,20);
      l7.setBounds(25,525,100,20);
      
      t1.setBounds(140,100,170,20);
      t5.setBounds(140,150,30,20);
      ck1.setBounds(140,200,50,20);
      ck2.setBounds(190,200,80,20);
      t2.setBounds(140,250,170,60);
      t3.setBounds(140,350,90,20);
      rb1.setBounds(140,400,70,30);  
      rb2.setBounds(210,400,95,30);
      rb3.setBounds(305,400,90,30);
      rb4.setBounds(395,400,100,30);
      serpro.setBounds(140,450,100,20);
      t4.setBounds(140,525,90,20);
      b1.setBounds(160,600,70,30);
    b2.setBounds(0,0,1500,30);
      b1.addActionListener(this); 
     setSize(new Dimension(500,700));
     setTitle("Simcard application form");
     setVisible(true);
    }
    
    public void actionPerformed(ActionEvent e){  
    if(rb1.isSelected()){  
    JOptionPane.showMessageDialog(this,"Thanks for choosing Airtel.Your simcard will be dispatched within a week. Your ID proof and simcard amount will be collected on delivery of your simcard");  
    }  
    if(rb2.isSelected()){  
    JOptionPane.showMessageDialog(this,"Thanks for choosing Vodafone.Your simcard will be dispatched within a week. Your ID proof and simcard amount will be collected on delivery of your simcard");  
    }  
    if(rb3.isSelected()){  
    JOptionPane.showMessageDialog(this,"Thanks for choosing Docomo.Your simcard will be dispatched within a week. Your ID proof and simcard amount will be collected on delivery of your simcard");  
    }  
    if(rb4.isSelected()){  
    JOptionPane.showMessageDialog(this,"Thanks for choosing Aircel.Your simcard will be dispatched within a week. Your ID proof and simcard amount will be collected on delivery of your simcard");  
    }  
    }  
    
    public static void main(String g[])
    {new stud2();
    
    }
    }
Working...