Web
Analytics
java frames example | Angular | ASP.NET Tutorials

For Consultation : +91 9887575540

Stay Connected :

Java frames plays important role of GUI  creation as we know that it is a old concept which was introduced in Java 1.0 but the concept of Java frames can be used in swings so that here I am taking a very simple example of Java frames . I am taking radio buttonsm list, text field and level and arranged them into a frame I hope you will like this blog.

 

import java.awt.*;
import java.awt.event.*;
//Extends Frame to create frame class object
 class MainClass extends Frame
{
	MainClass()
	{
		//Create new label with text enter your name
		Label l1=new Label("Enter User Name");
		//Set Location of Label
		l1.setBounds(30, 50, 100, 30);
		//Set Layout of frame
		setLayout(null);
		//Create New Text Field
		TextField t1=new TextField();
		//Set Position of TextField into frame
		t1.setBounds(140,50,100,30);
		//Create ListBox and make enable multiple selection using second argument of List COnstructor
		List list1=new List(1, true);
		list1.add("Rajasthan");
		list1.add("UP");
		list1.add("MP");
		list1.setBounds(30,155,100,100);
		add(list1);
		//To Create Radio button in frame , first we create CheckboxGroup then we will add checkbox and pass reference of checkboxgroup to create single selection of radio button from list of radio button
		CheckboxGroup cg=new CheckboxGroup();
		Checkbox cb1=new Checkbox("male",cg,false);
		Checkbox cb2=new Checkbox("female",cg,false);
		cb1.setBounds(30,250,100,30);
		cb2.setBounds(150,250,100,30);
	add(cb1);
	add(cb2);
	//Add Window Listner event 
	this.addWindowListener(new window());
	
		add(l1);
		add(t1);
		setSize(600,600);
		setVisible(true);
		setBackground(Color.green);
	}

public static void main(String[] args)
{
	MainClass obj=new MainClass();
}
}
 //Create Window Closing event handler
 class window implements WindowListener
 {
 	public void windowClosing(WindowEvent e)
 	{
 		
 		//Come Out from system
 		System.exit(0);
 	}
 }

Output

java_frame_awt_example
Download Source Code