Java Swing Registration Form Example

0% found this document useful (0 votes)
319 views5 pages
The document contains the code for a Java Swing application that creates a registration form with various labels, text fields, buttons, checkboxes and other components to collect information…

Uploaded by

zubair
  • Java OOP Assignment Introduction
  • Label and TextField Initialization
  • CheckBox and Icon Setup
  • Additional Components
  • Final Form Components

ASSIGNMENT

2nd

CSC104-Object oriented programming Java Oops

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package [Link];

import [Link].*;
import [Link].*;

public class HWJFrame {


public static void main(String[] args) {
JFrame jf = new JFrame("Registration Form");
JButton bt1 = new JButton("Submit");
[Link](310, 350, 80,40);//adding button here
JButton bt2 = new JButton("Cancel");
[Link](410, 350, 80,40);//adding button here
[Link](bt2);

JLabel lb1 = new JLabel();//registration form label/heading


[Link]("Registration Form");
[Link](320, 20 , 120 , 30);
[Link](true);
[Link]([Link]);

//label for name


JLabel lb = new JLabel();
[Link]("Name: ");
[Link](40, 80 , 40 , 30);
[Link](true);
[Link]([Link]);
//label for text
JTextField tf = new JTextField();
[Link](120,80, 200,30);

//label for age


JLabel age = new JLabel();
[Link]("Age: ");
[Link](40, 120 , 40 , 30);
[Link](true);
[Link]([Link]);
//label for text
JTextField agetext = new JTextField();
[Link](120,120, 60,30);
[Link](age);
[Link](agetext);

//label for adress


JLabel adress = new JLabel();
[Link]("Address: ");
[Link](40, 160 , 60 , 30);
[Link](true);
[Link]([Link]);
//label for adresstext
JTextField addrestext = new JTextField();
[Link](120,160, 200,100);
[Link](adress);
[Link](addrestext);

//label for Hobbies


JLabel Hobbies = new JLabel();
[Link]("Hobbies: ");
[Link](40, 280 , 60 , 30);
[Link](true);
[Link]([Link]);
//label for Hobbies
JCheckBox checkBox1 = new JCheckBox("Game");
[Link](118,280, 80,15);
JCheckBox checkBox2 = new JCheckBox("Reading");
[Link](200,280, 80,15);
JCheckBox checkBox3 = new JCheckBox("Fishing");
[Link](280,280, 80,15);
JCheckBox checkBox4 = new JCheckBox("Quize");
[Link](118,300, 80,15);
JCheckBox checkBox5 = new JCheckBox("Stamp");
[Link](200,300, 80,15);
JCheckBox checkBox6 = new JCheckBox("Coin");
[Link](280,300, 80,15);
[Link](Hobbies);
[Link](checkBox1);
[Link](checkBox2);
[Link](checkBox3);
[Link](checkBox4);
[Link](checkBox5);
[Link](checkBox6);

//label for father name


JLabel lb2 = new JLabel();
[Link]("Father Name: ");
[Link](360, 80 , 100 , 30);
[Link](true);
[Link]([Link]);
//label for text
JTextField tf1 = new JTextField();
[Link](470,80, 150,30);
[Link](lb2);//adding father name
[Link](tf1);//adding father text

Image icon = [Link]().getImage("E:\\[Link]");


[Link](icon);

//work of mine
//label for DOB
JLabel DOB = new JLabel();
[Link]("DOB: ");
[Link](360, 160 , 40 , 30);
[Link](true);
[Link]([Link]);
[Link](DOB);
//label for DOB
String Day
[]={"Day","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21
","22","23","24","25","26","27","28","29","30","31"};
JComboBox dy=new JComboBox(Day);
[Link](470, 160,50,30);
[Link](dy);//adding Nationtext
String Month
[]={"Month","January","February","March","April","May","June","July","August","September","October"
,"November","December"};
JComboBox mn=new JComboBox(Month);
[Link](535, 160,60,30);
[Link](mn);
String Year
[]={"Year","1990","1991","1992","1993","1993","1994","1995","1996","1997","1998","1998","1999","2
000","2001","2002","2003","2004","2005","2006"};
JComboBox yr = new JComboBox(Year);
[Link](610, 160,59,30);
[Link](yr);

//label for PHONE


JLabel PHONE = new JLabel();
[Link]("Phone: ");
[Link](360, 200 , 60 , 30);
[Link](true);
[Link]([Link]);
//label for PHONEtext
JTextField PHONEtext = new JTextField();
[Link](470,200, 200,30);
[Link](PHONE);//adding father name
[Link](PHONEtext);//adding father text

//label for Email


JLabel Email = new JLabel();
[Link]("Email: ");
[Link](360, 240 , 60 , 30);
[Link](true);
[Link]([Link]);
//label for Emailtext
JTextField Emailtext = new JTextField();
[Link](470,240, 200,30);
[Link](Email);//adding Email in JFrame
[Link](Emailtext);//adding Email Text area in JFrame

//label for Nation


JLabel Nation = new JLabel();
[Link]("Nation: ");
[Link](360, 280 , 60 , 30);
[Link](true);
[Link]([Link]);
//label for Nationtext
String[] nation = {"","USA", "Pakistan", "Russia", "India", "Australia"};
JComboBox cb=new JComboBox(nation);
[Link](470, 280,200,30);
[Link](Nation);//Nation
[Link](cb);//adding Nationtext
//label for sex
JLabel sex = new JLabel();
[Link]("Sex: ");
[Link](360, 120 , 40 , 30);
[Link](true);
[Link]([Link]);
//label for sex
JRadioButton sextext1 = new JRadioButton();
[Link](465,125, 20,20);
JRadioButton sextext2 = new JRadioButton();
[Link](530,125, 20,20);
JLabel male = new JLabel("Male");
// [Link]("Male");
[Link](490, 120 , 40 , 30);
[Link](true);
JLabel female = new JLabel("Female");
// [Link]("Female");
[Link](560, 120 , 60 , 30);
[Link](true);
[Link](female);
[Link](sextext2);
[Link](male);
[Link](sex);
[Link](sextext1);

[Link](tf);//name text field


[Link](lb1);//registration form label

JTextField pic=new JTextField();


[Link](630,30,120,120);
[Link]("NO IMAGE");
[Link]([Link]);
[Link]([Link]);
[Link](pic);

[Link](lb);//name label
[Link](bt1);//button
//JFrame functions
[Link](900, 600);
[Link](null);
[Link](true);
}
}

ASSIGNMENT
2nd
 CSC104-Object oriented programming Java Oops 
/*
 * To change this license header, choose License Headers in
lb.setBackground(Color.lightGray);
        //label for text
        JTextField tf = new JTextField();
        tf.setB
JCheckBox checkBox6 = new JCheckBox("Coin");
        checkBox6.setBounds(280,300, 80,15);
        jf.add(Hobbies);
jf.add(mn);
        String Year 
[]={"Year","1990","1991","1992","1993","1993","1994","1995","1996","1997","1998","19
//label for sex
        JLabel sex = new JLabel();
        sex.setText("Sex: ");
        sex.setBounds(360, 120 , 40

You might also like