Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

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 jframe.form;

import javax.swing.*;
import java.awt.*;

public class HWJFrame {


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

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


lb1.setText("Registration Form");
lb1.setBounds(320, 20 , 120 , 30);
lb1.setOpaque(true);
lb1.setBackground(Color.lightGray);

//label for name


JLabel lb = new JLabel();
lb.setText("Name: ");
lb.setBounds(40, 80 , 40 , 30);
lb.setOpaque(true);
lb.setBackground(Color.lightGray);
//label for text
JTextField tf = new JTextField();
tf.setBounds(120,80, 200,30);

//label for age


JLabel age = new JLabel();
age.setText("Age: ");
age.setBounds(40, 120 , 40 , 30);
age.setOpaque(true);
age.setBackground(Color.lightGray);
//label for text
JTextField agetext = new JTextField();
agetext.setBounds(120,120, 60,30);
jf.add(age);
jf.add(agetext);

//label for adress


JLabel adress = new JLabel();
adress.setText("Address: ");
adress.setBounds(40, 160 , 60 , 30);
adress.setOpaque(true);
adress.setBackground(Color.lightGray);
//label for adresstext
JTextField addrestext = new JTextField();
addrestext.setBounds(120,160, 200,100);
jf.add(adress);
jf.add(addrestext);

//label for Hobbies


JLabel Hobbies = new JLabel();
Hobbies.setText("Hobbies: ");
Hobbies.setBounds(40, 280 , 60 , 30);
Hobbies.setOpaque(true);
Hobbies.setBackground(Color.lightGray);
//label for Hobbies
JCheckBox checkBox1 = new JCheckBox("Game");
checkBox1.setBounds(118,280, 80,15);
JCheckBox checkBox2 = new JCheckBox("Reading");
checkBox2.setBounds(200,280, 80,15);
JCheckBox checkBox3 = new JCheckBox("Fishing");
checkBox3.setBounds(280,280, 80,15);
JCheckBox checkBox4 = new JCheckBox("Quize");
checkBox4.setBounds(118,300, 80,15);
JCheckBox checkBox5 = new JCheckBox("Stamp");
checkBox5.setBounds(200,300, 80,15);
JCheckBox checkBox6 = new JCheckBox("Coin");
checkBox6.setBounds(280,300, 80,15);
jf.add(Hobbies);
jf.add(checkBox1);
jf.add(checkBox2);
jf.add(checkBox3);
jf.add(checkBox4);
jf.add(checkBox5);
jf.add(checkBox6);

//label for father name


JLabel lb2 = new JLabel();
lb2.setText("Father Name: ");
lb2.setBounds(360, 80 , 100 , 30);
lb2.setOpaque(true);
lb2.setBackground(Color.lightGray);
//label for text
JTextField tf1 = new JTextField();
tf1.setBounds(470,80, 150,30);
jf.add(lb2);//adding father name
jf.add(tf1);//adding father text

Image icon = Toolkit.getDefaultToolkit().getImage("E:\\icon.png");


jf.setIconImage(icon);

//work of mine
//label for DOB
JLabel DOB = new JLabel();
DOB.setText("DOB: ");
DOB.setBounds(360, 160 , 40 , 30);
DOB.setOpaque(true);
DOB.setBackground(Color.lightGray);
jf.add(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);
dy.setBounds(470, 160,50,30);
jf.add(dy);//adding Nationtext
String Month
[]={"Month","January","February","March","April","May","June","July","August","September","October"
,"November","December"};
JComboBox mn=new JComboBox(Month);
mn.setBounds(535, 160,60,30);
jf.add(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);
yr.setBounds(610, 160,59,30);
jf.add(yr);

//label for PHONE


JLabel PHONE = new JLabel();
PHONE.setText("Phone: ");
PHONE.setBounds(360, 200 , 60 , 30);
PHONE.setOpaque(true);
PHONE.setBackground(Color.lightGray);
//label for PHONEtext
JTextField PHONEtext = new JTextField();
PHONEtext.setBounds(470,200, 200,30);
jf.add(PHONE);//adding father name
jf.add(PHONEtext);//adding father text

//label for Email


JLabel Email = new JLabel();
Email.setText("Email: ");
Email.setBounds(360, 240 , 60 , 30);
Email.setOpaque(true);
Email.setBackground(Color.lightGray);
//label for Emailtext
JTextField Emailtext = new JTextField();
Emailtext.setBounds(470,240, 200,30);
jf.add(Email);//adding Email in JFrame
jf.add(Emailtext);//adding Email Text area in JFrame

//label for Nation


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

jf.add(tf);//name text field


jf.add(lb1);//registration form label

JTextField pic=new JTextField();


pic.setBounds(630,30,120,120);
pic.setText("NO IMAGE");
pic.setForeground(Color.RED);
pic.setHorizontalAlignment(JTextField.CENTER);
jf.add(pic);

jf.add(lb);//name label
jf.add(bt1);//button
//JFrame functions
jf.setSize(900, 600);
jf.setLayout(null);
jf.setVisible(true);
}
}

You might also like