Frame in Java AWT


The class Frame is a top level window with border and title. It uses BorderLayout as default layout manager.

The size of the frame includes any area designated for the border. The dimensions of the border area may be obtained using the getInsets method, however, since these dimensions are platform-dependent, a valid insets value cannot be obtained until the frame is made displayable by either calling pack or show.

Source Code

01_method.java
package awtDemo;
 
import java.awt.*;
public class app {
 
	public static void main(String[] args) {
		Frame frm =new Frame("Tutor Joes");
		frm.setSize(1000,600);//w,h
		frm.setLayout(null);
 
		Button btn=new Button("Click Me");
		btn.setBounds(75,75,200,50);//X,Y,W,H
 
		frm.add(btn);
		frm.setVisible(true);
	}
}
 

Output

Java AWT

To download raw file Click Here

02_method.java
package awtDemo;
import java.awt.*;
 
public class app extends Frame
{
	Button btn;
	public app() 
	{
		super("Tutor Joes");
		setLayout(null);
		btn=new Button("Click Me");
		btn.setBounds(75,75,200,50);//X,Y,W,H
		add(btn);
		setSize(1000,600);
		setVisible(true);
	}
	public static void main(String args[])
	{
		app frm =new app();
	}
}
 

Output

Java AWT

To download raw file Click Here

03_method.java
package awtDemo;
import java.awt.*;
class MyApp extends Frame
{
	Button btn;
 
	public MyApp()
	{
		super("Tutor Joes");
		setLayout(null);
 
		btn=new Button("Click Me");
		btn.setBounds(75,75,200,50);
		add(btn);
		setSize(1000,600);
		setVisible(true);
 
	}
 
}
 
 
public class app
{
	public static void main(String args[])
	{
		MyApp frm =new MyApp();
	}
To download raw file Click Here

Output

Java AWT


Basic Programs