import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class RegistrationDemo
{
static JTextField name_tf;
static JTextField mobile_tf;
static JComboBox day;
static JComboBox month;
static JComboBox year;
static JRadioButton male;
static JRadioButton female;
static JTextArea add_ta;
static JCheckBox tandc;
static JButton submit;
static JTextArea output;
public static void main(String args[])
{
JFrame frame=new JFrame("RegistrationDemo");
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBounds(200,100,800,600);
Container cntr=frame.getContentPane();
cntr.setLayout(null);
cntr.setBackground(Color.YELLOW);
JPanel panel = new JPanel();
panel.setBackground(new Color(255, 204, 0));
panel.setBorder(new TitledBorder(null, "Personal Details", TitledBorder.CENTER, TitledBorder.TOP, null, new Color(255, 0, 0)));
panel.setBounds(20, 78, 808, 616);
add(panel);
panel.setLayout(null);
JLabel name_label=new JLabel("Name");
name_label.setBounds(50,50,60,30);
name_tf=new JTextField();
name_tf.setBounds(150,50,100,30);
JLabel mobile_label=new JLabel("Mobile");
mobile_label.setBounds(50,100,60,25);
mobile_tf=new JTextField();
mobile_tf.setBounds(150,100,100,25);
JLabel dob_label=new JLabel("DOB");
dob_label.setBounds(50,150,60,30);
String[] day_arr=new String[31];
for(int i=1; i<=31; i++)
day_arr[i-1]=Integer.toString(i);
day=new JComboBox(day_arr);
day.setBounds(150,150,60,25);
String[] month_arr={"jan","feb","mar","apr","may","June","July","Aug","sep","oct","nov","Dec"};
month=new JComboBox(month_arr);
month.setBounds(230,150,80,25);
String[] year_arr=new String[70];
for(int i=1951; i<=2020; i++)
year_arr[i-1951]=Integer.toString(i);
year=new JComboBox(year_arr);
year.setBounds(310,150,60,25);
JLabel gender_label=new JLabel("Gender");
gender_label.setBounds(50,200,60,30);
male=new JRadioButton("Male");
male.setBounds(150,200,60,30);
female=new JRadioButton("Female");
female.setBounds(240,200,60,30);
ButtonGroup gender=new ButtonGroup();
gender.add(male);
gender.add(female);
JLabel add_label=new JLabel("Adress");
add_label.setBounds(50,250,60,30);
add_ta=new JTextArea();
add_ta.setBounds(150,250,240,50);
tandc=new JCheckBox("I accept all terms and condition");
tandc.setBounds(50,320,250,25);
submit=new JButton("Submit");
submit.setBounds(100,355,80,40);
submit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event)
{
submit_action(event);
}
});
output=new JTextArea();
output.setBounds(400,50,300,350);
cntr.add(name_label);
cntr.add(name_tf);
cntr.add(mobile_label);
cntr.add(mobile_tf);
cntr.add(dob_label);
cntr.add(day);
cntr.add(month);
cntr.add(year);
cntr.add(gender_label);
cntr.add(male);
cntr.add(female);
cntr.add(add_label);
cntr.add(add_ta);
cntr.add(tandc);
cntr.add(submit);
cntr.add(output);
}
public static void submit_action(ActionEvent event)
{
if(tandc.isSelected()==true)
{
String name=name_tf.getText();
String mobile=mobile_tf.getText();
String day_name=(String)day.getSelectedItem();
String month_name=(String)month.getSelectedItem();
String year_name=(String)year.getSelectedItem();
String gen="Male";
if(female.isSelected()== true)
gen="Female";
String address=add_ta.getText();
output.setText("Name "+name+"\nMobile "+mobile+"\nDOB "+day_name+" "+month_name+" "+year_name+"\nGender "+gen+"\nAddress "+address);
}
else
{
output.setText("Please accept terms and conditions");
}
}
}
Output Screen
import java.awt.*;
import java.awt.event.*;
class RegistrationDemo
{
static JTextField name_tf;
static JTextField mobile_tf;
static JComboBox day;
static JComboBox month;
static JComboBox year;
static JRadioButton male;
static JRadioButton female;
static JTextArea add_ta;
static JCheckBox tandc;
static JButton submit;
static JTextArea output;
public static void main(String args[])
{
JFrame frame=new JFrame("RegistrationDemo");
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBounds(200,100,800,600);
Container cntr=frame.getContentPane();
cntr.setLayout(null);
cntr.setBackground(Color.YELLOW);
JPanel panel = new JPanel();
panel.setBackground(new Color(255, 204, 0));
panel.setBorder(new TitledBorder(null, "Personal Details", TitledBorder.CENTER, TitledBorder.TOP, null, new Color(255, 0, 0)));
panel.setBounds(20, 78, 808, 616);
add(panel);
panel.setLayout(null);
JLabel name_label=new JLabel("Name");
name_label.setBounds(50,50,60,30);
name_tf=new JTextField();
name_tf.setBounds(150,50,100,30);
JLabel mobile_label=new JLabel("Mobile");
mobile_label.setBounds(50,100,60,25);
mobile_tf=new JTextField();
mobile_tf.setBounds(150,100,100,25);
JLabel dob_label=new JLabel("DOB");
dob_label.setBounds(50,150,60,30);
String[] day_arr=new String[31];
for(int i=1; i<=31; i++)
day_arr[i-1]=Integer.toString(i);
day=new JComboBox(day_arr);
day.setBounds(150,150,60,25);
String[] month_arr={"jan","feb","mar","apr","may","June","July","Aug","sep","oct","nov","Dec"};
month=new JComboBox(month_arr);
month.setBounds(230,150,80,25);
String[] year_arr=new String[70];
for(int i=1951; i<=2020; i++)
year_arr[i-1951]=Integer.toString(i);
year=new JComboBox(year_arr);
year.setBounds(310,150,60,25);
JLabel gender_label=new JLabel("Gender");
gender_label.setBounds(50,200,60,30);
male=new JRadioButton("Male");
male.setBounds(150,200,60,30);
female=new JRadioButton("Female");
female.setBounds(240,200,60,30);
ButtonGroup gender=new ButtonGroup();
gender.add(male);
gender.add(female);
JLabel add_label=new JLabel("Adress");
add_label.setBounds(50,250,60,30);
add_ta=new JTextArea();
add_ta.setBounds(150,250,240,50);
tandc=new JCheckBox("I accept all terms and condition");
tandc.setBounds(50,320,250,25);
submit=new JButton("Submit");
submit.setBounds(100,355,80,40);
submit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event)
{
submit_action(event);
}
});
output=new JTextArea();
output.setBounds(400,50,300,350);
cntr.add(name_label);
cntr.add(name_tf);
cntr.add(mobile_label);
cntr.add(mobile_tf);
cntr.add(dob_label);
cntr.add(day);
cntr.add(month);
cntr.add(year);
cntr.add(gender_label);
cntr.add(male);
cntr.add(female);
cntr.add(add_label);
cntr.add(add_ta);
cntr.add(tandc);
cntr.add(submit);
cntr.add(output);
}
public static void submit_action(ActionEvent event)
{
if(tandc.isSelected()==true)
{
String name=name_tf.getText();
String mobile=mobile_tf.getText();
String day_name=(String)day.getSelectedItem();
String month_name=(String)month.getSelectedItem();
String year_name=(String)year.getSelectedItem();
String gen="Male";
if(female.isSelected()== true)
gen="Female";
String address=add_ta.getText();
output.setText("Name "+name+"\nMobile "+mobile+"\nDOB "+day_name+" "+month_name+" "+year_name+"\nGender "+gen+"\nAddress "+address);
}
else
{
output.setText("Please accept terms and conditions");
}
}
}
Output Screen
No comments:
Post a Comment