Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  Team2.java
Language: JAVA
Code:
import java.awt.*;

import java.awt.event.*;

import javax.swing.*;



/*<applet code="Team2" width=100 height=100>
</applet>*/

public class Team2 extends JApplet implements ItemListener

{
    
JLabel jlab6;

JTextField jtf1,jtf2,jtf3;
    
JComboBox<String> jcb;
     
String flags[] = { "-Select Country-","France","Germany","India","Japan"};
    

    
public void init()
    
{
      
try
      
{
          
SwingUtilities.invokeAndWait(new Runnable()
          
{
                
public void run()
                
{
                   
 makeGUI();
                 
}
          
});
       
}
       
catch(Exception e)
       
{
          
System.out.println("error");
        
}
     
}

      
private void makeGUI()
      
{
           
setLayout(new GridLayout(21,21));

               
JLabel jlab1 = new JLabel("First Name  :");
               
add(jlab1);
           
jtf1 = new JTextField(10);
                
add(jtf1);

                 
jtf1.addActionListener(new ActionListener()
                   
{
                       
public void actionPerformed(ActionEvent ae)
                       
{
                         
showStatus(jtf1.getText());
                        
}
                    
}
                    
);
 
           
               
JLabel jlab2 = new JLabel("Last Name  :");
               
add(jlab2);
               
jtf2 = new JTextField(10);
                
add(jtf2);
                 
jtf2.addActionListener(new ActionListener()
                   
{
                       
public void actionPerformed(ActionEvent ae)
                       
{
                         
showStatus(jtf2.getText());
                        
}
                    
}
                    
);

               
JLabel jlab3 = new JLabel("Choose your username  :");
               
add(jlab3);
                 
jtf3 = new JTextField(10);
                
add(jtf3);
                  
jtf3.addActionListener(new ActionListener()
                   
{
                       
public void actionPerformed(ActionEvent ae)
                       
{
                         
showStatus(jtf3.getText());
                        
}
                    
}
                    
);

             
JLabel j4=new JLabel("Pick a Password :");                                      
                
add(j4);
              
JPasswordField pw = new JPasswordField();
                  
pw.setEchoChar('*');
                 
add(pw);





   
        
JLabel jlab5 =new JLabel("Gender   :");
     
add(jlab5);

     
JRadioButton Jb1=new JRadioButton("Male");
     
Jb1.addItemListener(this);
     
add(Jb1);

     
JRadioButton Jb2=new JRadioButton("Female");
     
Jb2.addItemListener(this);
     
add(Jb2);

     
JRadioButton Jb3=new JRadioButton("Others");
     
Jb3.addItemListener(this);
     
add(Jb3);

     
       
jlab6 =new JLabel("");
     
add(jlab6);
     
     
ButtonGroup a=new ButtonGroup();
     
a.add(Jb1);
     
a.add(Jb2);
     
a.add(Jb3);



         
JLabel jlab7 =new JLabel("Country   :");
     
add(jlab7);

         
jcb = new JComboBox<String>(flags);

          
add(jcb);

          
jcb.addActionListener(new ActionListener()
          
{
             
public void actionPerformed(ActionEvent ae)
             
{
                 
String s = (String)jcb.getSelectedItem();
               
}
          
}
          
);   


 
          
 
 
           
JLabel jlab4 = new JLabel("Select Hobbies  :");
           
add(jlab4);
           
           
JCheckBox Jb=new JCheckBox("Singing");
           
add(Jb);

               
Jb=new JCheckBox("Dancing");
               
add(Jb);

               
Jb=new JCheckBox("Reading");
              
add(Jb);

              
Jb=new JCheckBox("Music");
             
add(Jb);


   
       
JButton Jbt=new JButton("Submit");
         
          
add(Jbt);

          
}


 public void itemStateChanged(ItemEvent e)
   
{
JRadioButton Jbx=(JRadioButton)e.getItem();

        


        
if(Jbx.isSelected())
             
jlab6.setText(Jbx.getText() +" is selected");
            
else

        
jlab6.setText(Jbx.getText()+ " is cleared");
     
}

       








          
Comments: