Make Registration form using only AWT

Java AWT (Abstract Window Toolkit) is an API to develop GUI in java.

it has many components like button, label, checkbox, etc. used as objects inside a Java Program.Java AWT components are platform-dependent which implies that they are displayed according to the view of the operating system. It is also heavyweight . java. awt package provides classes for AWT api.

In this program i have made a simple registration form with Awt as its major components and also used Swings combo box to get year of study.

In this program there are two classes : 1. Registration class which contains the main method and the details class which does the rest of the work

Output







Registration class

public class Registration 
{
	public static void main(String[] args) 
	{
		Details d1 = new Details();
		d1.Register();

	}
}

detailsClass

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


public class Details extends Frame implements ActionListener
{
	TextField t1;
	static JComboBox jc1;
	String[] s = new String[9]; 
	static Checkbox cb1,cb2;
	CheckboxGroup cbg;
	Button b;
	
	Details()
	{
		setVisible(true);
		setBounds(100,50,700,500);
		setTitle("Registration Form");
		setLayout(null);
		
		addWindowListener(new WindowAdapter()
		{
			public void windowClosing(WindowEvent e)
			{
				dispose();
			}
		});
	}
	void Register()
	{
		setLayout(null);
		Font f = new Font("Arial",Font.BOLD,20);
		Label l1 = new Label("Registration Form");
		l1.setBounds(250, 50, 400, 40);
		l1.setForeground(Color.BLUE);
		l1.setFont(f);
		Label l2 = new Label("Student_Id:");
		l2.setBounds(50, 100, 60, 20);
		t1 = new TextField();
		t1.setBounds(150, 100, 120, 20);
		Label l3 = new Label("Semester:");
		l3.setBounds(50, 150, 60, 20);
		for(int i=1; i<=8;i++)
		{
			s[i] = i+" semester";
		}
		jc1 = new JComboBox(s);
		jc1.setBounds(150, 150, 120, 20);
		Label l4 = new Label("Type:");
		l4.setBounds(50, 200, 60, 20);
		
		
		Label l5 = new Label("Type of study:");
		l5.setBounds(50, 210, 80, 20);
		cbg = new CheckboxGroup();
		cb1 = new Checkbox("GOVERNMENT",cbg,false);
		cb2 = new Checkbox("SELF",cbg,false);
		cb1.setBounds(140, 210, 100, 20);
		cb2.setBounds(240, 210, 100, 20);
		b = new Button("Register");
		b.setBounds(150, 250, 50, 20);
		b.addActionListener(this);
		

		add(l1);
		add(l2);
		add(t1);
		add(l3);
		add(jc1);
		add(l5);
		add(cb1);
		add(cb2);
		add(b);
				
	}
	@Override
	public void actionPerformed(ActionEvent e)
	{
		Label l = new Label("PRINTING DETAILS");
		l.setBounds(250, 300, 100, 30);
		l.setForeground(Color.BLUE);
		Label l2 = new Label();
		l2.setBounds(50, 320, 150, 30);
		Label l3 = new Label();
		l3.setBounds(50, 340, 180, 30);
		Label l4 = new Label();
		l4.setBounds(50, 360, 180, 30);
		Label l5 = new Label();
		l5.setBounds(50, 380, 180, 30);
		int student =Integer.parseInt(t1.getText());
		int fees = 0;
		String Sem = (String) jc1.getSelectedItem();
		
		if(cb1.getState()==true)
			{
			if(Sem.contains("1") || Sem.contains("2"))
					fees=100*2;
			if(Sem.contains("3") || Sem.contains("4"))
					fees=100*4;
			if(Sem.contains("5") || Sem.contains("6"))
					fees=100*6;
			if(Sem.contains("7") || Sem.contains("8"))
					fees=100*8;						
			}
		else if(cb2.getState()==true)
			{
			if(Sem.contains("1") || Sem.contains("2"))
					fees=50000*2;
			if(Sem.contains("3") || Sem.contains("4"))
					fees=40000*4;
			if(Sem.contains("5") || Sem.contains("6"))
					fees=30000*6;
			if(Sem.contains("7") || Sem.contains("8"))
					fees=20000*8;	
			}
			l2.setText("Student Number:" + student+" ");
			l3.setText("Type : Government Scholarship");
			l4.setText("Semester: " + Sem);
			l5.setText("Total Amount to be paid:" + fees);
			
			
			add(l);
			add(l2);
			add(l3);
			add(l4);
			add(l5);
		
	}
 }

1 comment: